Skip to main content

vtcode_config/constants/
ui.rs

1pub const TOOL_OUTPUT_MODE_COMPACT: &str = "compact";
2pub const TOOL_OUTPUT_MODE_FULL: &str = "full";
3pub const DEFAULT_INLINE_VIEWPORT_ROWS: u16 = 16;
4pub const DEFAULT_REASONING_VISIBLE: bool = true;
5pub const MODAL_MIN_WIDTH: u16 = 36;
6pub const MODAL_MIN_HEIGHT: u16 = 16;
7pub const MODAL_INSTRUCTIONS_BULLET: &str = "•";
8pub const INLINE_HEADER_HEIGHT: u16 = 3;
9pub const INLINE_INPUT_PADDING_HORIZONTAL: u16 = 1;
10pub const INLINE_INPUT_PADDING_VERTICAL: u16 = 1;
11pub const INLINE_INPUT_MAX_LINES: usize = 10;
12/// Transcript bottom padding rows. Live value:
13/// `vtcode_ui::tui::config::constants::ui::INLINE_TRANSCRIPT_BOTTOM_PADDING`
14/// with `effective_transcript_bottom_padding`; keep in sync.
15pub const INLINE_TRANSCRIPT_BOTTOM_PADDING: u16 = 2;
16pub const INLINE_PREVIEW_ELLIPSIS: &str = "…";
17pub const INLINE_PASTE_COLLAPSE_LINE_THRESHOLD: usize = 10;
18pub const HEADER_HIGHLIGHT_PREVIEW_MAX_CHARS: usize = 48;
19pub const INLINE_AGENT_MESSAGE_LEFT_PADDING: &str = " ";
20pub const INLINE_AGENT_QUOTE_PREFIX: &str = " •";
21pub const INLINE_USER_MESSAGE_DIVIDER_SYMBOL: &str = "─";
22
23pub const INLINE_BLOCK_HORIZONTAL: &str = "─";
24/// Shared inline separator between metadata segments (`a • b • c`).
25///
26/// Single source for every `" • "` join so spacing stays consistent across
27/// headers, modals, and slash-command detail lines.
28pub const META_BULLET_SEPARATOR: &str = " • ";
29pub const MODAL_LIST_HIGHLIGHT_FULL: &str = "┃ ";
30pub const MODAL_LIST_SUMMARY_NO_MATCHES: &str = "No matches";
31pub const MODAL_LIST_SUMMARY_RESET_HINT: &str = "Press Esc to reset";
32pub const MODAL_LIST_NO_RESULTS_MESSAGE: &str = "No matching options";
33pub const HEADER_VERSION_PROMPT: &str = "> ";
34pub const HEADER_VERSION_PREFIX: &str = "VT Code";
35pub const HEADER_VERSION_LEFT_DELIMITER: &str = "(";
36pub const HEADER_VERSION_RIGHT_DELIMITER: &str = ")";
37pub const HEADER_PROVIDER_PREFIX: &str = "Provider: ";
38pub const HEADER_MODEL_PREFIX: &str = "Model: ";
39pub const HEADER_SERVICE_TIER_PREFIX: &str = "Tier: ";
40pub const HEADER_COMPUTER_USE_PREFIX: &str = "Computer use: ";
41pub const HEADER_REASONING_PREFIX: &str = "";
42pub const HEADER_TRUST_PREFIX: &str = "Trust: ";
43pub const HEADER_TOOLS_PREFIX: &str = "Tools: ";
44pub const HEADER_MCP_PREFIX: &str = "MCP: ";
45pub const HEADER_GIT_PREFIX: &str = "git: ";
46pub const HEADER_GIT_CLEAN_SUFFIX: &str = "✓";
47pub const HEADER_GIT_DIRTY_SUFFIX: &str = "*";
48pub const HEADER_UNKNOWN_PLACEHOLDER: &str = "unavailable";
49/// Shortcut hints shared by the bootstrap and follow-up placeholders.
50///
51/// Defined once so the two cannot drift apart. The composer paints this on a
52/// single clipped line, so the most useful hints lead and trailing ones fall
53/// off first on narrow terminals.
54///
55/// Each key must match a live binding: `@`/`/` open the file and slash
56/// palettes, Enter submits, `Tab` queues while a turn runs, `Shift+Tab` cycles
57/// to the previous agent, and `Ctrl+R` opens the history picker.
58macro_rules! chat_input_shortcut_hint {
59    () => {
60        "@files /commands • Enter run • Tab queue • Shift+Tab agent • Ctrl+R history"
61    };
62}
63/// Empty-composer prompt before the first turn.
64pub const CHAT_INPUT_PLACEHOLDER_BOOTSTRAP: &str = concat!("Type a request… ", chat_input_shortcut_hint!());
65/// Empty-composer prompt after at least one turn.
66pub const CHAT_INPUT_PLACEHOLDER_FOLLOW_UP: &str = concat!("Continue… ", chat_input_shortcut_hint!());
67pub const CHAT_INPUT_PLACEHOLDER_INTERRUPTED: &str =
68    "Interrupted · What should VT Code do instead? • Esc cancel • Ctrl+C interrupt • Ctrl+D exit";
69pub const WELCOME_SLASH_COMMAND_LIMIT: usize = 6;
70pub const WELCOME_SLASH_COMMAND_PREFIX: &str = "/";
71pub const WELCOME_SLASH_COMMAND_INTRO: &str = "";
72pub const WELCOME_SLASH_COMMAND_INDENT: &str = "  ";
73pub const PLAN_BLOCK_TITLE: &str = "TODOs";
74pub const PLAN_STATUS_EMPTY: &str = "No TODOs";
75pub(crate) const STATUS_LINE_REFRESH_INTERVAL_MS: u64 = 1000;
76pub(crate) const STATUS_LINE_COMMAND_TIMEOUT_MS: u64 = 200;
77
78// Agent/Mode color constants.
79//
80// Mode badges resolve through one canonical token per mode. Most modes use a
81// **standard ANSI hue name** (green/blue/magenta/...), which the design system
82// (`vtcode-ui`) maps to a theme-appropriate variant at render time: the
83// brighter `Light*` ANSI variant on dark terminals, the base variant on light
84// terminals. Build is the exception: it uses a fixed hex token that renders
85// identically on both appearances.
86//
87// `AGENT_HUE_NAMES` mirrors the variant table in `vtcode-ui`'s design color
88// resolver, which owns the actual RGB values.
89const AGENT_HUE_NAMES: &[&str] = &["red", "green", "blue", "magenta", "yellow", "cyan"];
90
91/// Build agent color - sage `#73a18e` (calm, implementation tone).
92pub const AGENT_COLOR_BUILD: &str = "#73a18e";
93/// Auto agent hue - green (autonomy and forward progress).
94pub const AGENT_COLOR_AUTO: &str = "green";
95/// Plan agent hue - blue (thoughtful, planning tone).
96pub const AGENT_COLOR_PLAN: &str = "blue";
97/// Duck agent hue - magenta (soft, discussion-focused).
98pub const AGENT_COLOR_DUCK: &str = "magenta";
99
100/// Canonical primary-agent mode -> color token mapping (single source of
101/// truth). `subagents.rs` assigns the color to each built-in spec from here.
102const AGENT_MODE_HUE: &[(&str, &str)] = &[
103    ("build", AGENT_COLOR_BUILD),
104    ("auto", AGENT_COLOR_AUTO),
105    ("plan", AGENT_COLOR_PLAN),
106    ("duck", AGENT_COLOR_DUCK),
107];
108
109/// Resolve a primary-agent mode name to its canonical color token
110/// (e.g. `"build"` -> `"#73a18e"`, `"plan"` -> `"blue"`).
111pub fn agent_mode_hue(mode: &str) -> Option<&'static str> {
112    AGENT_MODE_HUE.iter().find(|(m, _)| *m == mode).map(|(_, h)| *h)
113}
114
115// TUI timing, tick, and viewport limits live in
116// `vtcode_ui::tui::config::constants::ui` — the only reader. Do not redeclare
117// them here: shadowed copies drift silently (see `no_shadowed_tui_constants`).
118
119// Theme and color constants
120pub const THEME_MIN_CONTRAST_RATIO: f32 = 4.5;
121/// WCAG AAA floor applied when `ui.high_contrast_mode` is enabled.
122pub const THEME_HIGH_CONTRAST_RATIO: f32 = 7.0;
123/// Luminance where white and black text reach the same WCAG contrast ratio;
124/// drives the filled-control foreground choice (`filled_text`).
125pub const THEME_FILLED_TEXT_LUMINANCE_CROSSOVER: f32 = 0.179;
126
127pub const THEME_FOREGROUND_LIGHTEN_RATIO: f32 = 0.25;
128pub const THEME_SECONDARY_LIGHTEN_RATIO: f32 = 0.2;
129pub const THEME_MIX_RATIO: f32 = 0.35;
130pub const THEME_TOOL_BODY_MIX_RATIO: f32 = 0.35;
131pub const THEME_TOOL_BODY_LIGHTEN_RATIO: f32 = 0.2;
132pub const THEME_RESPONSE_COLOR_LIGHTEN_RATIO: f32 = 0.15;
133pub const THEME_INPUT_BACKGROUND_MIX_RATIO: f32 = 0.08;
134pub const THEME_USER_COLOR_LIGHTEN_RATIO: f32 = 0.2;
135pub const THEME_SECONDARY_USER_COLOR_LIGHTEN_RATIO: f32 = 0.4;
136pub const THEME_PRIMARY_STATUS_LIGHTEN_RATIO: f32 = 0.35;
137pub const THEME_PRIMARY_STATUS_SECONDARY_LIGHTEN_RATIO: f32 = 0.5;
138pub const THEME_LOGO_ACCENT_BANNER_LIGHTEN_RATIO: f32 = 0.35;
139pub const THEME_LOGO_ACCENT_BANNER_SECONDARY_LIGHTEN_RATIO: f32 = 0.25;
140
141// UI Color constants
142pub const THEME_COLOR_WHITE_RED: u8 = 0xFF;
143pub const THEME_COLOR_WHITE_GREEN: u8 = 0xFF;
144pub const THEME_COLOR_WHITE_BLUE: u8 = 0xFF;
145pub const THEME_MIX_RATIO_MIN: f32 = 0.0;
146pub const THEME_MIX_RATIO_MAX: f32 = 1.0;
147pub const THEME_BLEND_CLAMP_MIN: f32 = 0.0;
148pub const THEME_BLEND_CLAMP_MAX: f32 = 255.0;
149
150// WCAG contrast algorithm constants
151pub const THEME_RELATIVE_LUMINANCE_CUTOFF: f32 = 0.03928;
152pub const THEME_RELATIVE_LUMINANCE_LOW_FACTOR: f32 = 12.92;
153pub const THEME_RELATIVE_LUMINANCE_OFFSET: f32 = 0.055;
154pub const THEME_RELATIVE_LUMINANCE_EXPONENT: f32 = 2.4;
155pub const THEME_CONTRAST_RATIO_OFFSET: f32 = 0.05;
156pub const THEME_RED_LUMINANCE_COEFFICIENT: f32 = 0.2126;
157pub const THEME_GREEN_LUMINANCE_COEFFICIENT: f32 = 0.7152;
158pub const THEME_BLUE_LUMINANCE_COEFFICIENT: f32 = 0.0722;
159pub const THEME_LUMINANCE_LIGHTEN_RATIO: f32 = 0.2;
160/// Mix ratio for PTY output text toward background — dim but readable (higher = dimmer)
161pub const THEME_PTY_OUTPUT_MIX_RATIO: f32 = 0.50;
162
163/// Medium gray for input placeholder text
164pub const PLACEHOLDER_R: u8 = 0x88;
165pub const PLACEHOLDER_G: u8 = 0x88;
166pub const PLACEHOLDER_B: u8 = 0x88;
167
168// Safe ANSI palette. Terminal color portability research:
169// <https://blog.xoria.org/terminal-colors/>
170// Only the bright-cyan index is shared with the config layer; the rest of the
171// palette lives in `vtcode_ui::tui::config::constants::ui`.
172
173/// Bright cyan (ANSI 14) — used for modal list title/border accents.
174pub const SAFE_ANSI_BRIGHT_CYAN: u8 = 14;
175
176#[cfg(test)]
177mod tests {
178    use super::*;
179
180    /// Representative terminal backgrounds the agent badge is rendered against.
181    /// A near-black dark theme (Catppuccin Mocha / Gruvbox) and a near-white
182    /// light theme (Solarized Light / Catppuccin Latte).
183    const DARK_BG: (u8, u8, u8) = (0x18, 0x18, 0x18);
184    const LIGHT_BG: (u8, u8, u8) = (0xFD, 0xF6, 0xE3);
185
186    /// Parse a `#rrggbb` token to its RGB triple. Returns `None` for anything
187    /// else (hue names fall through to the variant table below).
188    fn hex_to_rgb(hex: &str) -> Option<(u8, u8, u8)> {
189        let hex = hex.strip_prefix('#')?;
190        if hex.len() != 6 || !hex.bytes().all(|b| b.is_ascii_hexdigit()) {
191            return None;
192        }
193        let channel = |i: usize| u8::from_str_radix(&hex[i..i + 2], 16).ok();
194        Some((channel(0)?, channel(2)?, channel(4)?))
195    }
196
197    /// Standard ANSI variant RGB values used by the design system for each hue
198    /// (base + bright), plus the fixed Build hex. Hue badges pick the bright
199    /// variant on dark and the base variant on light, so both appearances stay
200    /// readable; the hex renders identically on both.
201    fn hue_rgb_on(hue: &str, light: bool) -> Option<(u8, u8, u8)> {
202        if let Some(rgb) = hex_to_rgb(hue) {
203            return Some(rgb);
204        }
205        let (d, l) = match hue {
206            "red" => ((0xFF, 0x5F, 0x5F), (0xCD, 0x00, 0x00)),
207            "green" => ((0x5F, 0xFF, 0x5F), (0x00, 0xCD, 0x00)),
208            "blue" => ((0x5F, 0x5F, 0xFF), (0x00, 0x00, 0xCD)),
209            "magenta" => ((0xFF, 0x5F, 0xFF), (0xCD, 0x00, 0xCD)),
210            "yellow" => ((0xFF, 0xFF, 0x5F), (0xCD, 0xCD, 0x00)),
211            "cyan" => ((0x5F, 0xFF, 0xFF), (0x00, 0xCD, 0xCD)),
212            _ => return None,
213        };
214        Some(if light { l } else { d })
215    }
216
217    fn channel_lin(c: u8) -> f32 {
218        let c = c as f32 / 255.0;
219        if c <= 0.03928 {
220            c / 12.92
221        } else {
222            ((c + 0.055) / 1.055).powf(2.4)
223        }
224    }
225
226    fn relative_luminance((r, g, b): (u8, u8, u8)) -> f32 {
227        0.2126 * channel_lin(r) + 0.7152 * channel_lin(g) + 0.0722 * channel_lin(b)
228    }
229
230    fn contrast_ratio(fg: (u8, u8, u8), bg: (u8, u8, u8)) -> f32 {
231        let l_fg = relative_luminance(fg);
232        let l_bg = relative_luminance(bg);
233        let (hi, lo) = if l_fg > l_bg { (l_fg, l_bg) } else { (l_bg, l_fg) };
234        (hi + 0.05) / (lo + 0.05)
235    }
236
237    /// Each mode color must resolve to a variant that stays legible on its
238    /// matching background. Dark terminals clear the WCAG "large/bold text"
239    /// 3:1 bar comfortably. On light terminals the ANSI hues clear 3:1 except
240    /// green (~2:1 — the best a standard `Green` code can do against white),
241    /// and the Build hex clears 2.7:1, so the light threshold stays at 2:1.
242    const MIN_CONTRAST_DARK: f32 = 3.0;
243    const MIN_CONTRAST_LIGHT: f32 = 2.0;
244
245    fn assert_agent_hue_readable(name: &str, hue: &str, light: bool, bg: (u8, u8, u8)) {
246        let fg =
247            hue_rgb_on(hue, light).unwrap_or_else(|| panic!("{name} ({hue}) is not a supported standard ANSI hue"));
248        let cr = contrast_ratio(fg, bg);
249        let min = if light { MIN_CONTRAST_LIGHT } else { MIN_CONTRAST_DARK };
250        assert!(
251            cr >= min,
252            "{name} ({hue}) on {} bg contrast {cr:.2} below {min}",
253            if light { "light" } else { "dark" }
254        );
255    }
256
257    #[test]
258    fn agent_mode_color_tokens_are_supported() {
259        for (_, hue) in AGENT_MODE_HUE {
260            let supported = AGENT_HUE_NAMES.contains(hue) || hex_to_rgb(hue).is_some();
261            assert!(supported, "mode token {hue} is neither a standard ANSI hue nor #rrggbb");
262        }
263    }
264
265    #[test]
266    fn agent_mode_colors_are_readable_in_dark_and_light_terminals() {
267        for (mode, hue) in AGENT_MODE_HUE {
268            // Dark terminals use the bright variant; light terminals the base.
269            assert_agent_hue_readable(mode, hue, false, DARK_BG);
270            assert_agent_hue_readable(mode, hue, true, LIGHT_BG);
271        }
272    }
273
274    /// The four mode colors must be visually distinct from one another so the
275    /// user can tell Build / Auto / Plan / Duck apart at a glance.
276    #[test]
277    fn agent_mode_colors_are_distinct() {
278        let hues: Vec<&str> = AGENT_MODE_HUE.iter().map(|(_, h)| *h).collect();
279        for i in 0..hues.len() {
280            for j in (i + 1)..hues.len() {
281                assert_ne!(hues[i], hues[j], "mode hues {} and {} are identical", hues[i], hues[j]);
282            }
283        }
284    }
285
286    #[test]
287    fn agent_mode_hue_resolves_mode_names() {
288        assert_eq!(agent_mode_hue("build"), Some(AGENT_COLOR_BUILD));
289        assert_eq!(agent_mode_hue("auto"), Some(AGENT_COLOR_AUTO));
290        assert_eq!(agent_mode_hue("plan"), Some(AGENT_COLOR_PLAN));
291        assert_eq!(agent_mode_hue("duck"), Some(AGENT_COLOR_DUCK));
292        assert_eq!(agent_mode_hue("unknown"), None);
293    }
294
295    #[test]
296    fn agent_mode_colors_are_wired_into_builtin_primary_agents() {
297        // Guards against the constants drifting from the specs that expose them.
298        assert_eq!(AGENT_COLOR_BUILD, "#73a18e");
299        assert_eq!(AGENT_COLOR_AUTO, "green");
300        assert_eq!(AGENT_COLOR_PLAN, "blue");
301        assert_eq!(AGENT_COLOR_DUCK, "magenta");
302    }
303
304    /// Chat placeholders share one hint fragment so they cannot drift apart.
305    #[test]
306    fn chat_input_placeholders_share_one_shortcut_hint() {
307        let hint = chat_input_shortcut_hint!();
308        assert!(CHAT_INPUT_PLACEHOLDER_BOOTSTRAP.ends_with(hint));
309        assert!(CHAT_INPUT_PLACEHOLDER_FOLLOW_UP.ends_with(hint));
310        assert!(CHAT_INPUT_PLACEHOLDER_BOOTSTRAP.starts_with("Type a request"));
311        assert!(CHAT_INPUT_PLACEHOLDER_FOLLOW_UP.starts_with("Continue"));
312        assert_ne!(CHAT_INPUT_PLACEHOLDER_BOOTSTRAP, CHAT_INPUT_PLACEHOLDER_FOLLOW_UP);
313    }
314
315    /// The metadata bullet separator has exactly one definition.
316    ///
317    /// Every `" • "` join reaches this constant instead of re-typing the
318    /// literal, so spacing changes land in one place.
319    #[test]
320    fn meta_bullet_separator_is_the_single_source() {
321        assert_eq!(META_BULLET_SEPARATOR, " • ");
322    }
323
324    /// Ratchet against the duplication that made this module rot.
325    ///
326    /// These constants were removed because `vtcode-ui` defines its own copy
327    /// under `tui::config::constants::ui` and never reads the one here, so the
328    /// two silently diverged. Re-adding any of them recreates that trap; the
329    /// TUI value is the live one, so edit it there instead.
330    #[test]
331    fn removed_shadowed_tui_constants_stay_removed() {
332        const SHADOWED: &[&str] = &[
333            "TUI_ACTIVE_TICK_RATE_HZ",
334            "TUI_IDLE_TICK_RATE_HZ",
335            "TUI_ACTIVE_TIMEOUT_MS",
336            "TUI_SHIMMER_FRAME_INTERVAL_MS",
337            "TUI_SHIMMER_SWEEP_DURATION_MS",
338            "TUI_SCROLL_CURSOR_STEADY_MS",
339            "TUI_MAX_VIEWPORT_WIDTH",
340            "TUI_MAX_VIEWPORT_HEIGHT",
341            "MODAL_WIDTH_RATIO",
342            "MODAL_HEIGHT_RATIO",
343            "MODAL_MAX_WIDTH_RATIO",
344            "MODAL_MAX_HEIGHT_RATIO",
345            "SLASH_PALETTE_MIN_WIDTH",
346            "SLASH_PALETTE_MIN_HEIGHT",
347            "HEADER_SHORTCUT_HINT",
348            "SCROLL_INDICATOR_FORMAT",
349            "HEADER_META_SEPARATOR",
350            "SLASH_PALETTE_TOP_OFFSET",
351        ];
352        // Source-level assertion: these names must not be declared here again.
353        let src = include_str!("ui.rs");
354        for name in SHADOWED {
355            let declared = src.lines().any(|line| {
356                let trimmed = line.trim_start();
357                trimmed
358                    .strip_prefix("pub const ")
359                    .or_else(|| trimmed.strip_prefix("pub(crate) const "))
360                    .is_some_and(|rest| rest.starts_with(&format!("{name}:")))
361            });
362            assert!(!declared, "`{name}` is shadowed by vtcode-ui; declare the live value there, not here");
363        }
364    }
365}