From bdeb819725753a5ffd391fa58cb2ae2baa2818d7 Mon Sep 17 00:00:00 2001 From: Chapman Pendery Date: Tue, 20 May 2025 19:06:10 -0700 Subject: [PATCH 1/4] fix: reset terminal state / raw mode on exit Signed-off-by: Chapman Pendery --- src/ui/ui-root.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ui/ui-root.ts b/src/ui/ui-root.ts index fe6cb3a..e7f7d97 100644 --- a/src/ui/ui-root.ts +++ b/src/ui/ui-root.ts @@ -9,7 +9,7 @@ import { Command } from "commander"; import log from "../utils/log.js"; import { getBackspaceSequence, Shell } from "../utils/shell.js"; import isterm from "../isterm/index.js"; -import { eraseLinesBelow } from "../utils/ansi.js"; +import { eraseLinesBelow, resetToInitialState } from "../utils/ansi.js"; import { SuggestionManager, MAX_LINES, KeyPressEvent } from "./suggestionManager.js"; export const renderConfirmation = (live: boolean): string => { @@ -22,6 +22,7 @@ export const render = async (program: Command, shell: Shell, underTest: boolean, const suggestionManager = new SuggestionManager(term, shell); let hasActiveSuggestions = false; let previousSuggestionsRows = 0; + const stdinStartedInRawMode = process.stdin.isRaw; if (process.stdin.isTTY) process.stdin.setRawMode(true); readline.emitKeypressEvents(process.stdin); @@ -141,6 +142,8 @@ export const render = async (program: Command, shell: Shell, underTest: boolean, }); term.onExit(({ exitCode }) => { + if (!stdinStartedInRawMode) process.stdin.setRawMode(false); + process.stdout.write(resetToInitialState); process.exit(exitCode); }); process.stdout.on("resize", () => { From 073317fc20c2e5b7421258ee72474373a8e65f55 Mon Sep 17 00:00:00 2001 From: Chapman Pendery Date: Tue, 20 May 2025 19:10:27 -0700 Subject: [PATCH 2/4] fix: add missing reset Signed-off-by: Chapman Pendery --- src/utils/ansi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ansi.ts b/src/utils/ansi.ts index da392ca..8090e30 100644 --- a/src/utils/ansi.ts +++ b/src/utils/ansi.ts @@ -13,7 +13,6 @@ export enum IstermOscPt { PromptStarted = "PS", PromptEnded = "PE", CurrentWorkingDirectory = "CWD", - Prompt = "PROMPT", } export const IstermPromptStart = IS_OSC + IstermOscPt.PromptStarted + BEL; @@ -24,6 +23,7 @@ export const cursorNextLine = CSI + "E"; export const eraseLine = CSI + "2K"; export const resetColor = CSI + "0m"; export const resetLine = CSI + "2K"; +export const resetToInitialState = ESC + "c" // RIS - Reset to Initial State export const cursorBackward = (count = 1) => CSI + count + "D"; export const cursorForward = (count = 1) => CSI + count + "C"; export const cursorTo = ({ x, y }: { x?: number; y?: number }) => { From e2eac8e4f7bed255a2995d73ddcab151e21a37c7 Mon Sep 17 00:00:00 2001 From: Chapman Pendery Date: Tue, 20 May 2025 19:16:14 -0700 Subject: [PATCH 3/4] fix: style Signed-off-by: Chapman Pendery --- src/utils/ansi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ansi.ts b/src/utils/ansi.ts index 8090e30..e1b0099 100644 --- a/src/utils/ansi.ts +++ b/src/utils/ansi.ts @@ -23,7 +23,7 @@ export const cursorNextLine = CSI + "E"; export const eraseLine = CSI + "2K"; export const resetColor = CSI + "0m"; export const resetLine = CSI + "2K"; -export const resetToInitialState = ESC + "c" // RIS - Reset to Initial State +export const resetToInitialState = ESC + "c"; // RIS - Reset to Initial State export const cursorBackward = (count = 1) => CSI + count + "D"; export const cursorForward = (count = 1) => CSI + count + "C"; export const cursorTo = ({ x, y }: { x?: number; y?: number }) => { From 86b7fd947f941665bdb0fad6be32db1836b1a76a Mon Sep 17 00:00:00 2001 From: Chapman Pendery Date: Tue, 20 May 2025 19:21:55 -0700 Subject: [PATCH 4/4] fix: add back prompt Signed-off-by: Chapman Pendery --- src/utils/ansi.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/ansi.ts b/src/utils/ansi.ts index e1b0099..b3efc27 100644 --- a/src/utils/ansi.ts +++ b/src/utils/ansi.ts @@ -13,6 +13,7 @@ export enum IstermOscPt { PromptStarted = "PS", PromptEnded = "PE", CurrentWorkingDirectory = "CWD", + Prompt = "PROMPT", } export const IstermPromptStart = IS_OSC + IstermOscPt.PromptStarted + BEL;