Skip to main content

vtcode_core/utils/ansi/
mod.rs

1use std::io;
2
3use anstream::AutoStream;
4
5use crate::config::ToolDisplayMode;
6use crate::config::loader::SyntaxHighlightingConfig;
7use crate::utils::ansi_capabilities::AnsiCapabilities;
8use vtcode_commons::ui_protocol::{CompactActivityMetadata, ToolOutputId};
9
10pub use crate::utils::message_style::MessageStyle;
11
12mod compact;
13mod core;
14mod links;
15mod markdown;
16mod output;
17mod sink;
18
19use sink::InlineSink;
20
21pub use links::apply_file_opener_config;
22use links::{
23    make_clickable_target, should_strip_inline_local_link_underline, terminal_table_content_width,
24    transcript_table_frame_width,
25};
26use sink::{contains_markdown_fence, looks_like_diff};
27
28/// Renderer with deferred output buffering
29pub struct AnsiRenderer {
30    writer: AutoStream<io::Stdout>,
31    buffer: String,
32    color: bool,
33    sink: Option<InlineSink>,
34    last_line_was_empty: bool,
35    highlight_config: SyntaxHighlightingConfig,
36    capabilities: AnsiCapabilities,
37    reasoning_visible: bool,
38    screen_reader_mode: bool,
39    show_diagnostics_in_transcript: bool,
40    tool_display_mode: ToolDisplayMode,
41    diff_preview_mode: vtcode_commons::ui_protocol::DiffPreviewMode,
42    compact_command_group: Option<CompactActivityMetadata>,
43    next_compact_group_id: u64,
44    pending_tool_output_anchor: Option<ToolOutputId>,
45    /// Capture id for the next exec-session expand notice. Set by the tool
46    /// output handler after recording the complete session capture; consumed
47    /// when the bounded body emits its `click to expand` row.
48    session_expand_anchor: Option<ToolOutputId>,
49    /// Force the next stream body onto the exec-session dim/expand path.
50    /// Needed for `unified_exec` follow-ups: the tool name alone cannot tell a
51    /// session poll from a command launch.
52    session_body: bool,
53}
54
55#[cfg(test)]
56mod tests;