Skip to content

Commit fbe5c85

Browse files
committed
fix: catch an interrupt implementation available on all goos
1 parent 58e95e9 commit fbe5c85

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

Diff for: spinner.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,8 @@ func (s *Spinner) Start() {
329329
color.NoColor = true
330330
}
331331

332-
interrupts := []os.Signal{
333-
syscall.Signal(0x0),
334-
syscall.SIGHUP,
335-
syscall.SIGINT,
336-
syscall.SIGQUIT,
337-
syscall.SIGTERM,
338-
}
339-
signal.Notify(s.stopChan, interrupts...)
340-
341332
s.active = true
333+
signal.Notify(s.stopChan, syscall.Signal(0x0), os.Interrupt)
342334
s.mu.Unlock()
343335

344336
go func() {
@@ -353,9 +345,14 @@ func (s *Spinner) Start() {
353345
if s.HideCursor && !isWindowsTerminalOnWindows {
354346
fmt.Fprint(s.Writer, "\033[?25h")
355347
}
348+
signal.Stop(s.stopChan)
349+
if !isWindows {
350+
process, _ := os.FindProcess(os.Getpid())
351+
_ = process.Signal(sig)
352+
}
353+
} else {
354+
signal.Stop(s.stopChan)
356355
}
357-
signal.Stop(s.stopChan)
358-
syscall.Kill(os.Getpid(), sig.(syscall.Signal))
359356
return
360357
default:
361358
s.mu.Lock()

Diff for: spinner_test.go

+2-11
Original file line numberDiff line numberDiff line change
@@ -326,25 +326,16 @@ func TestUnhideCursor(t *testing.T) {
326326
interrupt os.Signal
327327
}{
328328
"the spinner stops normally": {},
329-
"the terminal hangs up": {
330-
interrupt: syscall.SIGHUP,
331-
},
332329
"the process is interrupted": {
333-
interrupt: syscall.SIGINT,
334-
},
335-
"the process is quit": {
336-
interrupt: syscall.SIGQUIT,
337-
},
338-
"the process is terminated": {
339-
interrupt: syscall.SIGTERM,
330+
interrupt: os.Interrupt,
340331
},
341332
}
342333

343334
for name, test := range tests {
344335
t.Run(name, func(t *testing.T) {
345336
s, out := withOutput(CharSets[1], 100*time.Millisecond)
346337
interrupts := make(chan os.Signal, 1)
347-
signal.Notify(interrupts, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
338+
signal.Notify(interrupts, syscall.Signal(0x0), os.Interrupt)
348339
defer signal.Stop(interrupts)
349340
defer close(interrupts)
350341

0 commit comments

Comments
 (0)