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    tool_display_mode: ToolDisplayMode,
44    diff_preview_mode: vtcode_commons::ui_protocol::DiffPreviewMode,
45    compact_command_group: Option<CompactActivityMetadata>,
46    next_compact_group_id: u64,
47    pending_tool_output_anchor: Option<ToolOutputId>,
48    /// Capture id for the next exec-session expand notice. Set by the tool
49    /// output handler after recording the complete session capture; consumed
50    /// when the bounded body emits its `click to expand` row.
51    session_expand_anchor: Option<ToolOutputId>,
52    /// Force the next stream body onto the exec-session dim/expand path.
53    /// Needed for `unified_exec` follow-ups: the tool name alone cannot tell a
54    /// session poll from a command launch.
55    session_body: bool,
56    diagnostic_sink: Option<DiagnosticSink>,
57    diagnostic_history: std::collections::VecDeque<vtcode_commons::diagnostics::Diagnostic>,
58}
59
60#[cfg(test)]
61mod tests;