github.com/noriah/catnip@v1.8.5/graphic/terminal.go (about) 1 package graphic 2 3 import ( 4 "os" 5 "strings" 6 ) 7 8 // normalizeTerminal looks for incompatibilities in the terminal configuration 9 // with the underlying rendering libraries (Termbox) and makes some adjustments 10 // to avoid problems. 11 // 12 // Returns a function that allows you to restore the terminal configuration to its original state. 13 func normalizeTerminal() (func(), error) { 14 prevTERMINFO := os.Getenv("TERMINFO") 15 16 if strings.HasPrefix(os.Getenv("TERM"), "tmux") { 17 // Some combinations of TERMINFO with TERM in some Tmux value 18 // will cause Termbox to fail. 19 if err := os.Unsetenv("TERMINFO"); err != nil { 20 return nil, err 21 } 22 } 23 24 restore := func() { 25 if err := os.Setenv("TERMINFO", prevTERMINFO); err != nil { 26 panic(err) 27 } 28 } 29 30 return restore, nil 31 }