Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ui/ui-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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);

Expand Down Expand Up @@ -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", () => {
Expand Down
1 change: 1 addition & 0 deletions src/utils/ansi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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 }) => {
Expand Down