github.com/xyproto/orbiton/v2@v2.65.12-0.20240516144430-e10a419274ec/errormsg.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "runtime/debug" 7 "strings" 8 9 "github.com/xyproto/textoutput" 10 "github.com/xyproto/vt100" 11 ) 12 13 func quitError(tty *vt100.TTY, err error) { 14 if tty != nil { 15 tty.Close() 16 } 17 vt100.Reset() 18 vt100.Clear() 19 vt100.Close() 20 textoutput.NewTextOutput(true, true).Err(err.Error()) 21 vt100.SetXY(uint(0), uint(1)) 22 quitMut.Lock() 23 defer quitMut.Unlock() 24 os.Exit(1) 25 } 26 27 func quitMessage(tty *vt100.TTY, msg string) { 28 if tty != nil { 29 tty.Close() 30 } 31 vt100.Reset() 32 vt100.Clear() 33 vt100.Close() 34 fmt.Fprintln(os.Stderr, msg) 35 newLineCount := strings.Count(msg, "\n") 36 vt100.SetXY(uint(0), uint(newLineCount+1)) 37 quitMut.Lock() 38 defer quitMut.Unlock() 39 os.Exit(1) 40 } 41 42 func quitMessageWithStack(tty *vt100.TTY, msg string) { 43 if tty != nil { 44 tty.Close() 45 } 46 vt100.Reset() 47 vt100.Clear() 48 vt100.Close() 49 fmt.Fprintln(os.Stderr, msg) 50 newLineCount := strings.Count(msg, "\n") 51 vt100.SetXY(uint(0), uint(newLineCount+1)) 52 debug.PrintStack() 53 quitMut.Lock() 54 defer quitMut.Unlock() 55 os.Exit(1) 56 }