1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Move settings of TERM out of main()

This commit is contained in:
Chris Cummer 2019-07-21 16:32:18 -07:00
parent 7a7df7d4a7
commit 7a70ed75be

15
main.go
View File

@ -12,6 +12,7 @@ import (
"time" "time"
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/olebedev/config"
"github.com/pkg/profile" "github.com/pkg/profile"
"github.com/radovskyb/watcher" "github.com/radovskyb/watcher"
"github.com/rivo/tview" "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) { func watchForConfigChanges(app *tview.Application, configFilePath string, isCustomConfig bool, grid *tview.Grid, pages *tview.Pages) {
watch := watcher.New() watch := watcher.New()
absPath, _ := utils.ExpandHomeDir(configFilePath) absPath, _ := utils.ExpandHomeDir(configFilePath)
@ -141,10 +151,7 @@ func main() {
defer profile.Start(profile.MemProfile).Stop() defer profile.Start(profile.MemProfile).Stop()
} }
err := os.Setenv("TERM", config.UString("wtf.term", os.Getenv("TERM"))) setTerm(config)
if err != nil {
return
}
wtf.OpenFileUtil = config.UString("wtf.openFileUtil", "open") wtf.OpenFileUtil = config.UString("wtf.openFileUtil", "open")