Module styling

Module styling 

Source
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.
print
Prints to stdout.
println
Prints to stdout, with a newline.

Structs§

AnstyleStyle
ANSI Text styling
FormattedMessage
A message that has already been formatted with emoji and styling.
StyledLine
A line composed of multiple styled strings
StyledString
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