Skip to content

Commit 62cae59

Browse files
author
Henry Hale
authored
Merge pull request #3 from henryhale/fix/issue-2
fix/issue 2
2 parents 38613de + 17dffa8 commit 62cae59

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

source/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,18 @@ export default class ViteShell implements Shell {
226226
return Promise.reject(SHELL_INACTIVE);
227227
}
228228

229-
// flush the output stream and then activate it
230-
this.#output.reset();
231-
232229
// incase there's a currently executing command requiring user input
233230
if (this.#input.isBusy) {
234231
this.#input.insert(line);
235232
return Promise.resolve();
233+
} else {
234+
// otherwise clear the input buffer and any input callback
235+
this.#input.reset();
236236
}
237237

238+
// flush the output stream and then activate it
239+
this.#output.reset();
240+
238241
// check if the line contains characters
239242
if (typeof line !== "string" || !line.trim()) {
240243
this.#prompt();
@@ -253,6 +256,7 @@ export default class ViteShell implements Shell {
253256

254257
// reset abort token for reuse
255258
this.#abortSignal.reset();
259+
this.#abortSignal.onAbort(() => this.#input.reset());
256260

257261
// setup a nodejs-like process object
258262
const process = createProcessContext(

source/streams/input.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export default class InputStream implements StandardInput {
4141
});
4242
}
4343

44-
public clear(): void {
44+
public reset(): void {
4545
this.buffer.splice(0);
46+
this.extractor = undefined;
4647
}
4748
}

tests/input.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("Input stream interface", () => {
1313
expect(stdin).toHaveProperty("isBusy");
1414
expect(stdin).toHaveProperty("insert");
1515
expect(stdin).toHaveProperty("readline");
16-
expect(stdin).toHaveProperty("clear");
16+
expect(stdin).toHaveProperty("reset");
1717
});
1818

1919
test("usage", () => {

0 commit comments

Comments
 (0)