From 35c203ddef50e42f6bb353c44b2be4b1e8a6cf74 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sat, 20 Aug 2022 14:14:24 +0200 Subject: [PATCH] Clear down on exit --- package.json | 2 +- run-pty.js | 3 ++- test-exit-in-middle.js | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 test-exit-in-middle.js diff --git a/package.json b/package.json index 03f593c..c27aa3e 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "typescript": "4.7.4" }, "scripts": { - "start": "node run-pty.js % cat % false % echo hello world % ping localhost % node get-cursor-position.js % node test-keys.js % node signals.js % node slow-kill.js % node slow-kill.js 2000 \"Shutting down…\" % make watch % make signals % node test-clear-down.js % node colored-log.js", + "start": "node run-pty.js % cat % false % echo hello world % ping localhost % node get-cursor-position.js % node test-keys.js % node signals.js % node slow-kill.js % node slow-kill.js 2000 \"Shutting down…\" % make watch % make signals % node test-clear-down.js % node colored-log.js % node test-exit-in-middle.js", "example": "node run-pty.js example.json", "auto-exit": "node run-pty.js --auto-exit=2 % sleep 3 % sleep 1 % sleep 2 % sleep 1 % sleep 1 && echo success", "test": "node run-pty.js --auto-exit % prettier --check . % eslint . --report-unused-disable-directives % tsc % jest", diff --git a/run-pty.js b/run-pty.js index 0e1b71d..3c409f5 100755 --- a/run-pty.js +++ b/run-pty.js @@ -629,7 +629,7 @@ const exitTextAndHistory = ({ command, exitCode, numExited, numTotal }) => { lastLine.trim() === "" ? "" : "\n"; return ` ${commandTitleOnlyWithIndicator(exitIndicator(exitCode), command)} -${cwdText(command)}${command.history}${newline}${bold( +${cwdText(command)}${command.history}${CLEAR_DOWN}${newline}${bold( `exit ${exitCode}` )} ${dim(`(${numExited}/${numTotal} exited)`)} @@ -1481,6 +1481,7 @@ const runInteractively = (commandDescriptions, autoExit) => { HIDE_CURSOR + RESET_COLOR + disableAlternateScreen + + CLEAR_DOWN + newlines + (command.status.tag === "Waiting" ? waitingText(commands) diff --git a/test-exit-in-middle.js b/test-exit-in-middle.js new file mode 100644 index 0000000..b40bc6e --- /dev/null +++ b/test-exit-in-middle.js @@ -0,0 +1,7 @@ +"use strict"; +for (let i = 0; i < 20; i++) { + console.log("stuff"); +} +require("readline").moveCursor(process.stdout, 0, -10); +process.stdout.write("final print"); +setTimeout(Function.prototype, 1000);