-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
81 lines (74 loc) · 2.28 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
79
80
81
package main
import (
"flag"
"github.com/eeeXun/gtt/internal/style"
"github.com/eeeXun/gtt/internal/translate"
"github.com/eeeXun/gtt/internal/ui"
"github.com/rivo/tview"
)
var (
// version
version string
// argument
srcLangArg *string = flag.String("src", "", "Set source language")
dstLangArg *string = flag.String("dst", "", "Set destination language")
// Translate
translator translate.Translator
translators = make(map[string]translate.Translator, len(translate.AllTranslator))
// UI style
uiStyle = style.NewStyle()
// keyMaps
keyMaps = make(map[string]string)
// UI
app = tview.NewApplication()
srcInput = tview.NewTextArea()
dstOutput = tview.NewTextView()
defOutput = tview.NewTextArea()
posOutput = tview.NewTextArea()
translatorDropDown = tview.NewDropDown()
srcLangDropDown = tview.NewDropDown()
dstLangDropDown = tview.NewDropDown()
langCycle = ui.NewUICycle(srcLangDropDown, dstLangDropDown, translatorDropDown)
themeDropDown = tview.NewDropDown()
transparentDropDown = tview.NewDropDown()
hideBelowDropDown = tview.NewDropDown()
osc52DropDown = tview.NewDropDown()
srcBorderDropDown = tview.NewDropDown()
dstBorderDropDown = tview.NewDropDown()
styleCycle = ui.NewUICycle(
themeDropDown,
transparentDropDown,
hideBelowDropDown,
osc52DropDown,
srcBorderDropDown,
dstBorderDropDown)
keyMapMenu = tview.NewTextView()
langButton = tview.NewButton("(1)Language")
styleButton = tview.NewButton("(2)Style")
keyMapButton = tview.NewButton("(3)KeyMap")
translateWindow = tview.NewFlex()
translateAboveWidget = tview.NewFlex()
translateBelowWidget = tview.NewFlex()
langPopOut = tview.NewFlex()
stylePopOut = tview.NewFlex()
keyMapPopOut = tview.NewFlex()
mainPage = tview.NewPages()
)
func main() {
showVersion := flag.Bool("version", false, "Show version")
flag.Parse()
switch {
case *showVersion:
print(version, "\n")
default:
configInit()
uiInit()
SetTermTitle(translator.GetEngineName())
if err := app.SetRoot(mainPage, true).
EnableMouse(true).Run(); err != nil {
panic(err)
}
// Check if config file need to be updated
defer updateConfig()
}
}