From 636f2c2726b0c5c44225fe424ca84925b706de7e Mon Sep 17 00:00:00 2001 From: Johann Cruz Date: Wed, 24 Aug 2022 23:32:12 -0400 Subject: [PATCH] feat: catch SIGTERM (#412) * Added SIGTERM Signal. * docs: cleanup SIGINT/SIGTERM doc comment Co-authored-by: Christian Rocha --- tea.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tea.go b/tea.go index 28065a0..446a2bc 100644 --- a/tea.go +++ b/tea.go @@ -337,13 +337,17 @@ func (p *Program) StartReturningModel() (Model, error) { p.input = f } - // Listen for SIGINT. Note that in most cases ^C will not send an - // 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 - // TTY, however, ^C will be caught here. + // Listen for SIGINT and SIGTERM. + // + // In most cases ^C will not send an interrupt because the terminal will be + // 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() { sig := make(chan os.Signal, 1) - signal.Notify(sig, syscall.SIGINT) + signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) defer func() { signal.Stop(sig) close(sigintLoopDone)