feat: catch SIGTERM (#412)

* Added SIGTERM Signal.

* docs: cleanup SIGINT/SIGTERM doc comment

Co-authored-by: Christian Rocha <christian@rocha.is>
This commit is contained in:
Johann Cruz 2022-08-24 23:32:12 -04:00 committed by GitHub
parent 30bb43e5ae
commit 636f2c2726
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 5 deletions

14
tea.go
View File

@ -337,13 +337,17 @@ func (p *Program) StartReturningModel() (Model, error) {
p.input = f p.input = f
} }
// Listen for SIGINT. Note that in most cases ^C will not send an // Listen for SIGINT and SIGTERM.
// interrupt because the terminal will be in raw mode and thus capture //
// that keystroke and send it along to Program.Update. If input is not a // In most cases ^C will not send an interrupt because the terminal will be
// TTY, however, ^C will be caught here. // in raw mode and ^C will be captured as a keystroke and sent along to
// Program.Update as a KeyMsg. When input is not a TTY, however, ^C will be
// caught here.
//
// SIGTERM is sent by unix utilities (like kill) to terminate a process.
go func() { go func() {
sig := make(chan os.Signal, 1) sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT) signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
defer func() { defer func() {
signal.Stop(sig) signal.Stop(sig)
close(sigintLoopDone) close(sigintLoopDone)