From 7a70ed75be20fd2515da0477fd072048e13db814 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 21 Jul 2019 16:32:18 -0700 Subject: [PATCH] Move settings of TERM out of main() --- main.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 70e752b0..cc97a00d 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "time" "github.com/gdamore/tcell" + "github.com/olebedev/config" "github.com/pkg/profile" "github.com/radovskyb/watcher" "github.com/rivo/tview" @@ -79,6 +80,15 @@ func refreshAllWidgets(widgets []wtf.Wtfable) { } } +func setTerm(config *config.Config) { + term := config.UString("wtf.term", os.Getenv("TERM")) + err := os.Setenv("TERM", term) + if err != nil { + fmt.Printf("\n\033[0;31mERROR:\033[0m Failed to set $TERM to '\033[0;33m%s\033[0m'.\n", term) + os.Exit(1) + } +} + func watchForConfigChanges(app *tview.Application, configFilePath string, isCustomConfig bool, grid *tview.Grid, pages *tview.Pages) { watch := watcher.New() absPath, _ := utils.ExpandHomeDir(configFilePath) @@ -141,10 +151,7 @@ func main() { defer profile.Start(profile.MemProfile).Stop() } - err := os.Setenv("TERM", config.UString("wtf.term", os.Getenv("TERM"))) - if err != nil { - return - } + setTerm(config) wtf.OpenFileUtil = config.UString("wtf.openFileUtil", "open")