Skip to main content

vtcode_core/terminal_setup/terminals/
vscode.rs

1//! VS Code terminal configuration instruction generator.
2//!
3//! Generates instructions for configuring VS Code's integrated terminal.
4
5use crate::terminal_setup::detector::TerminalType;
6use crate::terminal_setup::features::multiline;
7use anyhow::Result;
8
9/// Generate VS Code setup instructions
10pub fn generate_config(features: &[crate::terminal_setup::detector::TerminalFeature]) -> Result<String> {
11    let mut instructions = vec![
12        "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━".to_string(),
13        "  VS Code Terminal Manual Configuration".to_string(),
14        "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━".to_string(),
15        String::new(),
16        "VS Code requires adding keybindings to keybindings.json".to_string(),
17        "Follow these steps:".to_string(),
18        String::new(),
19    ];
20
21    for (i, feature) in features.iter().enumerate() {
22        match feature {
23            crate::terminal_setup::detector::TerminalFeature::Multiline => {
24                instructions.push(format!("{}. MULTILINE INPUT (Shift+Enter)", i + 1));
25                instructions.push(String::new());
26                let multiline_instructions = multiline::generate_config(TerminalType::VSCode)?;
27                instructions.push(multiline_instructions);
28                instructions.push(String::new());
29            }
30            crate::terminal_setup::detector::TerminalFeature::CopyPaste => {
31                instructions.push(format!("{}. COPY/PASTE INTEGRATION", i + 1));
32                instructions.push(String::new());
33                instructions.push("Copy/paste is built-in to VS Code terminal.".to_string());
34                instructions.push("No additional configuration needed.".to_string());
35                instructions.push(String::new());
36                instructions.push("Default shortcuts:".to_string());
37                instructions.push("  - Copy: Cmd+C (macOS) / Ctrl+C (Windows/Linux)".to_string());
38                instructions.push("  - Paste: Cmd+V (macOS) / Ctrl+V (Windows/Linux)".to_string());
39                instructions.push(String::new());
40            }
41            crate::terminal_setup::detector::TerminalFeature::ShellIntegration => {
42                instructions.push(format!("{}. SHELL INTEGRATION", i + 1));
43                instructions.push(String::new());
44                instructions.push("VS Code has built-in shell integration.".to_string());
45                instructions.push("To enable:".to_string());
46                instructions.push("1. Open Settings (Cmd+, or Ctrl+,)".to_string());
47                instructions.push("2. Search for 'terminal.integrated.shellIntegration.enabled'".to_string());
48                instructions.push("3. Check the box to enable".to_string());
49                instructions.push(String::new());
50            }
51            crate::terminal_setup::detector::TerminalFeature::ThemeSync => {
52                instructions.push(format!("{}. THEME SYNCHRONIZATION", i + 1));
53                instructions.push(String::new());
54                instructions.push("VS Code terminal automatically matches your editor theme.".to_string());
55                instructions.push("To customize:".to_string());
56                instructions.push("1. Open Settings (Cmd+, or Ctrl+,)".to_string());
57                instructions.push("2. Search for 'workbench.colorCustomizations'".to_string());
58                instructions.push("3. Add terminal color overrides in settings.json".to_string());
59                instructions.push(String::new());
60            }
61            crate::terminal_setup::detector::TerminalFeature::Notifications => {
62                instructions.push(format!("{}. SYSTEM NOTIFICATIONS", i + 1));
63                instructions.push(String::new());
64                instructions.push("VS Code terminal supports notifications through:".to_string());
65                instructions.push("1. Settings → Terminal → Integrated → Bell Duration".to_string());
66                instructions.push("2. Enable 'Terminal > Integrated: Enable Bell'".to_string());
67                instructions.push(
68                    "3. For external notifications, consider using extensions like 'Notification Test'".to_string(),
69                );
70                instructions.push("4. Shell integration can trigger notifications via terminal bell '\\a'".to_string());
71                instructions.push(String::new());
72            }
73        }
74    }
75
76    instructions.push("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━".to_string());
77    instructions.push("After configuration, reload VS Code for changes to take effect.".to_string());
78    instructions.push("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━".to_string());
79
80    Ok(instructions.join("\n"))
81}
82
83#[cfg(test)]
84mod tests {
85    use super::*;
86    use crate::terminal_setup::detector::TerminalFeature;
87
88    #[test]
89    fn test_generate_instructions() {
90        let features = vec![TerminalFeature::Multiline, TerminalFeature::ShellIntegration];
91        let instructions = generate_config(&features).unwrap();
92        assert!(instructions.contains("VS Code"));
93        assert!(instructions.contains("keybindings.json") || instructions.contains("Settings"));
94        assert!(instructions.contains("MULTILINE"));
95    }
96}