Expand description
Consolidated styling module for terminal output.
This module uses the anstyle ecosystem:
- anstream for auto-detecting color support
- anstyle for composable styling
- Semantic style constants for domain-specific use
§stdout vs stderr principle
- stdout: ALL worktrunk output (messages, errors, warnings, directives, data)
- stderr: ALL child process output (git, npm, user commands)
- Exception: Interactive prompts use stderr so they appear even when stdout is redirected
Use println! for all worktrunk messages. Use eprintln! only for interactive prompts.
Macros§
- eprint
- Prints to
stderr. - eprintln
- Prints to
stderr, with a newline. - Prints to
stdout. - println
- Prints to
stdout, with a newline.
Structs§
- Anstyle
Style - ANSI Text styling
- Formatted
Message - A message that has already been formatted with emoji and styling.
- Styled
Line - A line composed of multiple styled strings
- Styled
String - A piece of text with an optional style
Constants§
- ADDITION
- Addition style for diffs (green) - used in table rendering
- DELETION
- Deletion style for diffs (red) - used in table rendering
- ERROR_
EMOJI - Error emoji:
cformat!("{ERROR_EMOJI} <red>message</>") - GUTTER
- Gutter style for quoted content (commands, config, error details)
- GUTTER_
OVERHEAD - Width overhead added by format_with_gutter()
- HINT_
EMOJI - Hint emoji:
cformat!("{HINT_EMOJI} <dim>message</>") - INFO_
EMOJI - Info emoji - use for neutral status (primary status NOT dimmed, metadata may be dimmed)
Primary status:
output::info("All commands already approved")?;Metadata:cformat!("{INFO_EMOJI} <dim>Showing 5 worktrees...</>") - PROGRESS_
EMOJI - Progress emoji:
cformat!("{PROGRESS_EMOJI} <cyan>message</>") - PROMPT_
EMOJI - Prompt emoji - use for questions requiring user input
eprint!("{PROMPT_EMOJI} Proceed? [y/N] ") - SUCCESS_
EMOJI - Success emoji:
cformat!("{SUCCESS_EMOJI} <green>message</>") - WARNING_
EMOJI - Warning emoji:
cformat!("{WARNING_EMOJI} <yellow>message</>")
Functions§
- error_
message - Format an error message with emoji and red styling
- fix_
dim_ after_ color_ reset - Fix dim rendering for terminals that don’t handle \e[2m after \e[39m.
- format_
bash_ with_ gutter - Formats bash/shell commands with syntax highlighting and gutter
- format_
heading - Format a section heading (cyan uppercase text, no emoji)
- format_
toml - Formats TOML content with syntax highlighting using synoptic
- format_
with_ gutter - Formats text with a gutter (single-space with background color) on each line
- get_
terminal_ width - Get terminal width, defaulting to 80 if detection fails
- hint_
message - Format a hint message with emoji and dim styling
- info_
message - Format an info message with emoji (no color - neutral status)
- progress_
message - Format a progress message with emoji and cyan styling
- stderr
- Create an ANSI escape code compatible stderr
- stdout
- Create an ANSI escape code compatible stdout
- success_
message - Format a success message with emoji and green styling
- truncate_
visible - Truncate a styled string to a visible width budget, preserving escapes. Escape sequences (ANSI/OSC) are zero-width; ellipsis is added when truncating. Appends ESC[0m on truncation to avoid style bleed.
- visual_
width - Calculate visual width of a string, ignoring ANSI escape codes
- warning_
message - Format a warning message with emoji and yellow styling