vtcode_commons/ui_protocol/markdown.rs
1//! Shared markdown rendering types.
2//!
3//! The actual rendering implementation lives in `vtcode-ui`. These structs
4//! define the output format so that `vtcode-core` can work with rendered
5//! markdown lines regardless of whether the TUI crate is compiled in.
6
7use anstyle::Style;
8
9/// A styled segment inside a rendered markdown line.
10#[derive(Clone, Debug)]
11pub struct MarkdownSegment {
12 style: Style,
13 text: String,
14 link_target: Option<String>,
15}
16
17/// A single rendered markdown line made up of styled segments.
18#[derive(Clone, Debug, Default)]
19pub struct MarkdownLine {
20 segments: Vec<MarkdownSegment>,
21}
22
23impl MarkdownLine {
24 pub fn is_empty(&self) -> bool {
25 self.segments.iter().all(|segment| segment.text.trim().is_empty())
26 }
27}
28
29/// Options for the markdown rendering pipeline.
30#[derive(Debug, Clone, Copy, Default)]
31pub struct RenderMarkdownOptions {
32 preserve_code_indentation: bool,
33 disable_code_block_table_reparse: bool,
34 /// Available content width for tables. Headered tables use their intrinsic
35 /// column widths when they fit; otherwise they fall back to labeled,
36 /// wrapped blocks. Headerless tables retain their table layout. Only
37 /// effective in TUI mode.
38 table_max_width: Option<usize>,
39}
40
41/// A syntax-highlighted text segment.
42#[derive(Clone, Debug)]
43pub struct HighlightedSegment {
44 style: Style,
45 text: String,
46}