summary refs log tree commit diff stats
path: root/aerc.go
diff options
context:
space:
mode:
Diffstat (limited to 'aerc.go')
-rw-r--r--aerc.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/aerc.go b/aerc.go
index 17b3c57..33acb43 100644
--- a/aerc.go
+++ b/aerc.go
@@ -6,6 +6,7 @@ import (
 	"io/ioutil"
 	"log"
 	"os"
+	"runtime/debug"
 	"sort"
 	"time"
 
@@ -153,6 +154,8 @@ func main() {
 		ui   *libui.UI
 	)
 
+	defer PanicTermFix(ui) // recover upon panic and try restoring the pty
+
 	aerc = widgets.NewAerc(conf, logger, func(cmd []string) error {
 		return execCommand(aerc, ui, cmd)
 	}, func(cmd string) []string {
@@ -198,3 +201,19 @@ func main() {
 	}
 	aerc.CloseBackends()
 }
+
+//FatalTermFix prints the stacktrace upon panic and tries to recover the term
+// not doing that leaves the terminal in a broken state
+func PanicTermFix(ui *libui.UI) {
+	var err interface{}
+	if err = recover(); err == nil {
+		return
+	}
+	debug.PrintStack()
+	if ui != nil {
+		ui.Close()
+	}
+	fmt.Fprintf(os.Stderr, "aerc crashed: %v\n", err)
+	os.Exit(1)
+
+}
='n140' href='#n140'>140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186