Disconnect UI from main Gomuks struct. Fixes #21

This commit is contained in:
Tulir Asokan
2018-04-18 18:35:24 +03:00
parent 3b2d5fa034
commit b17ff318c2
15 changed files with 137 additions and 97 deletions

View File

@@ -29,6 +29,8 @@ import (
)
var writer io.Writer
var RecoverPrettyPanic bool
var OnRecover func()
func init() {
var err error
@@ -59,6 +61,22 @@ func PrintStack() {
}
}
// Recover recovers a panic, runs the OnRecover handler and either re-panics or
// shows an user-friendly message about the panic depending on whether or not
// the pretty panic mode is enabled.
func Recover() {
if p := recover(); p != nil {
if OnRecover != nil {
OnRecover()
}
if RecoverPrettyPanic {
PrettyPanic(p)
} else {
panic(p)
}
}
}
const Oops = ` __________
< Oh noes! >
‾‾‾\‾‾‾‾‾‾