(p *tea.Program)
| 23 | type terminateMsg struct{} |
| 24 | |
| 25 | func installSignalHandler(p *tea.Program) func() { |
| 26 | ch := make(chan struct{}) |
| 27 | |
| 28 | go func() { |
| 29 | sig := make(chan os.Signal, 1) |
| 30 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) |
| 31 | |
| 32 | defer func() { |
| 33 | signal.Stop(sig) |
| 34 | close(ch) |
| 35 | }() |
| 36 | |
| 37 | for { |
| 38 | select { |
| 39 | case <-ch: |
| 40 | return |
| 41 | |
| 42 | case <-sig: |
| 43 | p.Send(terminateMsg{}) |
| 44 | } |
| 45 | } |
| 46 | }() |
| 47 | |
| 48 | return func() { |
| 49 | ch <- struct{}{} |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | type SelectOptions struct { |
| 54 | Options []string |
no test coverage detected