fables-tales / rubyfmt

Ruby Autoformatter!
MIT License
1.07k stars 50 forks source link

Properly exit when receiving `SIGINT`/`SIGTERM`/`SIGHUP` #377

Closed reese closed 1 year ago

reese commented 1 year ago

Resolves #322

Currently, rubyfmt has no concept of signal handling, and while it's theoretically so fast it shouldn't matter, there are times where it can hang or run for very long times (e.g. running in debug mode on gigantic files) where users may want to kill it. This PR uses the ctrlc crate to just exit when receiving any of SIGINT/SIGTERM/SIGHUP from the OS.

There may be more graceful ways to handle this (like setting a variable and then checking it at certain places in the program), but just exiting gets us 99% of the value here with far less invasive changes.