pub struct Formatter { /* private fields */ }Expand description
Formatter for CLI output
Handles both human-readable and JSON output formats based on configuration. When JSON mode is enabled, all output is strict JSON without colors or progress.
Implementations§
Source§impl Formatter
impl Formatter
Sourcepub fn new(config: OutputConfig) -> Self
pub fn new(config: OutputConfig) -> Self
Create a new formatter with the given configuration
Sourcepub fn colors_enabled(&self) -> bool
pub fn colors_enabled(&self) -> bool
Check if colors are enabled
Sourcepub fn output_config(&self) -> OutputConfig
pub fn output_config(&self) -> OutputConfig
Get a clone of the output configuration
Sourcepub fn style_file(&self, text: &str) -> String
pub fn style_file(&self, text: &str) -> String
Style a file name (default)
Sourcepub fn style_size(&self, text: &str) -> String
pub fn style_size(&self, text: &str) -> String
Style a file size (green)
Sourcepub fn style_date(&self, text: &str) -> String
pub fn style_date(&self, text: &str) -> String
Style a timestamp/date (dim)
Sourcepub fn style_name(&self, text: &str) -> String
pub fn style_name(&self, text: &str) -> String
Style an alias/bucket name (bold)
pub fn sanitize_text(&self, text: &str) -> String
Sourcepub fn style_tree_branch(&self, text: &str) -> String
pub fn style_tree_branch(&self, text: &str) -> String
Style tree branch characters (dim)
Sourcepub fn output<T: Serialize + Display>(&self, value: &T)
pub fn output<T: Serialize + Display>(&self, value: &T)
Output a value
In JSON mode, serializes the value to JSON. In human mode, uses the Display implementation.
Sourcepub fn error(&self, message: &str)
pub fn error(&self, message: &str)
Output an error message
Errors are always printed, even in quiet mode.
Sourcepub fn error_with_code(&self, code: ExitCode, message: &str)
pub fn error_with_code(&self, code: ExitCode, message: &str)
Output an error message with an explicit exit code.
Sourcepub fn error_with_suggestion(
&self,
code: ExitCode,
message: &str,
suggestion: &str,
)
pub fn error_with_suggestion( &self, code: ExitCode, message: &str, suggestion: &str, )
Output an error message with an explicit exit code and recovery suggestion.
Sourcepub fn fail(&self, code: ExitCode, message: &str) -> ExitCode
pub fn fail(&self, code: ExitCode, message: &str) -> ExitCode
Print an error and return the provided exit code.
Sourcepub fn fail_with_suggestion(
&self,
code: ExitCode,
message: &str,
suggestion: &str,
) -> ExitCode
pub fn fail_with_suggestion( &self, code: ExitCode, message: &str, suggestion: &str, ) -> ExitCode
Print an error with a recovery hint and return the provided exit code.
Sourcepub fn json<T: Serialize>(&self, value: &T)
pub fn json<T: Serialize>(&self, value: &T)
Output JSON directly
Used when you want to output a pre-built JSON structure.
Sourcepub fn json_line<T: Serialize>(&self, value: &T)
pub fn json_line<T: Serialize>(&self, value: &T)
Output one compact JSON Lines record to stdout.
Sourcepub fn try_json_line<T: Serialize>(&self, value: &T) -> Result<()>
pub fn try_json_line<T: Serialize>(&self, value: &T) -> Result<()>
Write one compact JSON Lines record to stdout and report output failures.
Sourcepub fn json_line_error<T: Serialize>(&self, value: &T)
pub fn json_line_error<T: Serialize>(&self, value: &T)
Output one compact JSON Lines error record to stderr.
Sourcepub fn json_error<T: Serialize>(&self, value: &T)
pub fn json_error<T: Serialize>(&self, value: &T)
Output a pre-built JSON error record on stderr.
Sourcepub fn try_println(&self, message: &str) -> Result<()>
pub fn try_println(&self, message: &str) -> Result<()>
Print a line to stdout and report output failures.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Formatter
impl RefUnwindSafe for Formatter
impl Send for Formatter
impl Sync for Formatter
impl Unpin for Formatter
impl UnsafeUnpin for Formatter
impl UnwindSafe for Formatter
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more