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/// Canonical diagnostic persistence callback installed by the runtime.
29pub use vtcode_commons::diagnostics::DiagnosticSink;
30
31/// Renderer with deferred output buffering
32pub struct AnsiRenderer {
33    writer: AutoStream<io::Stdout>,
34    buffer: String,
35    color: bool,
36    sink: Option<InlineSink>,
37    last_line_was_empty: bool,
38    highlight_config: SyntaxHighlightingConfig,
39    capabilities: AnsiCapabilities,
40    reasoning_visible: bool,
41    screen_reader_mode: bool,
42    show_diagnostics_in_transcript: bool,
43    show_message_timestamps: bool,
44    /// A completed agent response rendered this turn. The single wall-clock
45    /// footer is emitted at turn end so intermediate responses stay unstamped.
46    pending_response_footer: bool,
47    /// Defer the wall-clock footer to the turn boundary.
48    ///
49    /// Armed by [`AnsiRenderer::begin_turn_message_timestamp`] for the duration
50    /// of a turn. Outside a turn (session-exit reprint, pre-turn prompt replies)
51    /// responses stamp immediately, so out-of-turn callers never owe the
52    /// renderer a flush to keep their clock.
53    defer_turn_footer: bool,
54    tool_display_mode: ToolDisplayMode,
55    diff_preview_mode: vtcode_commons::ui_protocol::DiffPreviewMode,
56    compact_command_group: Option<CompactActivityMetadata>,
57    next_compact_group_id: u64,
58    pending_tool_output_anchor: Option<ToolOutputId>,
59    /// Capture id for the next exec-session expand notice. Set by the tool
60    /// output handler after recording the complete session capture; consumed
61    /// when the bounded body emits its `click to expand` row.
62    session_expand_anchor: Option<ToolOutputId>,
63    /// Force the next stream body onto the exec-session dim/expand path.
64    /// Needed for `unified_exec` follow-ups: the tool name alone cannot tell a
65    /// session poll from a command launch.
66    session_body: bool,
67    diagnostic_sink: Option<DiagnosticSink>,
68    diagnostic_history: std::collections::VecDeque<vtcode_commons::diagnostics::Diagnostic>,
69}
70
71#[cfg(test)]
72mod tests;