Module output

Module output 

Source
Expand description

Output formatting and logging Output formatting and logging module.

This module provides output formatting for different modes (human-readable, JSON) and logging functionality that is independent of output formatting.

§What

Provides:

  • OutputFormat enum for different output modes
  • Output struct for consistent formatting across all commands
  • JSON response structure for API-like output
  • Styling and color utilities
  • Table rendering capabilities
  • Progress indicators
  • Separation of concerns: logs go to stderr, output goes to stdout

§How

The module uses:

  • comfy-table for table rendering
  • indicatif for progress bars
  • console for styling and terminal control
  • tracing for structured logging
  • serde_json for JSON output

Key principle: --log-level controls stderr (logs), --format controls stdout (output). These are completely independent - you can have JSON output with debug logs, or text output with no logs, etc.

§Why

Separating output formatting from logging ensures:

  • Clean JSON output without log contamination
  • Consistent output across all commands
  • Flexibility in choosing output and logging independently
  • Better tooling integration (parseable JSON + debug logs)

§Examples

Creating an output instance:

use sublime_cli_tools::output::{Output, OutputFormat};
use std::io;

let output = Output::new(OutputFormat::Human, io::stdout(), false);
output.success("Operation completed successfully").unwrap();

Using JSON output:

use sublime_cli_tools::output::{Output, OutputFormat, JsonResponse};
use std::io;
use serde::Serialize;

#[derive(Serialize)]
struct MyData {
    value: String,
}

let output = Output::new(OutputFormat::Json, io::stdout(), false);
let data = MyData { value: "test".to_string() };
let response = JsonResponse::success(data);
output.json(&response).unwrap();

Re-exports§

pub use diff::DependencyDiff;
pub use diff::DiffLine;
pub use diff::DiffRenderer;
pub use diff::DiffType;
pub use diff::FileDiff;
pub use diff::VersionDiff;
pub use diff::dependency_diff;
pub use diff::file_diff_added;
pub use diff::file_diff_deleted;
pub use diff::file_diff_modified;
pub use diff::version_diff;
pub use export::ExportFormat;
pub use export::Exporter;
pub use export::HtmlExporter;
pub use export::MarkdownExporter;
pub use export::export_data;
pub use progress::MultiProgress;
pub use progress::ProgressBar;
pub use progress::Spinner;

Modules§

diff
Diff visualization for version changes and file modifications.
export
Export functionality for CLI reports.
logger
Logging system for CLI operations.
progress
Progress indicators for long-running operations.
styling
Output styling and formatting utilities for modern CLI display.
table
Table rendering utilities for terminal output.

Structs§

JsonResponse
Standard JSON response structure for all CLI commands.
Output
Main output handler for CLI commands.
Style
Styling utilities for terminal output.
StyledText
Builder for creating complex styled text.

Enums§

OutputFormat
Output format for CLI commands.