Print error message to stderr on unexpected exit

This commit is contained in:
Junegunn Choi 2017-01-11 23:01:56 +09:00
parent 2aa739be81
commit d64828ce6d
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
4 changed files with 9 additions and 15 deletions

View File

@ -241,7 +241,7 @@ func (r *LightRenderer) getBytesInternal(buffer []byte) []byte {
c, ok := r.getch(false) c, ok := r.getch(false)
if !ok { if !ok {
r.Close() r.Close()
errorExit() errorExit("Failed to read /dev/tty")
} }
retries := 0 retries := 0

View File

@ -25,7 +25,6 @@ int c_getcurx(WINDOW* win) {
import "C" import "C"
import ( import (
"fmt"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@ -109,13 +108,11 @@ func (r *FullscreenRenderer) Init() {
C.setlocale(C.LC_ALL, C.CString("")) C.setlocale(C.LC_ALL, C.CString(""))
tty := C.c_tty() tty := C.c_tty()
if tty == nil { if tty == nil {
fmt.Println("Failed to open /dev/tty") errorExit("Failed to open /dev/tty")
errorExit()
} }
_screen = C.c_newterm(tty) _screen = C.c_newterm(tty)
if _screen == nil { if _screen == nil {
fmt.Println("Invalid $TERM: " + os.Getenv("TERM")) errorExit("Invalid $TERM: " + os.Getenv("TERM"))
errorExit()
} }
C.set_term(_screen) C.set_term(_screen)
if r.mouse { if r.mouse {
@ -380,7 +377,7 @@ func (r *FullscreenRenderer) GetChar() Event {
case C.ERR: case C.ERR:
// Unexpected error from blocking read // Unexpected error from blocking read
r.Close() r.Close()
errorExit() errorExit("Failed to read /dev/tty")
case C.KEY_UP: case C.KEY_UP:
return Event{Up, 0, nil} return Event{Up, 0, nil}
case C.KEY_DOWN: case C.KEY_DOWN:

View File

@ -6,9 +6,6 @@ import (
"time" "time"
"unicode/utf8" "unicode/utf8"
"fmt"
"os"
"runtime" "runtime"
// https://github.com/gdamore/tcell/pull/135 // https://github.com/gdamore/tcell/pull/135
@ -123,12 +120,10 @@ var (
func (r *FullscreenRenderer) initScreen() { func (r *FullscreenRenderer) initScreen() {
s, e := tcell.NewScreen() s, e := tcell.NewScreen()
if e != nil { if e != nil {
fmt.Fprintf(os.Stderr, "%v\n", e) errorExit(e.Error())
errorExit()
} }
if e = s.Init(); e != nil { if e = s.Init(); e != nil {
fmt.Fprintf(os.Stderr, "%v\n", e) errorExit(e.Error())
errorExit()
} }
if r.mouse { if r.mouse {
s.EnableMouse() s.EnableMouse()

View File

@ -1,6 +1,7 @@
package tui package tui
import ( import (
"fmt"
"os" "os"
"strconv" "strconv"
"time" "time"
@ -284,7 +285,8 @@ func EmptyTheme() *ColorTheme {
Border: colUndefined} Border: colUndefined}
} }
func errorExit() { func errorExit(message string) {
fmt.Fprintln(os.Stderr, message)
os.Exit(2) os.Exit(2)
} }