From bb898ba0a8a9ac63086508bc9a6067986fc98c27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 5 Sep 2021 18:40:20 +0200 Subject: [PATCH] Add ansi reset at uninit --- TODO.md | 3 ++- ansi.test.ts | 2 +- ansi.ts | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index 9d295e5..80c7579 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,8 @@ - Add click events for ansi display - Fix resizing on web_div display -- Prevent ctrl+c on web display +- Ignore ctrl+c on web display (generally speaking, on displays that does not + support proper 'quit') - Optimize drawing to display, by allowing sequences of characters with the same colors (if supported by the display) - Restore ansi terminal properly after exit (ctrl+c does not work anymore, for diff --git a/ansi.test.ts b/ansi.test.ts index ef8bcd6..41c321f 100644 --- a/ansi.test.ts +++ b/ansi.test.ts @@ -18,7 +18,7 @@ describe(AnsiTerminalDisplay, () => { await display.init(); checkSequence(stdout, "![2J"); await display.uninit(); - checkSequence(stdout, "![2J![2J"); + checkSequence(stdout, "![2J![2J![?25h!c"); }); it("writes truecolor characters", async () => { diff --git a/ansi.ts b/ansi.ts index 9877493..ec3d3a2 100644 --- a/ansi.ts +++ b/ansi.ts @@ -34,6 +34,8 @@ export class AnsiTerminalDisplay extends Display { async uninit(): Promise { await this.writer.write(CLEAR); + await this.setCursorVisibility(true); + await this.writer.write(RESET); } async flush(): Promise { @@ -182,6 +184,7 @@ function get256Colors(): readonly Color[] { } const CLEAR = escape("[2J"); +const RESET = escape("c"); /** * Check if a reader will be compatible with raw mode