openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
41 lines (40 loc) • 1.41 kB
JavaScript
import { t as clearActiveProgressLine } from "./progress-line-DiTuCPbL.js";
//#region packages/terminal-core/src/restore.ts
const RESET_SEQUENCE = "\x1B[0m\x1B[?25h\x1B[?1000l\x1B[?1002l\x1B[?1003l\x1B[?1006l\x1B[?2004l\x1B[<u\x1B[>4;0m";
function reportRestoreFailure(scope, err, reason) {
const suffix = reason ? ` (${reason})` : "";
const message = `[terminal] restore ${scope} failed${suffix}: ${String(err)}`;
try {
process.stderr.write(`${message}\n`);
} catch (writeErr) {
console.error(`[terminal] restore reporting failed${suffix}: ${String(writeErr)}`);
}
}
function restoreTerminalState(reason, options = {}) {
const resumeStdin = options.resumeStdinIfPaused ?? options.resumeStdin ?? false;
try {
clearActiveProgressLine();
} catch (err) {
reportRestoreFailure("progress line", err, reason);
}
const stdin = process.stdin;
if (stdin.isTTY && typeof stdin.setRawMode === "function") {
try {
stdin.setRawMode(false);
} catch (err) {
reportRestoreFailure("raw mode", err, reason);
}
if (resumeStdin && typeof stdin.isPaused === "function" && stdin.isPaused()) try {
stdin.resume();
} catch (err) {
reportRestoreFailure("stdin resume", err, reason);
}
}
if (process.stdout.isTTY) try {
process.stdout.write(RESET_SEQUENCE);
} catch (err) {
reportRestoreFailure("stdout reset", err, reason);
}
}
//#endregion
export { restoreTerminalState as t };