pub fn format_highlighted_command(
command: &str,
span: &HighlightSpan,
use_color: bool,
max_width: usize,
) -> HighlightedCommandExpand description
Format a command with caret highlighting for a single span.
This function:
- Windows long commands to fit within
max_widthcharacters - Generates a caret line (^^^) under the matched span
- Optionally adds a label line below the carets
- Respects color settings for TTY/non-TTY output
§Arguments
command- The full command stringspan- The span to highlight (byte offsets)use_color- Whether to use ANSI color codesmax_width- Maximum display width (defaults toDEFAULT_WINDOW_WIDTH)
§Returns
A HighlightedCommand with the formatted output lines.
§Example
use destructive_command_guard::highlight::{format_highlighted_command, HighlightSpan};
let span = HighlightSpan::with_label(0, 16, "Matched: git reset --hard");
let result = format_highlighted_command("git reset --hard HEAD", &span, false, 80);
assert!(result.command_line.contains("git reset --hard"));
assert!(result.caret_line.contains("^"));