From c02206233cf0ef8bcd1f3a77b81071561cf01c1a Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Thu, 25 Mar 2021 13:55:17 -0400 Subject: [PATCH] Try out recover for panic calls --- gilo.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gilo.go b/gilo.go index 2eea5ae..248949f 100644 --- a/gilo.go +++ b/gilo.go @@ -1,14 +1,25 @@ package main import ( + "fmt" + "golang.org/x/term" "timshome.page/gilo/editor" "timshome.page/gilo/terminal" ) +func cleanup(oldState *term.State) { + defer terminal.RawOff(oldState) + + // Recover from panic to allow restoring terminal state + if a := recover(); a != nil { + fmt.Println("RECOVER", a) + } +} + func main() { // Go to proper raw mode, but restore canonical mode at exit oldState := terminal.RawOn() - defer terminal.RawOff(oldState) + defer cleanup(oldState) e := editor.New()