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

Move SetTerminal out of main and into its own file

Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
Chris Cummer 2020-12-21 03:06:38 -08:00
parent cf6d2fc061
commit 8b00760267
3 changed files with 27 additions and 28 deletions

View File

@ -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
}

29
main.go
View File

@ -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)

22
wtf/terminal.go Normal file
View File

@ -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)
}
}