From 8b00760267e8a5740259166ce5c828d7694ce438 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Mon, 21 Dec 2020 03:06:38 -0800 Subject: [PATCH] Move SetTerminal out of main and into its own file Signed-off-by: Chris Cummer --- app/exit_message.go | 4 ++-- main.go | 29 +++-------------------------- wtf/terminal.go | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 28 deletions(-) create mode 100644 wtf/terminal.go diff --git a/app/exit_message.go b/app/exit_message.go index 6dcd3e05..f68779ff 100644 --- a/app/exit_message.go +++ b/app/exit_message.go @@ -84,14 +84,14 @@ func readGitHubAPIKey(cfg *config.Config) string { func (wtfApp *WtfApp) contributorThankYouMessage() string { str := " On behalf of all the users of WTF, thank you for contributing to the source code." - str += fmt.Sprintf(" %s", aurora.Green("You rock.")) + str += fmt.Sprintf(" %s", aurora.Green("\n\n You rock.")) return str } func (wtfApp *WtfApp) sponsorThankYouMessage() string { str := " Your sponsorship of WTF makes a difference. Thank you for sponsoring and supporting WTF." - str += fmt.Sprintf(" %s", aurora.Green("You're awesome.")) + str += fmt.Sprintf(" %s", aurora.Green("\n\n You're awesome.")) return str } diff --git a/main.go b/main.go index 32d996c9..b95cd667 100644 --- a/main.go +++ b/main.go @@ -12,44 +12,20 @@ import ( _ "time/tzdata" "github.com/logrusorgru/aurora" - "github.com/olebedev/config" "github.com/pkg/profile" - "github.com/rivo/tview" "github.com/wtfutil/wtf/app" "github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/flags" "github.com/wtfutil/wtf/utils" + "github.com/wtfutil/wtf/wtf" ) -var tviewApp *tview.Application - var ( date = "dev" version = "dev" ) -/* -------------------- Functions -------------------- */ - -func setTerm(config *config.Config) { - term := config.UString("wtf.term", os.Getenv("TERM")) - err := os.Setenv("TERM", term) - if err != nil { - fmt.Printf("\n%s Failed to set $TERM to %s.\n", aurora.Red("ERROR"), aurora.Yellow(term)) - os.Exit(1) - } -} - -// // FIXME: Move this into the AppManager -// panic("BOO") -// func makeWtfApp(config *config.Config, flagConfig string) app.WtfApp { -// tviewApp = tview.NewApplication() -// wtfApp := app.NewWtfApp(tviewApp, config, flagConfig) -// wtfApp.Start() - -// return wtfApp -// } - /* -------------------- Main -------------------- */ func main() { @@ -62,7 +38,8 @@ func main() { // Load the configuration file cfg.Initialize(flags.HasCustomConfig()) config := cfg.LoadWtfConfigFile(flags.ConfigFilePath()) - setTerm(config) + + wtf.SetTerminal(config) flags.RenderIf(version, date, config) diff --git a/wtf/terminal.go b/wtf/terminal.go new file mode 100644 index 00000000..4700e1d4 --- /dev/null +++ b/wtf/terminal.go @@ -0,0 +1,22 @@ +package wtf + +import ( + "fmt" + "os" + + "github.com/logrusorgru/aurora" + "github.com/olebedev/config" +) + +// SetTerminal sets the TERM environment variable, defaulting to whatever the OS +// has as the current value if none is specified. +// See https://www.gnu.org/software/gettext/manual/html_node/The-TERM-variable.html for +// more details. +func SetTerminal(config *config.Config) { + term := config.UString("wtf.term", os.Getenv("TERM")) + err := os.Setenv("TERM", term) + if err != nil { + fmt.Printf("\n%s Failed to set $TERM to %s.\n", aurora.Red("ERROR"), aurora.Yellow(term)) + os.Exit(1) + } +}