vtcode_commons/ui_protocol/markdown.rs
1//! Shared markdown rendering types.
2//!
3//! The actual rendering implementation lives in `vtcode-tui`. 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 pub style: Style,
13 pub text: String,
14 pub 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 pub segments: Vec<MarkdownSegment>,
21}
22
23impl MarkdownLine {
24 pub fn is_empty(&self) -> bool {
25 self.segments
26 .iter()
27 .all(|segment| segment.text.trim().is_empty())
28 }
29}
30
31/// Options for the markdown rendering pipeline.
32#[derive(Debug, Clone, Copy, Default)]
33pub struct RenderMarkdownOptions {
34 pub preserve_code_indentation: bool,
35 pub disable_code_block_table_reparse: bool,
36 /// Maximum width for tables. When set, tables wider than this will have
37 /// their column widths proportionally scaled and cell text wrapped.
38 /// Only effective in TUI mode.
39 pub table_max_width: Option<usize>,
40}
41
42/// A syntax-highlighted text segment.
43#[derive(Clone, Debug)]
44pub struct HighlightedSegment {
45 pub style: Style,
46 pub text: String,
47}