spinner icon indicating copy to clipboard operation
spinner copied to clipboard

Unhide the cursor before exiting for termination signals

Open zimeg opened this issue 1 year ago • 1 comments

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

  • A few other changes are included in these commits and separated by commit. Happy to adjust these to any preference!

zimeg avatar Aug 19 '23 23:08 zimeg

This solves my biggest problem with this library!

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

kernel-sanders avatar Nov 30 '23 01:11 kernel-sanders