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")]
228 pub high_contrast_mode: bool,
229
230 #[serde(default = "default_bold_is_bright")]
234 pub bold_is_bright: bool,
235
236 #[serde(default = "default_ambiguous_width")]
246 pub ambiguous_width: AmbiguousWidthMode,
247
248 #[serde(default = "default_safe_colors_only")]
254 pub safe_colors_only: bool,
255
256 #[serde(default = "default_color_scheme_mode")]
261 pub color_scheme_mode: ColorSchemeMode,
262
263 #[serde(default = "default_app_icon")]
270 pub app_icon: AppIconPreference,
271
272 #[serde(default)]
274 pub program_status: UiProgramStatusConfig,
275
276 #[serde(default)]
278 pub notifications: UiNotificationsConfig,
279
280 #[serde(default)]
282 pub fullscreen: UiFullscreenConfig,
283
284 #[serde(default = "default_screen_reader_mode")]
289 pub screen_reader_mode: bool,
290
291 #[serde(default = "default_reduce_motion_mode")]
295 pub reduce_motion_mode: bool,
296
297 #[serde(default = "default_reduce_motion_keep_progress_animation")]
300 pub reduce_motion_keep_progress_animation: bool,
301
302 #[serde(default = "default_hide_header")]
304 pub hide_header: bool,
305
306 #[serde(default = "default_diff_preview_mode")]
309 pub diff_preview_mode: DiffPreviewMode,
310
311 #[serde(default)]
313 pub transcript_review: UiTranscriptReviewConfig,
314}
315
316#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
318#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, Default)]
319#[serde(rename_all = "snake_case")]
320pub enum ColorSchemeMode {
321 #[default]
323 Auto,
324 Light,
326 Dark,
328 #[serde(other)]
330 Unknown,
331}
332
333fn default_minimum_contrast() -> f32 {
334 crate::constants::ui::THEME_MIN_CONTRAST_RATIO
335}
336
337fn default_high_contrast_mode() -> bool {
338 env_bool_var("VTCODE_HIGH_CONTRAST").unwrap_or(false)
339}
340
341fn default_bold_is_bright() -> bool {
342 false
343}
344
345fn default_safe_colors_only() -> bool {
346 false
347}
348
349fn default_color_scheme_mode() -> ColorSchemeMode {
350 ColorSchemeMode::Auto
351}
352
353fn default_app_icon() -> AppIconPreference {
354 AppIconPreference::Dynamic
355}
356
357fn default_show_sidebar() -> bool {
358 true
359}
360
361fn default_dim_completed_todos() -> bool {
362 true
363}
364
365fn default_message_block_spacing() -> bool {
366 true
367}
368
369fn default_program_status_enabled() -> bool {
370 true
371}
372
373fn default_show_turn_timer() -> bool {
374 false
375}
376
377fn default_show_diagnostics_in_transcript() -> bool {
378 false
379}
380
381fn default_show_message_timestamps() -> bool {
382 true
383}
384
385fn default_vim_mode() -> bool {
386 false
387}
388
389fn default_busy_enter_behavior() -> BusyEnterBehavior {
390 BusyEnterBehavior::Queue
391}
392
393fn env_bool_var(name: &str) -> Option<bool> {
394 crate::env_helpers::read_env_var(name).and_then(|v| vtcode_commons::utils::parse_bool_env_value(&v))
395}
396
397fn env_u8_var(name: &str) -> Option<u8> {
398 crate::env_helpers::read_env_var(name)
399 .and_then(|value| value.trim().parse::<u8>().ok())
400 .map(clamp_fullscreen_scroll_speed)
401}
402
403fn clamp_fullscreen_scroll_speed(value: u8) -> u8 {
404 value.clamp(1, 20)
405}
406
407fn default_fullscreen_mouse_capture() -> bool {
408 env_bool_var("VTCODE_FULLSCREEN_MOUSE_CAPTURE").unwrap_or(true)
409}
410
411fn default_fullscreen_copy_on_select() -> bool {
412 env_bool_var("VTCODE_FULLSCREEN_COPY_ON_SELECT").unwrap_or(true)
413}
414
415fn default_fullscreen_scroll_speed() -> u8 {
416 env_u8_var("VTCODE_FULLSCREEN_SCROLL_SPEED").unwrap_or(3)
417}
418
419fn default_screen_reader_mode() -> bool {
420 env_bool_var("VTCODE_SCREEN_READER").unwrap_or(false)
421}
422
423fn default_ambiguous_width() -> AmbiguousWidthMode {
424 match crate::env_helpers::read_env_var("VTCODE_AMBIGUOUS_WIDTH")
425 .map(|value| value.trim().to_ascii_lowercase())
426 .as_deref()
427 {
428 Some("wide") => AmbiguousWidthMode::Wide,
429 Some("narrow") => AmbiguousWidthMode::Narrow,
430 _ => AmbiguousWidthMode::default(),
431 }
432}
433
434fn default_reduce_motion_mode() -> bool {
435 env_bool_var("VTCODE_REDUCE_MOTION")
436 .or_else(reduce_motion_preference)
437 .unwrap_or(false)
438}
439
440fn default_reduce_motion_keep_progress_animation() -> bool {
441 false
442}
443
444fn default_hide_header() -> bool {
445 true
446}
447
448fn default_diff_preview_mode() -> DiffPreviewMode {
449 DiffPreviewMode::Inline
450}
451
452fn default_transcript_review_control() -> bool {
453 true
454}
455
456fn default_show_task_panel() -> bool {
457 false
458}
459
460fn default_ask_questions_enabled() -> bool {
461 true
462}
463
464impl Default for UiConfig {
465 fn default() -> Self {
466 Self {
467 tool_output_mode: default_tool_output_mode(),
468 tool_display_mode: default_tool_display_mode(),
469 verb_callouts: default_verb_callouts(),
470 keybindings: HashMap::new(),
471 tool_output_max_lines: default_tool_output_max_lines(),
472 tool_output_spool_bytes: default_tool_output_spool_bytes(),
473 tool_output_spool_dir: None,
474 allow_tool_ansi: default_allow_tool_ansi(),
475 inline_viewport_rows: default_inline_viewport_rows(),
476 reasoning_display_mode: default_reasoning_display_mode(),
477 reasoning_visible_default: default_reasoning_visible_default(),
478 thinking_display: default_thinking_display(),
479 communication_style: default_communication_style(),
480 vim_mode: default_vim_mode(),
481 busy_enter_behavior: default_busy_enter_behavior(),
482 status_line: StatusLineConfig::default(),
483 terminal_title: TerminalTitleConfig::default(),
484 keyboard_protocol: KeyboardProtocolConfig::default(),
485 layout_mode: LayoutModeOverride::default(),
486 display_mode: UiDisplayMode::default(),
487 show_sidebar: default_show_sidebar(),
488 dim_completed_todos: default_dim_completed_todos(),
489 show_task_panel: default_show_task_panel(),
490 message_block_spacing: default_message_block_spacing(),
491 show_turn_timer: default_show_turn_timer(),
492 show_diagnostics_in_transcript: default_show_diagnostics_in_transcript(),
493 show_message_timestamps: default_show_message_timestamps(),
494 minimum_contrast: default_minimum_contrast(),
496 high_contrast_mode: default_high_contrast_mode(),
497 bold_is_bright: default_bold_is_bright(),
498 ambiguous_width: default_ambiguous_width(),
499 safe_colors_only: default_safe_colors_only(),
500 color_scheme_mode: default_color_scheme_mode(),
501 app_icon: default_app_icon(),
502 program_status: UiProgramStatusConfig::default(),
503 notifications: UiNotificationsConfig::default(),
504 fullscreen: UiFullscreenConfig::default(),
505 screen_reader_mode: default_screen_reader_mode(),
506 reduce_motion_mode: default_reduce_motion_mode(),
507 reduce_motion_keep_progress_animation: default_reduce_motion_keep_progress_animation(),
508 hide_header: default_hide_header(),
509 diff_preview_mode: default_diff_preview_mode(),
510 transcript_review: UiTranscriptReviewConfig::default(),
511 }
512 }
513}
514
515impl UiConfig {
516 pub fn effective_minimum_contrast(&self) -> f32 {
522 if self.high_contrast_mode {
523 crate::constants::ui::THEME_HIGH_CONTRAST_RATIO.max(self.minimum_contrast)
524 } else {
525 self.minimum_contrast
526 }
527 }
528}
529
530#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
532#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
533#[serde(default)]
534pub struct UiProgramStatusConfig {
535 #[serde(default = "default_program_status_enabled")]
537 pub enabled: bool,
538}
539
540impl Default for UiProgramStatusConfig {
541 fn default() -> Self {
542 Self { enabled: default_program_status_enabled() }
543 }
544}
545
546#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
548#[derive(Debug, Clone, Deserialize, Serialize, Default)]
549pub struct ChatConfig {
550 #[serde(default, rename = "askQuestions", alias = "ask_questions")]
552 pub ask_questions: AskQuestionsConfig,
553}
554
555#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
557#[derive(Debug, Clone, Deserialize, Serialize)]
558pub struct AskQuestionsConfig {
559 #[serde(default = "default_ask_questions_enabled")]
561 pub enabled: bool,
562}
563
564impl Default for AskQuestionsConfig {
565 fn default() -> Self {
566 Self { enabled: default_ask_questions_enabled() }
567 }
568}
569
570#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
572#[derive(Debug, Clone, Deserialize, Serialize)]
573pub struct PtyConfig {
574 #[serde(default = "default_pty_enabled")]
576 pub enabled: bool,
577
578 #[serde(default = "default_pty_rows")]
580 pub default_rows: u16,
581
582 #[serde(default = "default_pty_cols")]
584 pub default_cols: u16,
585
586 #[serde(default = "default_max_pty_sessions")]
588 pub max_sessions: usize,
589
590 #[serde(default = "default_pty_timeout")]
596 pub command_timeout_seconds: u64,
597
598 #[serde(default = "default_stdout_tail_lines")]
600 pub stdout_tail_lines: usize,
601
602 #[serde(default = "default_scrollback_lines")]
604 pub scrollback_lines: usize,
605
606 #[serde(default = "default_max_scrollback_bytes")]
608 pub max_scrollback_bytes: usize,
609
610 #[serde(default = "default_large_output_threshold_kb")]
612 pub large_output_threshold_kb: usize,
613
614 #[serde(default)]
616 pub preferred_shell: Option<String>,
617
618 #[serde(default = "default_shell_zsh_fork")]
620 pub shell_zsh_fork: bool,
621
622 #[serde(default)]
624 pub zsh_path: Option<String>,
625}
626
627impl Default for PtyConfig {
628 fn default() -> Self {
629 Self {
630 enabled: default_pty_enabled(),
631 default_rows: default_pty_rows(),
632 default_cols: default_pty_cols(),
633 max_sessions: default_max_pty_sessions(),
634 command_timeout_seconds: default_pty_timeout(),
635 stdout_tail_lines: default_stdout_tail_lines(),
636 scrollback_lines: default_scrollback_lines(),
637 max_scrollback_bytes: default_max_scrollback_bytes(),
638 large_output_threshold_kb: default_large_output_threshold_kb(),
639 preferred_shell: None,
640 shell_zsh_fork: default_shell_zsh_fork(),
641 zsh_path: None,
642 }
643 }
644}
645
646impl PtyConfig {
647 pub fn validate(&self) -> Result<()> {
648 self.zsh_fork_shell_path()?;
649 Ok(())
650 }
651
652 pub fn zsh_fork_shell_path(&self) -> Result<Option<&str>> {
653 if !self.shell_zsh_fork {
654 return Ok(None);
655 }
656
657 let zsh_path = self
658 .zsh_path
659 .as_deref()
660 .map(str::trim)
661 .filter(|path| !path.is_empty())
662 .ok_or_else(|| {
663 anyhow!(
664 "pty.shell_zsh_fork is enabled, but pty.zsh_path is not configured. \
665 Set pty.zsh_path to an absolute path to patched zsh."
666 )
667 })?;
668
669 #[cfg(not(unix))]
670 {
671 let _ = zsh_path;
672 bail!("pty.shell_zsh_fork is only supported on Unix platforms");
673 }
674
675 #[cfg(unix)]
676 {
677 let path = std::path::Path::new(zsh_path);
678 if !path.is_absolute() {
679 bail!("pty.zsh_path '{zsh_path}' must be an absolute path when pty.shell_zsh_fork is enabled");
680 }
681 if !path.exists() {
682 bail!("pty.zsh_path '{zsh_path}' does not exist (required when pty.shell_zsh_fork is enabled)");
683 }
684 if !path.is_file() {
685 bail!("pty.zsh_path '{zsh_path}' is not a file (required when pty.shell_zsh_fork is enabled)");
686 }
687
688 Ok(Some(zsh_path))
689 }
690 }
691}
692
693fn default_pty_enabled() -> bool {
694 true
695}
696
697fn default_pty_rows() -> u16 {
698 24
699}
700
701fn default_pty_cols() -> u16 {
702 80
703}
704
705fn default_max_pty_sessions() -> usize {
706 10
707}
708
709fn default_pty_timeout() -> u64 {
710 300
711}
712
713fn default_shell_zsh_fork() -> bool {
714 false
715}
716
717fn default_stdout_tail_lines() -> usize {
718 crate::constants::defaults::DEFAULT_PTY_STDOUT_TAIL_LINES
719}
720
721fn default_scrollback_lines() -> usize {
722 crate::constants::defaults::DEFAULT_PTY_SCROLLBACK_LINES
723}
724
725fn default_max_scrollback_bytes() -> usize {
726 25_000_000 }
730
731fn default_large_output_threshold_kb() -> usize {
732 5_000 }
734
735fn default_tool_output_mode() -> ToolOutputMode {
736 ToolOutputMode::Compact
737}
738
739fn default_tool_display_mode() -> ToolDisplayMode {
740 ToolDisplayMode::Compact
741}
742
743fn default_verb_callouts() -> bool {
744 true
745}
746
747fn default_tool_output_max_lines() -> usize {
748 30
749}
750
751fn default_tool_output_spool_bytes() -> usize {
752 80_000
753}
754
755fn default_allow_tool_ansi() -> bool {
756 false
757}
758
759fn default_inline_viewport_rows() -> u16 {
760 crate::constants::ui::DEFAULT_INLINE_VIEWPORT_ROWS
761}
762
763fn default_reasoning_display_mode() -> ReasoningDisplayMode {
764 ReasoningDisplayMode::Toggle
765}
766
767fn default_reasoning_visible_default() -> bool {
768 crate::constants::ui::DEFAULT_REASONING_VISIBLE
769}
770
771fn default_thinking_display() -> vtcode_commons::ui_protocol::ThinkingBlockState {
772 vtcode_commons::ui_protocol::ThinkingBlockState::Collapsed
773}
774
775fn default_communication_style() -> vtcode_commons::ui_protocol::CommunicationStyle {
776 vtcode_commons::ui_protocol::CommunicationStyle::Balanced
777}
778
779#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
783#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize, Serialize)]
784#[serde(rename_all = "snake_case")]
785pub enum KeyboardProtocolMode {
786 #[default]
788 Default,
789 Full,
791 Minimal,
793 Custom,
795}
796
797impl KeyboardProtocolMode {
798 pub fn as_str(&self) -> &'static str {
800 match self {
801 Self::Default => "default",
802 Self::Full => "full",
803 Self::Minimal => "minimal",
804 Self::Custom => "custom",
805 }
806 }
807}
808
809impl std::str::FromStr for KeyboardProtocolMode {
810 type Err = ();
811
812 fn from_str(value: &str) -> Result<Self, Self::Err> {
813 match value.to_ascii_lowercase().as_str() {
814 "default" => Ok(Self::Default),
815 "full" => Ok(Self::Full),
816 "minimal" => Ok(Self::Minimal),
817 "custom" => Ok(Self::Custom),
818 _ => Err(()),
819 }
820 }
821}
822
823#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
824#[derive(Debug, Clone, Deserialize, Serialize)]
825pub struct KeyboardProtocolConfig {
826 #[serde(default = "default_keyboard_protocol_enabled")]
828 pub enabled: bool,
829
830 #[serde(default = "default_keyboard_protocol_mode")]
832 pub mode: KeyboardProtocolMode,
833
834 #[serde(default = "default_disambiguate_escape_codes")]
836 pub disambiguate_escape_codes: bool,
837
838 #[serde(default = "default_report_event_types")]
840 pub report_event_types: bool,
841
842 #[serde(default = "default_report_alternate_keys")]
844 pub report_alternate_keys: bool,
845
846 #[serde(default = "default_report_all_keys")]
848 pub report_all_keys: bool,
849}
850
851impl Default for KeyboardProtocolConfig {
852 fn default() -> Self {
853 Self {
854 enabled: default_keyboard_protocol_enabled(),
855 mode: default_keyboard_protocol_mode(),
856 disambiguate_escape_codes: default_disambiguate_escape_codes(),
857 report_event_types: default_report_event_types(),
858 report_alternate_keys: default_report_alternate_keys(),
859 report_all_keys: default_report_all_keys(),
860 }
861 }
862}
863
864impl KeyboardProtocolConfig {
865 pub fn validate(&self) -> Result<()> {
866 let _ = self.mode;
868 Ok(())
869 }
870}
871
872fn default_keyboard_protocol_enabled() -> bool {
873 std::env::var("VTCODE_KEYBOARD_PROTOCOL_ENABLED")
874 .ok()
875 .and_then(|v| v.parse().ok())
876 .unwrap_or(true)
877}
878
879fn default_keyboard_protocol_mode() -> KeyboardProtocolMode {
880 std::env::var("VTCODE_KEYBOARD_PROTOCOL_MODE")
881 .ok()
882 .and_then(|v| v.parse().ok())
883 .unwrap_or_default()
884}
885
886fn default_disambiguate_escape_codes() -> bool {
887 true
888}
889
890fn default_report_event_types() -> bool {
891 true
892}
893
894fn default_report_alternate_keys() -> bool {
895 true
896}
897
898fn default_report_all_keys() -> bool {
899 false
900}
901#[cfg(test)]
902mod tests;