|
235 | 235 | this.input + this.writeLine("\n"), |
236 | 236 | ); |
237 | 237 | this.input = ""; |
| 238 | + this.cursorPosition = 0; |
238 | 239 | this.activeInput = false; |
239 | 240 | break; |
| 241 | + case "\x03": // CTRL+C |
| 242 | + this.input = ""; |
| 243 | + this.xterm.write("\n") |
| 244 | + // this is a real hack. the hard-coded 4... :\ |
| 245 | + this.xterm.write('\x1b[' + (this.cursorPosition + 4) + 'D'); |
| 246 | + this.cursorPosition = 0; |
| 247 | + this.resolveInput("" + '\n'); |
| 248 | + break; |
| 249 | + case "\x09": // TAB |
| 250 | + this.handleTab(); |
| 251 | + break; |
240 | 252 | case "\x7F": // BACKSPACE |
241 | 253 | case "\x08": // CTRL+H |
242 | 254 | this.handleCursorErase(true); |
|
245 | 257 | // Send empty input |
246 | 258 | if (this.input === "") { |
247 | 259 | this.resolveInput(""); |
| 260 | + this.cursorPosition = 0; |
248 | 261 | this.activeInput = false; |
249 | 262 | } |
250 | 263 | } |
|
376 | 389 | } |
377 | 390 | } |
378 | 391 |
|
| 392 | + handleTab() { |
| 393 | + // handle tabs: from the current position, add spaces until |
| 394 | + // this.cursorPosition is a multiple of 4. |
| 395 | + const prefix = this.input.slice(0, this.cursorPosition); |
| 396 | + const suffix = this.input.slice(this.cursorPosition); |
| 397 | + const count = 4 - (this.cursorPosition % 4); |
| 398 | + const toAdd = " ".repeat(count); |
| 399 | + this.input = prefix + toAdd + suffix; |
| 400 | + if (this.cursorPosition > 0){ |
| 401 | + this.xterm.write('\x1b[' + (this.cursorPosition) + 'D'); |
| 402 | + } |
| 403 | + // clear the line |
| 404 | + this.xterm.write('\x1b[K') |
| 405 | + this.xterm.write(this.input); |
| 406 | + if (suffix){ |
| 407 | + this.xterm.write('\x1b[' + suffix.length + 'D'); |
| 408 | + } |
| 409 | + this.cursorPosition += count; |
| 410 | + } |
| 411 | + |
379 | 412 | prompt = async () => { |
380 | 413 | this.activeInput = true; |
381 | 414 | // Hack to allow stdout/stderr to finish before we figure out where input starts |
|
0 commit comments