Skip to content
This repository was archived by the owner on Apr 19, 2024. It is now read-only.

Commit de54c4a

Browse files
author
Alan Donovan
authored
Clarify explanation of Ctrl-C (#373)
* Clarify explanation of Ctrl-C The user doesn't deliver SIGINT: the terminal does. * Fix typo.
1 parent 2a06c1e commit de54c4a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -464,17 +464,20 @@ survey aims to support most terminal emulators; it expects support for ANSI esca
464464
This means that reading from piped stdin or writing to piped stdout is **not supported**,
465465
and likely to break your application in these situations. See [#337](https://github.com/AlecAivazis/survey/pull/337#issue-581351617)
466466

467-
### Why isn't sending a SIGINT (aka. CTRL-C) signal working?
467+
### Why isn't Ctrl-C working?
468468

469-
When you send an interrupt signal to the process, it only interrupts the current prompt instead of the entire process. This manifests in a `github.com/AlecAivazis/survey/v2/terminal.InterruptErr` being returned from `Ask` and `AskOne`. If you want to stop the process, handle the returned error in your code:
469+
Ordinarily, when you type Ctrl-C, the terminal recognizes this as the QUIT button and delivers a SIGINT signal to the process, which terminates it.
470+
However, Survey temporarily configures the terminal to deliver control codes as ordinary input bytes.
471+
When Survey reads a ^C byte (ASCII \x03, "end of text"), it interrupts the current survey and returns a
472+
`github.com/AlecAivazis/survey/v2/terminal.InterruptErr` from `Ask` or `AskOne`.
473+
If you want to stop the process, handle the returned error in your code:
470474

471475
```go
472476
err := survey.AskOne(prompt, &myVar)
473-
if err == terminal.InterruptErr {
474-
fmt.Println("interrupted")
475-
476-
os.Exit(0)
477-
} else if err != nil {
478-
panic(err)
477+
if err != nil {
478+
if err == terminal.InterruptErr {
479+
log.Fatal("interrupted")
480+
}
481+
...
479482
}
480483
```

0 commit comments

Comments
 (0)