briandowns / spinner

Go (golang) package with 90 configurable terminal spinner/progress indicators.
Apache License 2.0
2.33k stars 129 forks source link

Unhide the cursor before exiting for termination signals #155

Open zimeg opened 1 year ago

zimeg commented 1 year ago

Summary

This PR unhides the cursor after a termination signal is sent while the spinner is active to prevent the cursor from disappearing in some terminals.

The signals listened for before termination are SIGHUP, SIGINT, SIGTERM, SIGQUIT – all gathered from the GNU termination signals page – and a custom syscall.Signal(0x0).

The syscall.Signal(0x0) is used to signal a successful .Stop() of the spinner and can safely be used as a termination signal since it doesn't send an actual signal, it only checks that the current process exists.

Preview

On some terminals, pressing CTRL-C would quit the program without unhiding the cursor. This example is shown with ANSI terminal:

Before changes https://github.com/briandowns/spinner/assets/18134219/c04b9098-a889-46f7-ac5f-fea25d399527
After changes https://github.com/briandowns/spinner/assets/18134219/e1b8d6f9-30b9-4ed6-bcbf-1a9f6eb86a3e

Reviewers

A small program to test with is ready in this repo to verify various exit codes and conditions in certain cases. Different testing cases are listed in SIGNALS.md if you want to try these yourself!

Notes

kernel-sanders commented 10 months ago

This solves my biggest problem with this library!

Unfortunately, it doesn't compile on Windows: spinner/spinner.go:359:14: undefined: syscall.Kill