1use anyhow::{Result, anyhow, bail};
2use hashbrown::HashMap;
3use serde::{Deserialize, Serialize};
4
5use crate::accessibility::reduce_motion_preference;
6use crate::status_line::StatusLineConfig;
7use crate::terminal_title::TerminalTitleConfig;
8use vtcode_commons::ui_protocol::AmbiguousWidthMode;
9use vtcode_commons::ui_protocol::AppIconPreference;
10use vtcode_commons::ui_protocol::BusyEnterBehavior;
11use vtcode_commons::ui_protocol::DiffPreviewMode;
12
13mod modes;
14
15pub use modes::{
16 LayoutModeOverride, NotificationBackend, NotificationDeliveryMode, ReasoningDisplayMode, ToolDisplayMode,
17 ToolOutputMode, UiDisplayMode,
18};
19
20mod notifications;
21
22pub use notifications::UiNotificationsConfig;
23
24#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
25#[derive(Debug, Clone, Deserialize, Serialize)]
26pub struct UiFullscreenConfig {
27 #[serde(default = "default_fullscreen_mouse_capture")]
30 pub mouse_capture: bool,
31
32 #[serde(default = "default_fullscreen_copy_on_select")]
38 pub copy_on_select: bool,
39
40 #[serde(default = "default_fullscreen_scroll_speed")]
44 pub scroll_speed: u8,
45}
46
47impl Default for UiFullscreenConfig {
48 fn default() -> Self {
49 Self {
50 mouse_capture: default_fullscreen_mouse_capture(),
51 copy_on_select: default_fullscreen_copy_on_select(),
52 scroll_speed: default_fullscreen_scroll_speed(),
53 }
54 }
55}
56
57#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
61#[derive(Debug, Clone, Deserialize, Serialize)]
62pub struct UiTranscriptReviewConfig {
63 #[serde(default = "default_transcript_review_control")]
65 pub show_hints: bool,
66
67 #[serde(default = "default_transcript_review_control")]
69 pub show_shortcut_guide: bool,
70
71 #[serde(default = "default_transcript_review_control")]
73 pub show_close_button: bool,
74}
75
76impl Default for UiTranscriptReviewConfig {
77 fn default() -> Self {
78 Self {
79 show_hints: default_transcript_review_control(),
80 show_shortcut_guide: default_transcript_review_control(),
81 show_close_button: default_transcript_review_control(),
82 }
83 }
84}
85
86#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
87#[derive(Debug, Clone, Deserialize, Serialize)]
88pub struct UiConfig {
89 #[serde(default = "default_tool_output_mode")]
91 pub tool_output_mode: ToolOutputMode,
92
93 #[serde(default = "default_tool_display_mode")]
96 pub tool_display_mode: ToolDisplayMode,
97
98 #[serde(default = "default_verb_callouts")]
102 pub verb_callouts: bool,
103
104 #[serde(default, alias = "key_bindings")]
107 #[cfg_attr(
108 feature = "schema",
109 schemars(with = "std::collections::BTreeMap<String, Vec<String>>")
110 )]
111 pub keybindings: HashMap<String, Vec<String>>,
112
113 #[serde(default = "default_tool_output_max_lines")]
115 pub tool_output_max_lines: usize,
116
117 #[serde(default = "default_tool_output_spool_bytes")]
119 pub tool_output_spool_bytes: usize,
120
121 #[serde(default)]
123 pub tool_output_spool_dir: Option<String>,
124
125 #[serde(default = "default_allow_tool_ansi")]
127 pub allow_tool_ansi: bool,
128
129 #[serde(default = "default_inline_viewport_rows")]
131 pub inline_viewport_rows: u16,
132
133 #[serde(default = "default_reasoning_display_mode")]
135 pub reasoning_display_mode: ReasoningDisplayMode,
136
137 #[serde(default = "default_reasoning_visible_default")]
139 pub reasoning_visible_default: bool,
140
141 #[serde(default = "default_thinking_display")]
143 pub thinking_display: vtcode_commons::ui_protocol::ThinkingBlockState,
144
145 #[serde(default = "default_communication_style")]
147 pub communication_style: vtcode_commons::ui_protocol::CommunicationStyle,
148
149 #[serde(default = "default_vim_mode")]
151 pub vim_mode: bool,
152
153 #[serde(default = "default_busy_enter_behavior")]
158 pub busy_enter_behavior: BusyEnterBehavior,
159
160 #[serde(default)]
162 pub status_line: StatusLineConfig,
163
164 #[serde(default)]
166 pub terminal_title: TerminalTitleConfig,
167
168 #[serde(default)]
170 pub keyboard_protocol: KeyboardProtocolConfig,
171
172 #[serde(default)]
174 pub layout_mode: LayoutModeOverride,
175
176 #[serde(default)]
178 pub display_mode: UiDisplayMode,
179
180 #[serde(default = "default_show_sidebar")]
182 pub show_sidebar: bool,
183
184 #[serde(default = "default_dim_completed_todos")]
186 pub dim_completed_todos: bool,
187
188 #[serde(default = "default_show_task_panel")]
192 pub show_task_panel: bool,
193
194 #[serde(default = "default_message_block_spacing")]
196 pub message_block_spacing: bool,
197
198 #[serde(default = "default_show_turn_timer")]
200 pub show_turn_timer: bool,
201
202 #[serde(default = "default_show_diagnostics_in_transcript")]
206 pub show_diagnostics_in_transcript: bool,
207
208 #[serde(default = "default_show_message_timestamps")]
210 pub show_message_timestamps: bool,
211
212 #[serde(default = "default_minimum_contrast")]
220 pub minimum_contrast: f32,
221
222 #[serde(default = "default_high_contrast_mode")]
226 pub high_contrast_mode: bool,
227
228 #[serde(default = "default_bold_is_bright")]
232 pub bold_is_bright: bool,
233
234 #[serde(default = "default_ambiguous_width")]
244 pub ambiguous_width: AmbiguousWidthMode,
245
246 #[serde(default = "default_safe_colors_only")]
252 pub safe_colors_only: bool,
253
254 #[serde(default = "default_color_scheme_mode")]
259 pub color_scheme_mode: ColorSchemeMode,
260
261 #[serde(default = "default_app_icon")]
268 pub app_icon: AppIconPreference,
269
270 #[serde(default)]
272 pub program_status: UiProgramStatusConfig,
273
274 #[serde(default)]
276 pub notifications: UiNotificationsConfig,
277
278 #[serde(default)]
280 pub fullscreen: UiFullscreenConfig,
281
282 #[serde(default = "default_screen_reader_mode")]
287 pub screen_reader_mode: bool,
288
289 #[serde(default = "default_reduce_motion_mode")]
293 pub reduce_motion_mode: bool,
294
295 #[serde(default = "default_reduce_motion_keep_progress_animation")]
298 pub reduce_motion_keep_progress_animation: bool,
299
300 #[serde(default = "default_hide_header")]
302 pub hide_header: bool,
303
304 #[serde(default = "default_diff_preview_mode")]
307 pub diff_preview_mode: DiffPreviewMode,
308
309 #[serde(default)]
311 pub transcript_review: UiTranscriptReviewConfig,
312}
313
314#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
316#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, Default)]
317#[serde(rename_all = "snake_case")]
318pub enum ColorSchemeMode {
319 #[default]
321 Auto,
322 Light,
324 Dark,
326 #[serde(other)]
328 Unknown,
329}
330
331fn default_minimum_contrast() -> f32 {
332 crate::constants::ui::THEME_MIN_CONTRAST_RATIO
333}
334
335fn default_high_contrast_mode() -> bool {
336 env_bool_var("VTCODE_HIGH_CONTRAST").unwrap_or(false)
337}
338
339fn default_bold_is_bright() -> bool {
340 false
341}
342
343fn default_safe_colors_only() -> bool {
344 false
345}
346
347fn default_color_scheme_mode() -> ColorSchemeMode {
348 ColorSchemeMode::Auto
349}
350
351fn default_app_icon() -> AppIconPreference {
352 AppIconPreference::Dynamic
353}
354
355fn default_show_sidebar() -> bool {
356 true
357}
358
359fn default_dim_completed_todos() -> bool {
360 true
361}
362
363fn default_message_block_spacing() -> bool {
364 true
365}
366
367fn default_program_status_enabled() -> bool {
368 true
369}
370
371fn default_show_turn_timer() -> bool {
372 false
373}
374
375fn default_show_diagnostics_in_transcript() -> bool {
376 false
377}
378
379fn default_show_message_timestamps() -> bool {
380 true
381}
382
383fn default_vim_mode() -> bool {
384 false
385}
386
387fn default_busy_enter_behavior() -> BusyEnterBehavior {
388 BusyEnterBehavior::Queue
389}
390
391fn env_bool_var(name: &str) -> Option<bool> {
392 crate::env_helpers::read_env_var(name).and_then(|v| vtcode_commons::utils::parse_bool_env_value(&v))
393}
394
395fn env_u8_var(name: &str) -> Option<u8> {
396 crate::env_helpers::read_env_var(name)
397 .and_then(|value| value.trim().parse::<u8>().ok())
398 .map(clamp_fullscreen_scroll_speed)
399}
400
401fn clamp_fullscreen_scroll_speed(value: u8) -> u8 {
402 value.clamp(1, 20)
403}
404
405fn default_fullscreen_mouse_capture() -> bool {
406 env_bool_var("VTCODE_FULLSCREEN_MOUSE_CAPTURE").unwrap_or(true)
407}
408
409fn default_fullscreen_copy_on_select() -> bool {
410 env_bool_var("VTCODE_FULLSCREEN_COPY_ON_SELECT").unwrap_or(true)
411}
412
413fn default_fullscreen_scroll_speed() -> u8 {
414 env_u8_var("VTCODE_FULLSCREEN_SCROLL_SPEED").unwrap_or(3)
415}
416
417fn default_screen_reader_mode() -> bool {
418 env_bool_var("VTCODE_SCREEN_READER").unwrap_or(false)
419}
420
421fn default_ambiguous_width() -> AmbiguousWidthMode {
422 match crate::env_helpers::read_env_var("VTCODE_AMBIGUOUS_WIDTH")
423 .map(|value| value.trim().to_ascii_lowercase())
424 .as_deref()
425 {
426 Some("wide") => AmbiguousWidthMode::Wide,
427 Some("narrow") => AmbiguousWidthMode::Narrow,
428 _ => AmbiguousWidthMode::default(),
429 }
430}
431
432fn default_reduce_motion_mode() -> bool {
433 env_bool_var("VTCODE_REDUCE_MOTION")
434 .or_else(reduce_motion_preference)
435 .unwrap_or(false)
436}
437
438fn default_reduce_motion_keep_progress_animation() -> bool {
439 false
440}
441
442fn default_hide_header() -> bool {
443 true
444}
445
446fn default_diff_preview_mode() -> DiffPreviewMode {
447 DiffPreviewMode::Inline
448}
449
450fn default_transcript_review_control() -> bool {
451 true
452}
453
454fn default_show_task_panel() -> bool {
455 false
456}
457
458fn default_ask_questions_enabled() -> bool {
459 true
460}
461
462impl Default for UiConfig {
463 fn default() -> Self {
464 Self {
465 tool_output_mode: default_tool_output_mode(),
466 tool_display_mode: default_tool_display_mode(),
467 verb_callouts: default_verb_callouts(),
468 keybindings: HashMap::new(),
469 tool_output_max_lines: default_tool_output_max_lines(),
470 tool_output_spool_bytes: default_tool_output_spool_bytes(),
471 tool_output_spool_dir: None,
472 allow_tool_ansi: default_allow_tool_ansi(),
473 inline_viewport_rows: default_inline_viewport_rows(),
474 reasoning_display_mode: default_reasoning_display_mode(),
475 reasoning_visible_default: default_reasoning_visible_default(),
476 thinking_display: default_thinking_display(),
477 communication_style: default_communication_style(),
478 vim_mode: default_vim_mode(),
479 busy_enter_behavior: default_busy_enter_behavior(),
480 status_line: StatusLineConfig::default(),
481 terminal_title: TerminalTitleConfig::default(),
482 keyboard_protocol: KeyboardProtocolConfig::default(),
483 layout_mode: LayoutModeOverride::default(),
484 display_mode: UiDisplayMode::default(),
485 show_sidebar: default_show_sidebar(),
486 dim_completed_todos: default_dim_completed_todos(),
487 show_task_panel: default_show_task_panel(),
488 message_block_spacing: default_message_block_spacing(),
489 show_turn_timer: default_show_turn_timer(),
490 show_diagnostics_in_transcript: default_show_diagnostics_in_transcript(),
491 show_message_timestamps: default_show_message_timestamps(),
492 minimum_contrast: default_minimum_contrast(),
494 high_contrast_mode: default_high_contrast_mode(),
495 bold_is_bright: default_bold_is_bright(),
496 ambiguous_width: default_ambiguous_width(),
497 safe_colors_only: default_safe_colors_only(),
498 color_scheme_mode: default_color_scheme_mode(),
499 app_icon: default_app_icon(),
500 program_status: UiProgramStatusConfig::default(),
501 notifications: UiNotificationsConfig::default(),
502 fullscreen: UiFullscreenConfig::default(),
503 screen_reader_mode: default_screen_reader_mode(),
504 reduce_motion_mode: default_reduce_motion_mode(),
505 reduce_motion_keep_progress_animation: default_reduce_motion_keep_progress_animation(),
506 hide_header: default_hide_header(),
507 diff_preview_mode: default_diff_preview_mode(),
508 transcript_review: UiTranscriptReviewConfig::default(),
509 }
510 }
511}
512
513impl UiConfig {
514 pub fn effective_minimum_contrast(&self) -> f32 {
520 if self.high_contrast_mode {
521 crate::constants::ui::THEME_HIGH_CONTRAST_RATIO.max(self.minimum_contrast)
522 } else {
523 self.minimum_contrast
524 }
525 }
526}
527
528#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
530#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
531#[serde(default)]
532pub struct UiProgramStatusConfig {
533 #[serde(default = "default_program_status_enabled")]
535 pub enabled: bool,
536}
537
538impl Default for UiProgramStatusConfig {
539 fn default() -> Self {
540 Self { enabled: default_program_status_enabled() }
541 }
542}
543
544#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
546#[derive(Debug, Clone, Deserialize, Serialize, Default)]
547pub struct ChatConfig {
548 #[serde(default, rename = "askQuestions", alias = "ask_questions")]
550 pub ask_questions: AskQuestionsConfig,
551}
552
553#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
555#[derive(Debug, Clone, Deserialize, Serialize)]
556pub struct AskQuestionsConfig {
557 #[serde(default = "default_ask_questions_enabled")]
559 pub enabled: bool,
560}
561
562impl Default for AskQuestionsConfig {
563 fn default() -> Self {
564 Self { enabled: default_ask_questions_enabled() }
565 }
566}
567
568#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
570#[derive(Debug, Clone, Deserialize, Serialize)]
571pub struct PtyConfig {
572 #[serde(default = "default_pty_enabled")]
574 pub enabled: bool,
575
576 #[serde(default = "default_pty_rows")]
578 pub default_rows: u16,
579
580 #[serde(default = "default_pty_cols")]
582 pub default_cols: u16,
583
584 #[serde(default = "default_max_pty_sessions")]
586 pub max_sessions: usize,
587
588 #[serde(default = "default_pty_timeout")]
594 pub command_timeout_seconds: u64,
595
596 #[serde(default = "default_stdout_tail_lines")]
598 pub stdout_tail_lines: usize,
599
600 #[serde(default = "default_scrollback_lines")]
602 pub scrollback_lines: usize,
603
604 #[serde(default = "default_max_scrollback_bytes")]
606 pub max_scrollback_bytes: usize,
607
608 #[serde(default = "default_large_output_threshold_kb")]
610 pub large_output_threshold_kb: usize,
611
612 #[serde(default)]
614 pub preferred_shell: Option<String>,
615
616 #[serde(default = "default_shell_zsh_fork")]
618 pub shell_zsh_fork: bool,
619
620 #[serde(default)]
622 pub zsh_path: Option<String>,
623}
624
625impl Default for PtyConfig {
626 fn default() -> Self {
627 Self {
628 enabled: default_pty_enabled(),
629 default_rows: default_pty_rows(),
630 default_cols: default_pty_cols(),
631 max_sessions: default_max_pty_sessions(),
632 command_timeout_seconds: default_pty_timeout(),
633 stdout_tail_lines: default_stdout_tail_lines(),
634 scrollback_lines: default_scrollback_lines(),
635 max_scrollback_bytes: default_max_scrollback_bytes(),
636 large_output_threshold_kb: default_large_output_threshold_kb(),
637 preferred_shell: None,
638 shell_zsh_fork: default_shell_zsh_fork(),
639 zsh_path: None,
640 }
641 }
642}
643
644impl PtyConfig {
645 pub fn validate(&self) -> Result<()> {
646 self.zsh_fork_shell_path()?;
647 Ok(())
648 }
649
650 pub fn zsh_fork_shell_path(&self) -> Result<Option<&str>> {
651 if !self.shell_zsh_fork {
652 return Ok(None);
653 }
654
655 let zsh_path = self
656 .zsh_path
657 .as_deref()
658 .map(str::trim)
659 .filter(|path| !path.is_empty())
660 .ok_or_else(|| {
661 anyhow!(
662 "pty.shell_zsh_fork is enabled, but pty.zsh_path is not configured. \
663 Set pty.zsh_path to an absolute path to patched zsh."
664 )
665 })?;
666
667 #[cfg(not(unix))]
668 {
669 let _ = zsh_path;
670 bail!("pty.shell_zsh_fork is only supported on Unix platforms");
671 }
672
673 #[cfg(unix)]
674 {
675 let path = std::path::Path::new(zsh_path);
676 if !path.is_absolute() {
677 bail!("pty.zsh_path '{zsh_path}' must be an absolute path when pty.shell_zsh_fork is enabled");
678 }
679 if !path.exists() {
680 bail!("pty.zsh_path '{zsh_path}' does not exist (required when pty.shell_zsh_fork is enabled)");
681 }
682 if !path.is_file() {
683 bail!("pty.zsh_path '{zsh_path}' is not a file (required when pty.shell_zsh_fork is enabled)");
684 }
685
686 Ok(Some(zsh_path))
687 }
688 }
689}
690
691fn default_pty_enabled() -> bool {
692 true
693}
694
695fn default_pty_rows() -> u16 {
696 24
697}
698
699fn default_pty_cols() -> u16 {
700 80
701}
702
703fn default_max_pty_sessions() -> usize {
704 10
705}
706
707fn default_pty_timeout() -> u64 {
708 300
709}
710
711fn default_shell_zsh_fork() -> bool {
712 false
713}
714
715fn default_stdout_tail_lines() -> usize {
716 crate::constants::defaults::DEFAULT_PTY_STDOUT_TAIL_LINES
717}
718
719fn default_scrollback_lines() -> usize {
720 crate::constants::defaults::DEFAULT_PTY_SCROLLBACK_LINES
721}
722
723fn default_max_scrollback_bytes() -> usize {
724 25_000_000 }
728
729fn default_large_output_threshold_kb() -> usize {
730 5_000 }
732
733fn default_tool_output_mode() -> ToolOutputMode {
734 ToolOutputMode::Compact
735}
736
737fn default_tool_display_mode() -> ToolDisplayMode {
738 ToolDisplayMode::Compact
739}
740
741fn default_verb_callouts() -> bool {
742 true
743}
744
745fn default_tool_output_max_lines() -> usize {
746 30
747}
748
749fn default_tool_output_spool_bytes() -> usize {
750 80_000
751}
752
753fn default_allow_tool_ansi() -> bool {
754 false
755}
756
757fn default_inline_viewport_rows() -> u16 {
758 crate::constants::ui::DEFAULT_INLINE_VIEWPORT_ROWS
759}
760
761fn default_reasoning_display_mode() -> ReasoningDisplayMode {
762 ReasoningDisplayMode::Toggle
763}
764
765fn default_reasoning_visible_default() -> bool {
766 crate::constants::ui::DEFAULT_REASONING_VISIBLE
767}
768
769fn default_thinking_display() -> vtcode_commons::ui_protocol::ThinkingBlockState {
770 vtcode_commons::ui_protocol::ThinkingBlockState::Collapsed
771}
772
773fn default_communication_style() -> vtcode_commons::ui_protocol::CommunicationStyle {
774 vtcode_commons::ui_protocol::CommunicationStyle::Balanced
775}
776
777#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
781#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize, Serialize)]
782#[serde(rename_all = "snake_case")]
783pub enum KeyboardProtocolMode {
784 #[default]
786 Default,
787 Full,
789 Minimal,
791 Custom,
793}
794
795impl KeyboardProtocolMode {
796 pub fn as_str(&self) -> &'static str {
798 match self {
799 Self::Default => "default",
800 Self::Full => "full",
801 Self::Minimal => "minimal",
802 Self::Custom => "custom",
803 }
804 }
805}
806
807#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
808#[derive(Debug, Clone, Deserialize, Serialize)]
809pub struct KeyboardProtocolConfig {
810 #[serde(default = "default_keyboard_protocol_enabled")]
812 pub enabled: bool,
813
814 #[serde(default = "default_keyboard_protocol_mode")]
816 pub mode: KeyboardProtocolMode,
817
818 #[serde(default = "default_disambiguate_escape_codes")]
820 pub disambiguate_escape_codes: bool,
821
822 #[serde(default = "default_report_event_types")]
824 pub report_event_types: bool,
825
826 #[serde(default = "default_report_alternate_keys")]
828 pub report_alternate_keys: bool,
829
830 #[serde(default = "default_report_all_keys")]
832 pub report_all_keys: bool,
833}
834
835impl Default for KeyboardProtocolConfig {
836 fn default() -> Self {
837 Self {
838 enabled: default_keyboard_protocol_enabled(),
839 mode: default_keyboard_protocol_mode(),
840 disambiguate_escape_codes: default_disambiguate_escape_codes(),
841 report_event_types: default_report_event_types(),
842 report_alternate_keys: default_report_alternate_keys(),
843 report_all_keys: default_report_all_keys(),
844 }
845 }
846}
847
848impl KeyboardProtocolConfig {
849 pub fn validate(&self) -> Result<()> {
850 let _ = self.mode;
852 Ok(())
853 }
854}
855
856fn default_keyboard_protocol_enabled() -> bool {
857 std::env::var("VTCODE_KEYBOARD_PROTOCOL_ENABLED")
858 .ok()
859 .and_then(|v| v.parse().ok())
860 .unwrap_or(true)
861}
862
863fn default_keyboard_protocol_mode() -> KeyboardProtocolMode {
864 std::env::var("VTCODE_KEYBOARD_PROTOCOL_MODE")
865 .ok()
866 .and_then(|v| match v.to_ascii_lowercase().as_str() {
867 "default" => Some(KeyboardProtocolMode::Default),
868 "full" => Some(KeyboardProtocolMode::Full),
869 "minimal" => Some(KeyboardProtocolMode::Minimal),
870 "custom" => Some(KeyboardProtocolMode::Custom),
871 _ => None,
872 })
873 .unwrap_or_default()
874}
875
876fn default_disambiguate_escape_codes() -> bool {
877 true
878}
879
880fn default_report_event_types() -> bool {
881 true
882}
883
884fn default_report_alternate_keys() -> bool {
885 true
886}
887
888fn default_report_all_keys() -> bool {
889 false
890}
891#[cfg(test)]
892mod tests;