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///
11/// Keep field-compatible with the TUI variant `vtcode_ui::tui::ui::markdown::MarkdownSegment`;
12/// `vtcode-core` picks one of the two by feature and streams both through the same shapes.
13#[derive(Clone, Debug)]
14pub struct MarkdownSegment {
15 style: Style,
16 text: String,
17 link_target: Option<Box<str>>,
18}
19
20/// A single rendered markdown line made up of styled segments.
21#[derive(Clone, Debug, Default)]
22pub struct MarkdownLine {
23 segments: Vec<MarkdownSegment>,
24}
25
26impl MarkdownLine {
27 pub fn is_empty(&self) -> bool {
28 self.segments.iter().all(|segment| segment.text.trim().is_empty())
29 }
30}
31
32/// Options for the markdown rendering pipeline.
33#[derive(Debug, Clone, Copy, Default)]
34pub struct RenderMarkdownOptions {
35 preserve_code_indentation: bool,
36 disable_code_block_table_reparse: bool,
37 /// Available content width for tables. Headered tables use their intrinsic
38 /// column widths when they fit; otherwise they fall back to labeled,
39 /// wrapped blocks. Headerless tables retain their table layout. Only
40 /// effective in TUI mode.
41 table_max_width: Option<usize>,
42}
43
44/// A syntax-highlighted text segment.
45#[derive(Clone, Debug)]
46pub struct HighlightedSegment {
47 style: Style,
48 text: String,
49}