...
1
2
3 package prompt
4
5 import (
6 "os"
7 "os/signal"
8 "syscall"
9
10 "github.com/c-bata/go-prompt/internal/debug"
11 )
12
13 func (p *Prompt) handleSignals(exitCh chan int, winSizeCh chan *WinSize, stop chan struct{}) {
14 in := p.in
15 sigCh := make(chan os.Signal, 1)
16 signal.Notify(
17 sigCh,
18 syscall.SIGINT,
19 syscall.SIGTERM,
20 syscall.SIGQUIT,
21 syscall.SIGWINCH,
22 )
23
24 for {
25 select {
26 case <-stop:
27 debug.Log("stop handleSignals")
28 return
29 case s := <-sigCh:
30 switch s {
31 case syscall.SIGINT:
32 debug.Log("Catch SIGINT")
33 exitCh <- 0
34
35 case syscall.SIGTERM:
36 debug.Log("Catch SIGTERM")
37 exitCh <- 1
38
39 case syscall.SIGQUIT:
40 debug.Log("Catch SIGQUIT")
41 exitCh <- 0
42
43 case syscall.SIGWINCH:
44 debug.Log("Catch SIGWINCH")
45 winSizeCh <- in.GetWinSize()
46 }
47 }
48 }
49 }
50
View as plain text