(text: string, execute: boolean = true)
| 263 | } |
| 264 | |
| 265 | export async function runTextInTerm(text: string, execute: boolean = true): Promise<void> { |
| 266 | if (isGuestSession) { |
| 267 | rGuestService?.requestRunTextInTerm(text); |
| 268 | } else { |
| 269 | const term = await chooseTerminal(); |
| 270 | if (term === undefined) { |
| 271 | return; |
| 272 | } |
| 273 | if (config().get<boolean>('bracketedPaste')) { |
| 274 | // Surround with ANSI control characters for bracketed paste mode |
| 275 | text = `\x1b[200~${text}\x1b[201~`; |
| 276 | term.sendText(text, execute); |
| 277 | } else { |
| 278 | const rtermSendDelay: number = config().get('rtermSendDelay') || 8; |
| 279 | const split = text.split('\n'); |
| 280 | const last_split = split.length - 1; |
| 281 | for (const [count, line] of split.entries()) { |
| 282 | if (count > 0) { |
| 283 | await delay(rtermSendDelay); // Increase delay if RTerm can't handle speed. |
| 284 | } |
| 285 | |
| 286 | // Avoid sending newline on last line |
| 287 | if (count === last_split && !execute) { |
| 288 | term.sendText(line, false); |
| 289 | } else { |
| 290 | term.sendText(line); |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | setFocus(term); |
| 295 | // Scroll console to see latest output |
| 296 | await vscode.commands.executeCommand('workbench.action.terminal.scrollToBottom'); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | function setFocus(term: vscode.Terminal) { |
| 301 | const focus: string = config().get('source.focus') || 'editor'; |
no test coverage detected