Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make sure the interactive printers can cleanup after Ctrl+C
After canceling the interactive printers with Ctrl+C, `os.Exit` was directly called in the keyboard listener. Because of this the `defer` statements of the surrounding function were not called (for example `cursor.Show`) and the keyboard listener was still running. This resulted in a broken user "terminal" (no Cursor, no Ctrl+C)
- Loading branch information
Showing
4 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package internal | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// CancelationSignal for keeping track of a cancelation | ||
type CancelationSignal struct { | ||
canceled bool | ||
} | ||
|
||
// Cancel marks the signal as canceled | ||
func (cs *CancelationSignal) Cancel() { | ||
cs.canceled = true | ||
} | ||
|
||
// ExitOnCancelation exists with code=1 if the signal was marked as canceled | ||
func (cs *CancelationSignal) ExitOnCancelation() { | ||
if cs.canceled { | ||
os.Exit(1) | ||
} | ||
} |