forked from Mirrors/bubbletea
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:
parent
30bb43e5ae
commit
636f2c2726
14
tea.go
14
tea.go
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue