From 4a6b466943e6b5dfbb2b868197e64e2ab0e4152f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Wed, 31 Oct 2018 23:12:00 +0100 Subject: print detailed error message for ErrTermNotFound Closes #15. Unfortunately, it seems that the "terminfo" infrastructure in the Linux/Unix world is defined only at C ABI level (not at file format level), and as such is fundamentally incompatible with pure-Go applications. I don't see a good way to solve this problem in a cross-platform (or, mainly, cross-Unix) way, so I'm currently falling back to displaying an error message, asking user to patch the mess locally for themselves by hand. --- up.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/up.go b/up.go index 97b379e..f647e1f 100644 --- a/up.go +++ b/up.go @@ -21,6 +21,7 @@ import ( "bufio" "bytes" "context" + "crypto/sha1" "fmt" "io" "io/ioutil" @@ -30,6 +31,7 @@ import ( "sync" "github.com/gdamore/tcell" + "github.com/gdamore/tcell/terminfo" "github.com/mattn/go-isatty" "github.com/spf13/pflag" ) @@ -233,6 +235,29 @@ func initTUI() tcell.Screen { // Init TUI code // TODO: maybe try gocui or termbox? tui, err := tcell.NewScreen() + if err == terminfo.ErrTermNotFound { + term := os.Getenv("TERM") + hash := sha1.Sum([]byte(term)) + // TODO: add a flag which would attempt to perform the download automatically if explicitly requested by user + die(fmt.Sprintf(`%[1]s +Your terminal code: + TERM=%[2]s +was not found in the database provided by tcell library. Please try checking if +a supplemental database is found for your terminal at one of the following URLs: + https://github.com/gdamore/tcell/raw/master/terminfo/database/%.1[3]x/%.4[3]x + https://github.com/gdamore/tcell/raw/master/terminfo/database/%.1[3]x/%.4[3]x.gz +If yes, download it and save in the following directory: + $HOME/.tcelldb/%.1[3]x/ +then try running "up" again. If that does not work for you, please first consult: + https://github.com/akavel/up/issues/15 +and if you don't see your terminal code mentioned there, please try asking on: + https://github.com/gdamore/tcell/issues +Or, you might try changing TERM temporarily to some other value, for example by +running "up" with: + TERM=xterm up +Good luck!`, + err, term, hash)) + } if err != nil { die(err.Error()) } -- cgit v1.2.3