()
| 174 | } |
| 175 | |
| 176 | export async function chooseTerminal(): Promise<vscode.Terminal | undefined> { |
| 177 | // VSCode Python's extension creates hidden terminal with string 'Deactivate' |
| 178 | // For now ignore terminals with this string |
| 179 | const ignoreTermIdentifier = 'Deactivate'; |
| 180 | |
| 181 | // Filter out terminals to be ignored |
| 182 | const visibleTerminals = vscode.window.terminals.filter(terminal => { |
| 183 | return !terminal.name.toLowerCase().includes(ignoreTermIdentifier); |
| 184 | }); |
| 185 | |
| 186 | if (config().get('alwaysUseActiveTerminal')) { |
| 187 | if (visibleTerminals.length < 1) { |
| 188 | void vscode.window.showInformationMessage('There are no open terminals.'); |
| 189 | return undefined; |
| 190 | } |
| 191 | |
| 192 | return vscode.window.activeTerminal; |
| 193 | } |
| 194 | |
| 195 | let msg = '[chooseTerminal] '; |
| 196 | msg += `A. There are ${vscode.window.terminals.length} terminals: `; |
| 197 | for (let i = 0; i < vscode.window.terminals.length; i++){ |
| 198 | msg += `Terminal ${i}: ${vscode.window.terminals[i].name} `; |
| 199 | } |
| 200 | |
| 201 | const rTermNameOptions = ['R', 'R Interactive']; |
| 202 | |
| 203 | const validRTerminals = visibleTerminals.filter(terminal => { |
| 204 | return rTermNameOptions.includes(terminal.name); |
| 205 | }); |
| 206 | |
| 207 | if (validRTerminals.length > 0) { |
| 208 | // If there is an active terminal that is an R terminal, use it |
| 209 | if (vscode.window.activeTerminal && rTermNameOptions.includes(vscode.window.activeTerminal.name)) { |
| 210 | return vscode.window.activeTerminal; |
| 211 | } |
| 212 | // Otherwise, use last valid R terminal |
| 213 | const rTerminal = validRTerminals[validRTerminals.length - 1]; |
| 214 | rTerminal.show(true); |
| 215 | return rTerminal; |
| 216 | } else { |
| 217 | // If no valid R terminals are found, create a new one |
| 218 | console.info(msg); |
| 219 | await createRTerm(true); |
| 220 | await delay(200); // Let RTerm warm up |
| 221 | return rTerm; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | |
| 226 | export async function runSelectionInTerm(moveCursor: boolean, useRepl = true): Promise<void> { |
no test coverage detected