v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-18 16:50:14 -07:00

Merge branch 'master' into part_of_speech

This commit is contained in:
eeeXun 2023-01-11 16:51:57 +08:00
commit 40179f17e2
3 changed files with 78 additions and 68 deletions

View File

@ -24,7 +24,7 @@ func configInit() {
}
config.AddConfigPath("$HOME/.config/gtt")
// create config file if not exists
// Create config file if not exists
if err := config.ReadInConfig(); err != nil {
config.Set("transparent", false)
config.Set("theme", "Gruvbox")

View File

@ -45,10 +45,10 @@ func main() {
configInit()
uiInit()
mainPage.AddPage("translatePage", translateWindow, true, true)
mainPage.AddPage("langPage", langWindow, true, false)
mainPage.AddPage("stylePage", styleWindow, true, false)
mainPage.AddPage("keyMapPage", keyMapWindow, true, false)
mainPage.AddPage("translateWindow", translateWindow, true, true)
mainPage.AddPage("langWindow", langWindow, true, false)
mainPage.AddPage("styleWindow", styleWindow, true, false)
mainPage.AddPage("keyMapWindow", keyMapWindow, true, false)
if err := app.SetRoot(mainPage, true).
EnableMouse(true).Run(); err != nil {

136
ui.go
View File

@ -43,10 +43,10 @@ const (
func updateBackgroundColor() {
// input/output
srcInput.SetBackgroundColor(style.BackgroundColor())
srcInput.SetTextStyle(tcell.StyleDefault.
Background(style.BackgroundColor()).
Foreground(style.ForegroundColor()))
Foreground(style.ForegroundColor())).
SetBackgroundColor(style.BackgroundColor())
dstOutput.SetBackgroundColor(style.BackgroundColor())
defOutput.SetBackgroundColor(style.BackgroundColor())
defOutput.SetTextStyle(tcell.StyleDefault.
@ -58,48 +58,48 @@ func updateBackgroundColor() {
Foreground(style.ForegroundColor()))
// dropdown
srcLangDropDown.SetBackgroundColor(style.BackgroundColor())
srcLangDropDown.SetListStyles(tcell.StyleDefault.
Background(style.BackgroundColor()).
Foreground(style.ForegroundColor()),
tcell.StyleDefault.
Background(style.SelectedColor()).
Foreground(style.PrefixColor()))
dstLangDropDown.SetBackgroundColor(style.BackgroundColor())
Foreground(style.PrefixColor())).
SetBackgroundColor(style.BackgroundColor())
dstLangDropDown.SetListStyles(tcell.StyleDefault.
Background(style.BackgroundColor()).
Foreground(style.ForegroundColor()),
tcell.StyleDefault.
Background(style.SelectedColor()).
Foreground(style.PrefixColor()))
themeDropDown.SetBackgroundColor(style.BackgroundColor())
Foreground(style.PrefixColor())).
SetBackgroundColor(style.BackgroundColor())
themeDropDown.SetListStyles(tcell.StyleDefault.
Background(style.BackgroundColor()).
Foreground(style.ForegroundColor()),
tcell.StyleDefault.
Background(style.SelectedColor()).
Foreground(style.PrefixColor()))
transparentDropDown.SetBackgroundColor(style.BackgroundColor())
Foreground(style.PrefixColor())).
SetBackgroundColor(style.BackgroundColor())
transparentDropDown.SetListStyles(tcell.StyleDefault.
Background(style.BackgroundColor()).
Foreground(style.ForegroundColor()),
tcell.StyleDefault.
Background(style.SelectedColor()).
Foreground(style.PrefixColor()))
srcBorderDropDown.SetBackgroundColor(style.BackgroundColor())
Foreground(style.PrefixColor())).
SetBackgroundColor(style.BackgroundColor())
srcBorderDropDown.SetListStyles(tcell.StyleDefault.
Background(style.BackgroundColor()).
Foreground(style.ForegroundColor()),
tcell.StyleDefault.
Background(style.SelectedColor()).
Foreground(style.PrefixColor()))
dstBorderDropDown.SetBackgroundColor(style.BackgroundColor())
Foreground(style.PrefixColor())).
SetBackgroundColor(style.BackgroundColor())
dstBorderDropDown.SetListStyles(tcell.StyleDefault.
Background(style.BackgroundColor()).
Foreground(style.ForegroundColor()),
tcell.StyleDefault.
Background(style.SelectedColor()).
Foreground(style.PrefixColor()))
Foreground(style.PrefixColor())).
SetBackgroundColor(style.BackgroundColor())
// key map
keyMapMenu.SetBackgroundColor(style.BackgroundColor())
@ -147,20 +147,20 @@ func updateNonConfigColor() {
dstLangDropDown.SetFieldBackgroundColor(style.SelectedColor()).
SetFieldTextColor(style.ForegroundColor()).
SetPrefixTextColor(style.PrefixColor())
themeDropDown.SetLabelColor(style.LabelColor())
themeDropDown.SetFieldBackgroundColor(style.SelectedColor()).
themeDropDown.SetLabelColor(style.LabelColor()).
SetFieldBackgroundColor(style.SelectedColor()).
SetFieldTextColor(style.ForegroundColor()).
SetPrefixTextColor(style.PrefixColor())
transparentDropDown.SetLabelColor(style.LabelColor())
transparentDropDown.SetFieldBackgroundColor(style.SelectedColor()).
transparentDropDown.SetLabelColor(style.LabelColor()).
SetFieldBackgroundColor(style.SelectedColor()).
SetFieldTextColor(style.ForegroundColor()).
SetPrefixTextColor(style.PrefixColor())
srcBorderDropDown.SetLabelColor(style.LabelColor())
srcBorderDropDown.SetFieldBackgroundColor(style.SelectedColor()).
srcBorderDropDown.SetLabelColor(style.LabelColor()).
SetFieldBackgroundColor(style.SelectedColor()).
SetFieldTextColor(style.ForegroundColor()).
SetPrefixTextColor(style.PrefixColor())
dstBorderDropDown.SetLabelColor(style.LabelColor())
dstBorderDropDown.SetFieldBackgroundColor(style.SelectedColor()).
dstBorderDropDown.SetLabelColor(style.LabelColor()).
SetFieldBackgroundColor(style.SelectedColor()).
SetFieldTextColor(style.ForegroundColor()).
SetPrefixTextColor(style.PrefixColor())
@ -197,10 +197,14 @@ func updateAllColor() {
func updateTitle() {
srcInput.SetTitle(translator.SrcLang)
dstOutput.SetTitle(translator.DstLang)
srcLangDropDown.SetCurrentOption(IndexOf(translator.SrcLang, translate.Lang))
srcLangDropDown.SetTitle(translator.SrcLang)
dstLangDropDown.SetCurrentOption(IndexOf(translator.DstLang, translate.Lang))
dstLangDropDown.SetTitle(translator.DstLang)
srcLangDropDown.SetCurrentOption(
IndexOf(translator.SrcLang,
translate.Lang)).
SetTitle(translator.SrcLang)
dstLangDropDown.SetCurrentOption(
IndexOf(translator.DstLang,
translate.Lang)).
SetTitle(translator.DstLang)
}
func attachButton() *tview.Flex {
@ -224,10 +228,10 @@ func uiInit() {
SetTitle("Part of speech")
// dropdown
srcLangDropDown.SetBorder(true)
srcLangDropDown.SetOptions(translate.Lang, nil)
dstLangDropDown.SetBorder(true)
dstLangDropDown.SetOptions(translate.Lang, nil)
srcLangDropDown.SetOptions(translate.Lang, nil).
SetBorder(true)
dstLangDropDown.SetOptions(translate.Lang, nil).
SetBorder(true)
themeDropDown.SetLabel("Theme: ").
SetOptions(color.AllTheme, nil).
SetCurrentOption(IndexOf(style.Theme, color.AllTheme))
@ -238,19 +242,25 @@ func uiInit() {
[]string{"true", "false"}))
srcBorderDropDown.SetLabel("Border Color: ").
SetOptions(color.Palette, nil).
SetCurrentOption(IndexOf(style.SrcBorderStr(), color.Palette))
srcBorderDropDown.SetBorder(true).
SetCurrentOption(
IndexOf(style.SrcBorderStr(),
color.Palette)).
SetBorder(true).
SetTitle("Source")
dstBorderDropDown.SetLabel("Border Color: ").
SetOptions(color.Palette, nil).
SetCurrentOption(IndexOf(style.DstBorderStr(), color.Palette))
dstBorderDropDown.SetBorder(true).
SetCurrentOption(
IndexOf(style.DstBorderStr(),
color.Palette)).
SetBorder(true).
SetTitle("Destination")
// key map
keyMapMenu.SetBorder(true).
keyMapMenu.SetDynamicColors(true).
SetText(fmt.Sprintf(keyMapText,
fmt.Sprintf("%.6x", style.HighLightColor().TrueColor().Hex()))).
SetBorder(true).
SetTitle("Key Map")
keyMapMenu.SetDynamicColors(true)
// window
translateWindow.SetDirection(tview.FlexColumn).
@ -309,7 +319,7 @@ func uiInit() {
// handler
mainPage.SetInputCapture(mainPageHandler)
translateWindow.SetInputCapture(translatePageHandler)
translateWindow.SetInputCapture(translateWindowHandler)
langWindow.SetInputCapture(popOutWindowHandler)
styleWindow.SetInputCapture(popOutWindowHandler)
keyMapWindow.SetInputCapture(popOutWindowHandler)
@ -348,25 +358,25 @@ func uiInit() {
keyMapMenu.SetDoneFunc(func(key tcell.Key) {
switch key {
case tcell.KeyEsc:
mainPage.HidePage("keyMapPage")
mainPage.HidePage("keyMapWindow")
}
})
langButton.SetSelectedFunc(func() {
mainPage.HidePage("stylePage")
mainPage.HidePage("keyMapPage")
mainPage.ShowPage("langPage")
mainPage.HidePage("styleWindow")
mainPage.HidePage("keyMapWindow")
mainPage.ShowPage("langWindow")
app.SetFocus(langCycle.GetCurrentUI())
})
styleButton.SetSelectedFunc(func() {
mainPage.HidePage("langPage")
mainPage.HidePage("keyMapPage")
mainPage.ShowPage("stylePage")
mainPage.HidePage("langWindow")
mainPage.HidePage("keyMapWindow")
mainPage.ShowPage("styleWindow")
app.SetFocus(styleCycle.GetCurrentUI())
})
keyMapButton.SetSelectedFunc(func() {
mainPage.HidePage("langPage")
mainPage.HidePage("stylePage")
mainPage.ShowPage("keyMapPage")
mainPage.HidePage("langWindow")
mainPage.HidePage("styleWindow")
mainPage.ShowPage("keyMapWindow")
})
}
@ -386,17 +396,17 @@ func mainPageHandler(event *tcell.EventKey) *tcell.EventKey {
return event
}
func translatePageHandler(event *tcell.EventKey) *tcell.EventKey {
func translateWindowHandler(event *tcell.EventKey) *tcell.EventKey {
key := event.Key()
switch key {
case tcell.KeyEsc:
mainPage.ShowPage("langPage")
mainPage.ShowPage("langWindow")
app.SetFocus(langCycle.GetCurrentUI())
case tcell.KeyCtrlJ:
message := srcInput.GetText()
// Only translate when message exist
if len(message) > 0 {
// Only translate when message exist
translation, partOfSpeech, err := translator.Translate(message)
if err != nil {
dstOutput.SetText(err.Error())
@ -447,8 +457,8 @@ func translatePageHandler(event *tcell.EventKey) *tcell.EventKey {
// Play source sound
if translator.SoundLock.Available() {
message := srcInput.GetText()
// Only play when message exist
if len(message) > 0 {
// Only play when message exist
translator.SoundLock.Acquire()
go func() {
err := translator.PlaySound(translator.SrcLang, message)
@ -463,8 +473,8 @@ func translatePageHandler(event *tcell.EventKey) *tcell.EventKey {
// Play destination sound
if translator.SoundLock.Available() {
message := dstOutput.GetText(false)
// Only play when message exist
if len(message) > 0 {
// Only play when message exist
translator.SoundLock.Acquire()
go func() {
err := translator.PlaySound(translator.DstLang, message)
@ -487,19 +497,19 @@ func popOutWindowHandler(event *tcell.EventKey) *tcell.EventKey {
switch ch {
case '1':
mainPage.HidePage("stylePage")
mainPage.HidePage("keyMapPage")
mainPage.ShowPage("langPage")
mainPage.HidePage("styleWindow")
mainPage.HidePage("keyMapWindow")
mainPage.ShowPage("langWindow")
app.SetFocus(langCycle.GetCurrentUI())
case '2':
mainPage.HidePage("langPage")
mainPage.HidePage("keyMapPage")
mainPage.ShowPage("stylePage")
mainPage.HidePage("langWindow")
mainPage.HidePage("keyMapWindow")
mainPage.ShowPage("styleWindow")
app.SetFocus(styleCycle.GetCurrentUI())
case '3':
mainPage.HidePage("langPage")
mainPage.HidePage("stylePage")
mainPage.ShowPage("keyMapPage")
mainPage.HidePage("langWindow")
mainPage.HidePage("styleWindow")
mainPage.ShowPage("keyMapWindow")
}
return event
@ -514,7 +524,7 @@ func langDropDownHandler(key tcell.Key) {
langCycle.Decrease()
app.SetFocus(langCycle.GetCurrentUI())
case tcell.KeyEsc:
mainPage.HidePage("langPage")
mainPage.HidePage("langWindow")
}
}
@ -527,6 +537,6 @@ func styleDropDownHandler(key tcell.Key) {
styleCycle.Decrease()
app.SetFocus(styleCycle.GetCurrentUI())
case tcell.KeyEsc:
mainPage.HidePage("stylePage")
mainPage.HidePage("styleWindow")
}
}