( terminalName: string, appName: string, )
| 132 | |
| 133 | // Generic VS Code-style terminal configuration |
| 134 | async function configureVSCodeStyle( |
| 135 | terminalName: string, |
| 136 | appName: string, |
| 137 | ): Promise<TerminalSetupResult> { |
| 138 | const configDir = getVSCodeStyleConfigDir(appName); |
| 139 | |
| 140 | if (!configDir) { |
| 141 | return { |
| 142 | success: false, |
| 143 | message: `Could not determine ${terminalName} config path on Windows: APPDATA environment variable is not set.`, |
| 144 | }; |
| 145 | } |
| 146 | |
| 147 | const keybindingsFile = path.join(configDir, 'keybindings.json'); |
| 148 | |
| 149 | try { |
| 150 | await fs.mkdir(configDir, { recursive: true }); |
| 151 | |
| 152 | let keybindings: unknown[] = []; |
| 153 | try { |
| 154 | const content = await fs.readFile(keybindingsFile, 'utf8'); |
| 155 | await backupFile(keybindingsFile); |
| 156 | try { |
| 157 | const cleanContent = stripJsonComments(content); |
| 158 | const parsedContent = JSON.parse(cleanContent); |
| 159 | if (!Array.isArray(parsedContent)) { |
| 160 | return { |
| 161 | success: false, |
| 162 | message: |
| 163 | `${terminalName} keybindings.json exists but is not a valid JSON array. ` + |
| 164 | `Please fix the file manually or delete it to allow automatic configuration.\n` + |
| 165 | `File: ${keybindingsFile}`, |
| 166 | }; |
| 167 | } |
| 168 | keybindings = parsedContent; |
| 169 | } catch (parseError) { |
| 170 | return { |
| 171 | success: false, |
| 172 | message: |
| 173 | `Failed to parse ${terminalName} keybindings.json. The file contains invalid JSON.\n` + |
| 174 | `Please fix the file manually or delete it to allow automatic configuration.\n` + |
| 175 | `File: ${keybindingsFile}\n` + |
| 176 | `Error: ${parseError}`, |
| 177 | }; |
| 178 | } |
| 179 | } catch { |
| 180 | // File doesn't exist, will create new one |
| 181 | } |
| 182 | |
| 183 | const shiftEnterBinding = { |
| 184 | key: 'shift+enter', |
| 185 | command: 'workbench.action.terminal.sendSequence', |
| 186 | when: 'terminalFocus', |
| 187 | args: { text: VSCODE_SHIFT_ENTER_SEQUENCE }, |
| 188 | }; |
| 189 | |
| 190 | const ctrlEnterBinding = { |
| 191 | key: 'ctrl+enter', |
no test coverage detected