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 keep a padded,
38 /// width-aware grid while cells remain readable, then fall back to aligned
39 /// labeled records when the grid becomes too cramped. Headerless tables
40 /// retain their grid layout and scale columns to fit. Only effective in
41 /// TUI mode.
42 table_max_width: Option<usize>,
43}
44
45/// A syntax-highlighted text segment.
46#[derive(Clone, Debug)]
47pub struct HighlightedSegment {
48 style: Style,
49 text: String,
50}