Skip to content

Commit

Permalink
fix: clear stdout on ctrl+c (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Feb 3, 2021
1 parent 821f13d commit 1e15d38
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/prompt/os_signals.ts
Expand Up @@ -6,7 +6,7 @@ import { Toggle } from "../../prompt/toggle.ts";
const sig = Deno.signals.interrupt();
(async () => {
for await (const _ of sig) {
tty.cursorShow();
tty.cursorLeft.eraseDown.cursorShow();
console.log("\nSigint received. Exiting deno process!");
Deno.exit(1);
}
Expand Down
7 changes: 4 additions & 3 deletions prompt/README.md
Expand Up @@ -298,8 +298,9 @@ By default, cliffy will call `Deno.exit(0)` after the user presses `ctrl+c`. If
you need to use a custom signal handler, you can enable the `cbreak` option on
your prompt. This will enable pass-through of os signals to deno, allowing you
to register your own signal handler. Currently, when using prompts like `Select`
or `Toggle` and `cbreak` mode is enabled, you must manually show the cursor
before calling `Deno.exit()`. Maybe this will be improved somehow in the future.
or `Toggle` and `cbreak` mode is enabled, you have to show the cursor and clear
the stdout before calling `Deno.exit()` manually. Maybe this will be improved
somehow in the future.

```typescript
import { tty } from "https://deno.land/x/cliffy/ansi/tty.ts";
Expand All @@ -308,7 +309,7 @@ import { Toggle } from "https://deno.land/x/cliffy/prompt/toggle.ts";
const sig = Deno.signals.interrupt();
(async () => {
for await (const _ of sig) {
tty.cursorShow();
tty.cursorLeft.eraseDown.cursorShow();
console.log("\nSigint received. Exiting deno process!");
Deno.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion prompt/_generic_input.ts
Expand Up @@ -90,7 +90,7 @@ export abstract class GenericInput<
protected async handleEvent(event: KeyEvent): Promise<void> {
switch (true) {
case event.name === "c" && event.ctrl:
this.tty.cursorShow();
this.tty.cursorLeft.eraseDown.cursorShow();
Deno.exit(0);
return;
case this.isKey(this.settings.keys, "moveCursorLeft", event):
Expand Down
2 changes: 1 addition & 1 deletion prompt/_generic_prompt.ts
Expand Up @@ -227,7 +227,7 @@ export abstract class GenericPrompt<
protected async handleEvent(event: KeyEvent): Promise<void> {
switch (true) {
case event.name === "c" && event.ctrl:
this.tty.cursorShow();
this.tty.cursorLeft.eraseDown.cursorShow();
Deno.exit(0);
return;
case this.isKey(this.settings.keys, "submit", event):
Expand Down

0 comments on commit 1e15d38

Please sign in to comment.