Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle SIGINT and SIGTERM #13

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package ysmrr
import (
"io"
"os"
"os/signal"
"syscall"
"time"

"github.com/chelnak/ysmrr/pkg/charmap"
Expand Down Expand Up @@ -59,6 +61,19 @@ func (sm *spinnerManager) GetSpinners() []*Spinner {

// Start signals that all spinners should start.
func (sm *spinnerManager) Start() {
// Handle SIGINT and SIGTERM so we can ensure that the
// terminal is properly reset.
// Unsure if this is the right place for this especially given
// that it calls os.Exit.
signals := make(chan os.Signal, 2)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)

go func() {
<-signals
sm.Stop()
os.Exit(0)
}()

sm.ticks = time.NewTicker(sm.frameDuration)
go sm.render()
}
Expand Down