pub struct Printer { /* private fields */ }Expand description
Main printer for CLI output
Implementations§
Source§impl Printer
impl Printer
Sourcepub fn new(format: OutputFormat, verbose: bool) -> Self
pub fn new(format: OutputFormat, verbose: bool) -> Self
Creates a new printer with the specified format and verbosity.
Sourcepub fn with_not_found(self, not_found: &[String]) -> Self
pub fn with_not_found(self, not_found: &[String]) -> Self
Say which targets matched nothing: the JSON results (dry run, action,
the empty result and the refusal that asks for --yes) then list them
as not_found, an empty array when every target was found.
Sourcepub fn wide(self, wide: bool) -> Self
pub fn wide(self, wide: bool) -> Self
Opt into untruncated output (--wide). Values print in full and rows
may exceed the terminal width rather than being elided.
Sourcepub fn from_flags(json: bool, verbose: bool) -> Self
pub fn from_flags(json: bool, verbose: bool) -> Self
Create a printer from common CLI flags.
Sourcepub fn success(&self, message: &str)
pub fn success(&self, message: &str)
Print a success message (human only — use print_empty_result for JSON-safe success)
Sourcepub fn print_empty_result(&self, action: &str, message: &str)
pub fn print_empty_result(&self, action: &str, message: &str)
Print a “nothing found” success result with JSON support.
In human mode, prints a green success message. In JSON mode, outputs structured JSON so scripts/LLMs always get parseable output.
Sourcepub fn print_processes_as(
&self,
action: &str,
processes: &[Process],
context: Option<&str>,
)
pub fn print_processes_as( &self, action: &str, processes: &[Process], context: Option<&str>, )
Print a list of processes with action name and optional context.
The action parameter sets the JSON action field (e.g. “list”, “by”, “stuck”).
Sourcepub fn print_processes_with_context(
&self,
processes: &[Process],
context: Option<&str>,
)
pub fn print_processes_with_context( &self, processes: &[Process], context: Option<&str>, )
Print a list of processes with optional context (e.g., “in /path/to/dir”). Uses “list” as the JSON action name.
Sourcepub fn print_processes(&self, processes: &[Process])
pub fn print_processes(&self, processes: &[Process])
Print a list of processes. Uses “list” as the JSON action name.
Sourcepub fn print_processes_under_headline(
&self,
action: &str,
processes: &[Process],
)
pub fn print_processes_under_headline( &self, action: &str, processes: &[Process], )
Like print_processes_as, for a caller that has printed its own headline
(⚠ Found 2 orphaned processes): the generic ✓ Found 2 processes line
would repeat it, so only the table is printed.
Sourcepub fn print_json<T: Serialize>(&self, data: &T)
pub fn print_json<T: Serialize>(&self, data: &T)
Print JSON output for any serializable type
Sourcepub fn print_action_result(
&self,
action: &str,
succeeded: &[Process],
failed: &[(Process, String)],
) -> Result<()>
pub fn print_action_result( &self, action: &str, succeeded: &[Process], failed: &[(Process, String)], ) -> Result<()>
Print action result (generalized for kill/stop/freeze/thaw).
The action parameter is the command name (e.g. “kill”, “stop”, “freeze”).
It is used as-is in JSON output and as the verb for human display.
Returns Err(ProcError::Reported) when any process failed, so the command
exits non-zero without printing a second result.
Sourcepub fn print_action_result_as(
&self,
action: &str,
verb: &str,
succeeded: &[Process],
failed: &[(Process, String)],
) -> Result<()>
pub fn print_action_result_as( &self, action: &str, verb: &str, succeeded: &[Process], failed: &[(Process, String)], ) -> Result<()>
Print action result where the JSON action differs from the verb shown
to humans (e.g. proc orphans --kill reports action “orphans”, verb “kill”).
Sourcepub fn print_dry_run(&self, action: &str, processes: &[Process])
pub fn print_dry_run(&self, action: &str, processes: &[Process])
Print dry-run summary for a destructive command.
The action is the command name (e.g. “kill”, “stop”, “freeze”, “thaw”),
used both as the JSON action and as the verb in the human summary.
Sourcepub fn print_dry_run_with(
&self,
action: &str,
processes: &[Process],
message: &str,
)
pub fn print_dry_run_with( &self, action: &str, processes: &[Process], message: &str, )
Print dry-run summary with a custom human message.
JSON output is {"action", "success", "dry_run": true, "count", "not_found" (when the printer was given targets), "processes"}.
Sourcepub fn ask_confirm(
&self,
action: &str,
processes: &[Process],
yes: bool,
) -> Result<bool>
pub fn ask_confirm( &self, action: &str, processes: &[Process], yes: bool, ) -> Result<bool>
Show confirmation prompt and return whether the user confirmed.
Returns Ok(true) if confirmed or skipped (–yes), Ok(false) if the
user declined (prints “Cancelled”), and an error when there’s nobody to
ask (see must_confirm) or the list of what would change can’t be
shown to them (see prompt).
Sourcepub fn print_confirmation(&self, action: &str, processes: &[Process])
pub fn print_confirmation(&self, action: &str, processes: &[Process])
Print a confirmation prompt showing processes about to be acted on