Skip to main content

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: Primary data output (table data, JSON, statusline)
  • stderr: Status messages (progress, success, errors, hints, warnings)

This separation allows piping (wt list | grep foo) without status messages interfering. Use println! for primary output, eprintln! for status messages.

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

Enums§

Stream
possible stream sources

Constants§

ADDITION
Addition style for diffs (green) - used in table rendering
DEFAULT_HELP_WIDTH
Default width for help text rendering when terminal width is unknown. Used in both the CLI binary and tests for consistent output in docs.
DELETION
Deletion style for diffs (red) - used in table rendering
ERROR_SYMBOL
Error symbol (red ✗)
GUTTER
Gutter style for quoted content (commands, config, error details)
GUTTER_OVERHEAD
Width overhead added by format_with_gutter()
HINT_SYMBOL
Hint symbol (dim ↳)
INFO_SYMBOL
Info symbol (dim ○) - for neutral status
PROGRESS_SYMBOL
Progress symbol (cyan ◎)
PROMPT_SYMBOL
Prompt symbol (cyan ❯) - for questions requiring user input
SUCCESS_SYMBOL
Success symbol (green ✓)
WARNING_SYMBOL
Warning symbol (yellow ▲)

Functions§

error_message
Format an error message with symbol 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
hint_message
Format a hint message with symbol and dim styling
hyperlink_stdout
Format text as a clickable hyperlink for stdout, or return plain text if unsupported.
info_message
Format an info message with symbol (no color on text - neutral status)
progress_message
Format a progress message with symbol and cyan styling
prompt_message
Format a prompt message with symbol and cyan styling
set_verbosity
Set the global verbosity level.
stderr
Create an ANSI escape code compatible stderr
stdout
Create an ANSI escape code compatible stdout
strip_osc8_hyperlinks
Strip OSC 8 hyperlinks while preserving other ANSI sequences (colors).
success_message
Format a success message with symbol and green styling
suggest_command
Build a suggested command string for hints.
suggest_command_in_dir
Like suggest_command, but prepends -C <path> for commands targeting a specific worktree directory.
supports_hyperlinks
Returns true if stream is a TTY, and the current terminal supports_hyperlinks.
terminal_width
Get terminal width, or usize::MAX if detection fails.
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.
verbosity
Get the current verbosity level.
visual_width
Calculate visual width of a string, ignoring ANSI escape codes
warning_message
Format a warning message with symbol and yellow styling
wrap_styled_text
Wrap ANSI-styled text at word boundaries, preserving styles across line breaks