forked from wtfutil/wtf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (59 loc) · 1.7 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
// Generators
// To generate the skeleton for a new TextWidget use 'WTF_WIDGET_NAME=MySuperAwesomeWidget go generate -run=text
//go:generate -command text go run generator/textwidget.go
//go:generate text
import (
"fmt"
"log"
"os"
"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"
)
var tviewApp *tview.Application
var (
commit = "dev"
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)
}
}
/* -------------------- Main -------------------- */
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
// Manage the configuration directories and config file
// Parse and handle flags
flags := flags.NewFlags()
flags.Parse()
hasCustom := flags.HasCustomConfig()
cfg.Initialize(hasCustom)
// Load the configuration file
config := cfg.LoadWtfConfigFile(flags.ConfigFilePath(), hasCustom)
flags.RenderIf(version, config)
if flags.Profile {
defer profile.Start(profile.MemProfile).Stop()
}
utils.Init(config.UString("wtf.openFileUtil", "open"))
setTerm(config)
// Build the application
tviewApp = tview.NewApplication()
wtfApp := app.NewWtfApp(tviewApp, config, flags.Config, hasCustom)
wtfApp.Start()
if err := tviewApp.Run(); err != nil {
fmt.Printf("\n%s %v\n", aurora.Red("ERROR"), err)
os.Exit(1)
}
}