Skip to content

Commit

Permalink
Add REPL abort API
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Mar 8, 2022
1 parent 2416ed7 commit 2d642a2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/repl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,11 @@ export default class REPL {
// #onDidOverrideDimensions
onDidWrite
#onDidWrite

onDidDispose
#onDidDispose
onAbort
#onAbort

#prompt_cb
#ps_len
Expand Down Expand Up @@ -242,6 +245,8 @@ export default class REPL {
this.onDidWrite = this.#onDidWrite.event;
this.#onDidDispose = new vscode.EventEmitter();
this.onDidDispose = this.#onDidDispose.event;
this.#onAbort = new vscode.EventEmitter();
this.onAbort = this.#onAbort.event;
this.#cursor = new Cursor();
}

Expand Down Expand Up @@ -322,6 +327,22 @@ export default class REPL {
else if (data === '\x1b\r') {
return this.#new_line();
}
else if (data === '\x03') {
if (this.#lines.length > 1 || this.#lines[0].text != this.#ps0) {
this.#do_cursor_start_of_line();
this.#do_cursor_up(this.#count_lines(0, this.#cursor.line) +
this.#cursor.subline);
this.#do_clear_end_of_screen();
this.#new_prompt();
return;
}
this.#write('^C');
this.#do_cursor_start_of_nextline();
this.#do_clear_end_of_screen();
this.#new_prompt();
this.#onAbort.fire();
return;
}
this.#input_text(data);
}
setDimensions(dims) {
Expand Down

0 comments on commit 2d642a2

Please sign in to comment.