v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-18 08:40:35 -07:00

Merge branch 'master' into Reverso

This commit is contained in:
eeeXun 2023-02-18 11:37:31 +08:00
commit e43302c948
11 changed files with 267 additions and 274 deletions

View File

@ -4,26 +4,20 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/eeeXun/gtt/internal/color"
"github.com/eeeXun/gtt/internal/translate" "github.com/eeeXun/gtt/internal/translate"
config "github.com/spf13/viper" config "github.com/spf13/viper"
) )
var (
// settings
style = color.NewStyle()
hideBelow bool
)
// Search XDG_CONFIG_HOME or $HOME/.config // Search XDG_CONFIG_HOME or $HOME/.config
func configInit() { func configInit() {
var ( var (
defaultConfigPath string defaultConfigPath string
defaultConfig = map[string]interface{}{ defaultConfig = map[string]interface{}{
"hide_below": false,
"transparent": false, "transparent": false,
"theme": "Gruvbox", "theme": "Gruvbox",
"source.borderColor": "red", "source.border_color": "red",
"destination.borderColor": "blue", "destination.border_color": "blue",
"source.language.apertiumtranslate": "English", "source.language.apertiumtranslate": "English",
"destination.language.apertiumtranslate": "English", "destination.language.apertiumtranslate": "English",
"source.language.argostranslate": "English", "source.language.argostranslate": "English",
@ -32,7 +26,6 @@ func configInit() {
"destination.language.googletranslate": "English", "destination.language.googletranslate": "English",
"source.language.reversotranslate": "English", "source.language.reversotranslate": "English",
"destination.language.reversotranslate": "English", "destination.language.reversotranslate": "English",
"hide_below": false,
"translator": "ArgosTranslate", "translator": "ArgosTranslate",
} }
) )
@ -79,11 +72,11 @@ func configInit() {
config.GetString(fmt.Sprintf("destination.language.%s", name))) config.GetString(fmt.Sprintf("destination.language.%s", name)))
} }
translator = translators[config.GetString("translator")] translator = translators[config.GetString("translator")]
hideBelow = config.GetBool("hide_below") uiStyle.Theme = config.GetString("theme")
style.Theme = config.GetString("theme") uiStyle.HideBelow = config.GetBool("hide_below")
style.Transparent = config.GetBool("transparent") uiStyle.Transparent = config.GetBool("transparent")
style.SetSrcBorderColor(config.GetString("source.borderColor")). uiStyle.SetSrcBorderColor(config.GetString("source.border_color")).
SetDstBorderColor(config.GetString("destination.borderColor")) SetDstBorderColor(config.GetString("destination.border_color"))
// set argument language // set argument language
if len(*srcLangArg) > 0 { if len(*srcLangArg) > 0 {
translator.SetSrcLang(*srcLangArg) translator.SetSrcLang(*srcLangArg)
@ -119,25 +112,25 @@ func updateConfig() {
changed = true changed = true
config.Set("translator", translator.GetEngineName()) config.Set("translator", translator.GetEngineName())
} }
if config.GetBool("hide_below") != hideBelow { if config.GetBool("hide_below") != uiStyle.HideBelow {
changed = true changed = true
config.Set("hide_below", hideBelow) config.Set("hide_below", uiStyle.HideBelow)
} }
if config.GetString("theme") != style.Theme { if config.GetString("theme") != uiStyle.Theme {
changed = true changed = true
config.Set("theme", style.Theme) config.Set("theme", uiStyle.Theme)
} }
if config.GetBool("transparent") != style.Transparent { if config.GetBool("transparent") != uiStyle.Transparent {
changed = true changed = true
config.Set("transparent", style.Transparent) config.Set("transparent", uiStyle.Transparent)
} }
if config.GetString("source.borderColor") != style.SrcBorderStr() { if config.GetString("source.border_color") != uiStyle.SrcBorderStr() {
changed = true changed = true
config.Set("source.borderColor", style.SrcBorderStr()) config.Set("source.border_color", uiStyle.SrcBorderStr())
} }
if config.GetString("destination.borderColor") != style.DstBorderStr() { if config.GetString("destination.border_color") != uiStyle.DstBorderStr() {
changed = true changed = true
config.Set("destination.borderColor", style.DstBorderStr()) config.Set("destination.border_color", uiStyle.DstBorderStr())
} }
if changed { if changed {

View File

@ -1,92 +0,0 @@
package color
import (
"github.com/gdamore/tcell/v2"
)
type windowStyle struct {
borderColor string
}
type Style struct {
src windowStyle
dst windowStyle
backgroundColor string
foregroundColor string
selectedColor string
prefixColor string
labelColor string
pressColor string
highLightColor string
Theme string
Transparent bool
}
func NewStyle() *Style {
return &Style{
backgroundColor: "bg",
foregroundColor: "fg",
selectedColor: "gray",
prefixColor: "cyan",
labelColor: "yellow",
pressColor: "purple",
highLightColor: "orange",
}
}
func (s Style) BackgroundColor() tcell.Color {
if s.Transparent {
return tcell.ColorDefault
}
return themes[s.Theme][s.backgroundColor]
}
func (s Style) ForegroundColor() tcell.Color {
return themes[s.Theme][s.foregroundColor]
}
func (s Style) SelectedColor() tcell.Color {
return themes[s.Theme][s.selectedColor]
}
func (s Style) PrefixColor() tcell.Color {
return themes[s.Theme][s.prefixColor]
}
func (s Style) LabelColor() tcell.Color {
return themes[s.Theme][s.labelColor]
}
func (s Style) PressColor() tcell.Color {
return themes[s.Theme][s.pressColor]
}
func (s Style) HighLightColor() tcell.Color {
return themes[s.Theme][s.highLightColor]
}
func (s Style) SrcBorderColor() tcell.Color {
return themes[s.Theme][s.src.borderColor]
}
func (s Style) DstBorderColor() tcell.Color {
return themes[s.Theme][s.dst.borderColor]
}
func (s Style) SrcBorderStr() string {
return s.src.borderColor
}
func (s Style) DstBorderStr() string {
return s.dst.borderColor
}
func (s *Style) SetSrcBorderColor(color string) *Style {
s.src.borderColor = color
return s
}
func (s *Style) SetDstBorderColor(color string) *Style {
s.dst.borderColor = color
return s
}

View File

@ -1,4 +1,4 @@
package color package style
import ( import (
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"

89
internal/style/style.go Normal file
View File

@ -0,0 +1,89 @@
package style
import (
"github.com/gdamore/tcell/v2"
)
type style struct {
HideBelow bool
Transparent bool
Theme string
srcBorderColor string
dstBorderColor string
backgroundColor string
foregroundColor string
selectedColor string
prefixColor string
labelColor string
pressColor string
highLightColor string
}
func NewStyle() *style {
return &style{
backgroundColor: "bg",
foregroundColor: "fg",
selectedColor: "gray",
prefixColor: "cyan",
labelColor: "yellow",
pressColor: "purple",
highLightColor: "orange",
}
}
func (s style) BackgroundColor() tcell.Color {
if s.Transparent {
return tcell.ColorDefault
}
return themes[s.Theme][s.backgroundColor]
}
func (s style) ForegroundColor() tcell.Color {
return themes[s.Theme][s.foregroundColor]
}
func (s style) SelectedColor() tcell.Color {
return themes[s.Theme][s.selectedColor]
}
func (s style) PrefixColor() tcell.Color {
return themes[s.Theme][s.prefixColor]
}
func (s style) LabelColor() tcell.Color {
return themes[s.Theme][s.labelColor]
}
func (s style) PressColor() tcell.Color {
return themes[s.Theme][s.pressColor]
}
func (s style) HighLightColor() tcell.Color {
return themes[s.Theme][s.highLightColor]
}
func (s style) SrcBorderColor() tcell.Color {
return themes[s.Theme][s.srcBorderColor]
}
func (s style) DstBorderColor() tcell.Color {
return themes[s.Theme][s.dstBorderColor]
}
func (s style) SrcBorderStr() string {
return s.srcBorderColor
}
func (s style) DstBorderStr() string {
return s.dstBorderColor
}
func (s *style) SetSrcBorderColor(color string) *style {
s.srcBorderColor = color
return s
}
func (s *style) SetDstBorderColor(color string) *style {
s.dstBorderColor = color
return s
}

View File

@ -51,7 +51,7 @@ func (t *ApertiumTranslate) SwapLang() {
} }
func (t *ApertiumTranslate) Translate(message string) (translation, definition, partOfSpeech string, err error) { func (t *ApertiumTranslate) Translate(message string) (translation, definition, partOfSpeech string, err error) {
var data interface{} var data map[string]interface{}
urlStr := fmt.Sprintf( urlStr := fmt.Sprintf(
textURL, textURL,
@ -71,22 +71,23 @@ func (t *ApertiumTranslate) Translate(message string) (translation, definition,
return "", "", "", err return "", "", "", err
} }
if len(data.(map[string]interface{})) > 0 { if len(data) <= 0 {
switch res.StatusCode { return "", "", "", errors.New("Translation not found")
case 200:
translation += fmt.Sprintf("%v",
data.(map[string]interface{})["responseData"].(map[string]interface{})["translatedText"])
default:
return "", "", "", errors.New(
fmt.Sprintf("%s does not support translate from %s to %s.\nSee available pair on %s",
t.EngineName,
t.srcLang,
t.dstLang,
"https://www.apertium.org/",
))
}
return translation, definition, partOfSpeech, nil
} }
return "", "", "", errors.New("Translation not found")
switch res.StatusCode {
case 200:
translation += fmt.Sprintf("%v",
data["responseData"].(map[string]interface{})["translatedText"])
default:
return "", "", "", errors.New(
fmt.Sprintf("%s does not support translate from %s to %s.\nSee available pair on %s",
t.EngineName,
t.srcLang,
t.dstLang,
"https://www.apertium.org/",
))
}
return translation, definition, partOfSpeech, nil
} }

View File

@ -51,7 +51,7 @@ func (t *ArgosTranslate) SwapLang() {
} }
func (t *ArgosTranslate) Translate(message string) (translation, definition, partOfSpeech string, err error) { func (t *ArgosTranslate) Translate(message string) (translation, definition, partOfSpeech string, err error) {
var data interface{} var data map[string]interface{}
res, err := http.PostForm(textURL, res, err := http.PostForm(textURL,
url.Values{ url.Values{
@ -70,11 +70,11 @@ func (t *ArgosTranslate) Translate(message string) (translation, definition, par
return "", "", "", err return "", "", "", err
} }
if len(data.(map[string]interface{})) > 0 { if len(data) <= 0 {
translation += fmt.Sprintf("%v", return "", "", "", errors.New("Translation not found")
data.(map[string]interface{})["translatedText"])
return translation, definition, partOfSpeech, nil
} }
return "", "", "", errors.New("Translation not found")
translation += fmt.Sprintf("%v", data["translatedText"])
return translation, definition, partOfSpeech, nil
} }

View File

@ -71,58 +71,57 @@ func (t *GoogleTranslate) Translate(message string) (translation, definition, pa
return "", "", "", err return "", "", "", err
} }
if len(data) > 0 { if len(data) <= 0 {
// translation = data[0] return "", "", "", errors.New("Translation not found")
for _, lines := range data[0].([]interface{}) {
translatedLine := lines.([]interface{})[0]
translation += fmt.Sprintf("%v", translatedLine)
}
// part of speech = data[1]
if data[1] != nil {
for _, parts := range data[1].([]interface{}) {
// part of speech
part := parts.([]interface{})[0]
partOfSpeech += fmt.Sprintf("[%v]\n", part)
for _, words := range parts.([]interface{})[2].([]interface{}) {
// dst lang
dstWord := words.([]interface{})[0]
partOfSpeech += fmt.Sprintf("\t%v:", dstWord)
// src lang
firstWord := true
for _, word := range words.([]interface{})[1].([]interface{}) {
if firstWord {
partOfSpeech += fmt.Sprintf(" %v", word)
firstWord = false
} else {
partOfSpeech += fmt.Sprintf(", %v", word)
}
}
partOfSpeech += "\n"
}
}
}
// definition = data[12]
if len(data) >= 13 && data[12] != nil {
for _, parts := range data[12].([]interface{}) {
// part of speech
part := parts.([]interface{})[0]
definition += fmt.Sprintf("[%v]\n", part)
for _, sentences := range parts.([]interface{})[1].([]interface{}) {
// definition
def := sentences.([]interface{})[0]
definition += fmt.Sprintf("\t- %v\n", def)
// example sentence
if len(sentences.([]interface{})) >= 3 && sentences.([]interface{})[2] != nil {
example := sentences.([]interface{})[2]
definition += fmt.Sprintf("\t\t\"%v\"\n", example)
}
}
}
}
return translation, definition, partOfSpeech, nil
} }
return "", "", "", errors.New("Translation not found") // translation = data[0]
for _, lines := range data[0].([]interface{}) {
translatedLine := lines.([]interface{})[0]
translation += fmt.Sprintf("%v", translatedLine)
}
// part of speech = data[1]
if data[1] != nil {
for _, parts := range data[1].([]interface{}) {
// part of speech
part := parts.([]interface{})[0]
partOfSpeech += fmt.Sprintf("[%v]\n", part)
for _, words := range parts.([]interface{})[2].([]interface{}) {
// dst lang
dstWord := words.([]interface{})[0]
partOfSpeech += fmt.Sprintf("\t%v:", dstWord)
// src lang
firstWord := true
for _, word := range words.([]interface{})[1].([]interface{}) {
if firstWord {
partOfSpeech += fmt.Sprintf(" %v", word)
firstWord = false
} else {
partOfSpeech += fmt.Sprintf(", %v", word)
}
}
partOfSpeech += "\n"
}
}
}
// definition = data[12]
if len(data) >= 13 && data[12] != nil {
for _, parts := range data[12].([]interface{}) {
// part of speech
part := parts.([]interface{})[0]
definition += fmt.Sprintf("[%v]\n", part)
for _, sentences := range parts.([]interface{})[1].([]interface{}) {
// definition
def := sentences.([]interface{})[0]
definition += fmt.Sprintf("\t- %v\n", def)
// example sentence
if len(sentences.([]interface{})) >= 3 && sentences.([]interface{})[2] != nil {
example := sentences.([]interface{})[2]
definition += fmt.Sprintf("\t\t\"%v\"\n", example)
}
}
}
}
return translation, definition, partOfSpeech, nil
} }

View File

@ -54,9 +54,8 @@ func (t *GoogleTranslate) PlayTTS(lang, message string) error {
if t.SoundLock.Stop { if t.SoundLock.Stop {
t.SoundLock.Release() t.SoundLock.Release()
return nil return nil
} else {
time.Sleep(time.Millisecond)
} }
time.Sleep(time.Millisecond)
} }
if err = player.Close(); err != nil { if err = player.Close(); err != nil {
t.SoundLock.Release() t.SoundLock.Release()

View File

@ -82,10 +82,11 @@ func (t *ReversoTranslate) Translate(message string) (translation, definition, p
return "", "", "", err return "", "", "", err
} }
if len(data) > 0 { if len(data) <= 0 {
translation += fmt.Sprintf("%v", data) return "", "", "", errors.New("Translation not found")
return translation, definition, partOfSpeech, nil
} }
return "", "", "", errors.New("Translation not found")
translation += fmt.Sprintf("%v", data["translation"].([]interface{})[0])
return translation, definition, partOfSpeech, nil
} }

View File

@ -3,6 +3,7 @@ package main
import ( import (
"flag" "flag"
"github.com/eeeXun/gtt/internal/style"
"github.com/eeeXun/gtt/internal/translate" "github.com/eeeXun/gtt/internal/translate"
"github.com/eeeXun/gtt/internal/ui" "github.com/eeeXun/gtt/internal/ui"
"github.com/rivo/tview" "github.com/rivo/tview"
@ -17,6 +18,8 @@ var (
// Translate // Translate
translator translate.Translator translator translate.Translator
translators = make(map[string]translate.Translator, len(translate.AllTranslator)) translators = make(map[string]translate.Translator, len(translate.AllTranslator))
// UI style
uiStyle = style.NewStyle()
// UI // UI
app = tview.NewApplication() app = tview.NewApplication()
srcInput = tview.NewTextArea() srcInput = tview.NewTextArea()

144
ui.go
View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"github.com/eeeXun/gtt/internal/color" "github.com/eeeXun/gtt/internal/style"
"github.com/eeeXun/gtt/internal/translate" "github.com/eeeXun/gtt/internal/translate"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
"github.com/rivo/tview" "github.com/rivo/tview"
@ -54,7 +54,7 @@ type Item struct {
func updateTranslateWindow() { func updateTranslateWindow() {
translateWindow.Clear() translateWindow.Clear()
if hideBelow { if uiStyle.HideBelow {
translateWindow.AddItem(translateAboveWidget, 0, 1, true) translateWindow.AddItem(translateAboveWidget, 0, 1, true)
} else { } else {
translateWindow.SetDirection(tview.FlexRow). translateWindow.SetDirection(tview.FlexRow).
@ -66,18 +66,18 @@ func updateTranslateWindow() {
func updateBackgroundColor() { func updateBackgroundColor() {
// input/output // input/output
srcInput.SetTextStyle(tcell.StyleDefault. srcInput.SetTextStyle(tcell.StyleDefault.
Background(style.BackgroundColor()). Background(uiStyle.BackgroundColor()).
Foreground(style.ForegroundColor())). Foreground(uiStyle.ForegroundColor())).
SetBackgroundColor(style.BackgroundColor()) SetBackgroundColor(uiStyle.BackgroundColor())
dstOutput.SetBackgroundColor(style.BackgroundColor()) dstOutput.SetBackgroundColor(uiStyle.BackgroundColor())
defOutput.SetTextStyle(tcell.StyleDefault. defOutput.SetTextStyle(tcell.StyleDefault.
Background(style.BackgroundColor()). Background(uiStyle.BackgroundColor()).
Foreground(style.ForegroundColor())). Foreground(uiStyle.ForegroundColor())).
SetBackgroundColor(style.BackgroundColor()) SetBackgroundColor(uiStyle.BackgroundColor())
posOutput.SetTextStyle(tcell.StyleDefault. posOutput.SetTextStyle(tcell.StyleDefault.
Background(style.BackgroundColor()). Background(uiStyle.BackgroundColor()).
Foreground(style.ForegroundColor())). Foreground(uiStyle.ForegroundColor())).
SetBackgroundColor(style.BackgroundColor()) SetBackgroundColor(uiStyle.BackgroundColor())
// dropdown // dropdown
for _, dropdown := range []*tview.DropDown{ for _, dropdown := range []*tview.DropDown{
@ -90,58 +90,58 @@ func updateBackgroundColor() {
srcBorderDropDown, srcBorderDropDown,
dstBorderDropDown} { dstBorderDropDown} {
dropdown.SetListStyles(tcell.StyleDefault. dropdown.SetListStyles(tcell.StyleDefault.
Background(style.BackgroundColor()). Background(uiStyle.BackgroundColor()).
Foreground(style.ForegroundColor()), Foreground(uiStyle.ForegroundColor()),
tcell.StyleDefault. tcell.StyleDefault.
Background(style.SelectedColor()). Background(uiStyle.SelectedColor()).
Foreground(style.PrefixColor())). Foreground(uiStyle.PrefixColor())).
SetBackgroundColor(style.BackgroundColor()) SetBackgroundColor(uiStyle.BackgroundColor())
} }
// key map // key map
keyMapMenu.SetBackgroundColor(style.BackgroundColor()) keyMapMenu.SetBackgroundColor(uiStyle.BackgroundColor())
} }
func updateBorderColor() { func updateBorderColor() {
// input/output // input/output
srcInput.SetBorderColor(style.SrcBorderColor()). srcInput.SetBorderColor(uiStyle.SrcBorderColor()).
SetTitleColor(style.SrcBorderColor()) SetTitleColor(uiStyle.SrcBorderColor())
dstOutput.SetBorderColor(style.DstBorderColor()). dstOutput.SetBorderColor(uiStyle.DstBorderColor()).
SetTitleColor(style.DstBorderColor()) SetTitleColor(uiStyle.DstBorderColor())
defOutput.SetBorderColor(style.SrcBorderColor()). defOutput.SetBorderColor(uiStyle.SrcBorderColor()).
SetTitleColor(style.SrcBorderColor()) SetTitleColor(uiStyle.SrcBorderColor())
posOutput.SetBorderColor(style.DstBorderColor()). posOutput.SetBorderColor(uiStyle.DstBorderColor()).
SetTitleColor(style.DstBorderColor()) SetTitleColor(uiStyle.DstBorderColor())
// dropdown // dropdown
for _, srcDropDown := range []*tview.DropDown{srcLangDropDown, srcBorderDropDown} { for _, srcDropDown := range []*tview.DropDown{srcLangDropDown, srcBorderDropDown} {
srcDropDown.SetBorderColor(style.SrcBorderColor()). srcDropDown.SetBorderColor(uiStyle.SrcBorderColor()).
SetTitleColor(style.SrcBorderColor()) SetTitleColor(uiStyle.SrcBorderColor())
} }
for _, dstDropDown := range []*tview.DropDown{dstLangDropDown, dstBorderDropDown} { for _, dstDropDown := range []*tview.DropDown{dstLangDropDown, dstBorderDropDown} {
dstDropDown.SetBorderColor(style.DstBorderColor()). dstDropDown.SetBorderColor(uiStyle.DstBorderColor()).
SetTitleColor(style.DstBorderColor()) SetTitleColor(uiStyle.DstBorderColor())
} }
} }
func updateNonConfigColor() { func updateNonConfigColor() {
// input/output // input/output
srcInput.SetSelectedStyle(tcell.StyleDefault. srcInput.SetSelectedStyle(tcell.StyleDefault.
Background(style.SelectedColor()). Background(uiStyle.SelectedColor()).
Foreground(style.ForegroundColor())) Foreground(uiStyle.ForegroundColor()))
dstOutput.SetTextColor(style.ForegroundColor()) dstOutput.SetTextColor(uiStyle.ForegroundColor())
defOutput.SetSelectedStyle(tcell.StyleDefault. defOutput.SetSelectedStyle(tcell.StyleDefault.
Background(style.SelectedColor()). Background(uiStyle.SelectedColor()).
Foreground(style.ForegroundColor())) Foreground(uiStyle.ForegroundColor()))
posOutput.SetSelectedStyle(tcell.StyleDefault. posOutput.SetSelectedStyle(tcell.StyleDefault.
Background(style.SelectedColor()). Background(uiStyle.SelectedColor()).
Foreground(style.ForegroundColor())) Foreground(uiStyle.ForegroundColor()))
// dropdown // dropdown
for _, noLabelDropDown := range []*tview.DropDown{srcLangDropDown, dstLangDropDown} { for _, noLabelDropDown := range []*tview.DropDown{srcLangDropDown, dstLangDropDown} {
noLabelDropDown.SetFieldBackgroundColor(style.SelectedColor()). noLabelDropDown.SetFieldBackgroundColor(uiStyle.SelectedColor()).
SetFieldTextColor(style.ForegroundColor()). SetFieldTextColor(uiStyle.ForegroundColor()).
SetPrefixTextColor(style.PrefixColor()) SetPrefixTextColor(uiStyle.PrefixColor())
} }
for _, labelDropDown := range []*tview.DropDown{ for _, labelDropDown := range []*tview.DropDown{
translatorDropDown, translatorDropDown,
@ -150,27 +150,27 @@ func updateNonConfigColor() {
hideBelowDropDown, hideBelowDropDown,
srcBorderDropDown, srcBorderDropDown,
dstBorderDropDown} { dstBorderDropDown} {
labelDropDown.SetLabelColor(style.LabelColor()). labelDropDown.SetLabelColor(uiStyle.LabelColor()).
SetFieldBackgroundColor(style.SelectedColor()). SetFieldBackgroundColor(uiStyle.SelectedColor()).
SetFieldTextColor(style.ForegroundColor()). SetFieldTextColor(uiStyle.ForegroundColor()).
SetPrefixTextColor(style.PrefixColor()) SetPrefixTextColor(uiStyle.PrefixColor())
} }
// button // button
for _, button := range []*tview.Button{langButton, styleButton, keyMapButton} { for _, button := range []*tview.Button{langButton, styleButton, keyMapButton} {
button.SetLabelColor(style.ForegroundColor()). button.SetLabelColor(uiStyle.ForegroundColor()).
SetBackgroundColorActivated(style.PressColor()). SetBackgroundColorActivated(uiStyle.PressColor()).
SetLabelColorActivated(style.ForegroundColor()). SetLabelColorActivated(uiStyle.ForegroundColor()).
SetBackgroundColor(style.SelectedColor()) SetBackgroundColor(uiStyle.SelectedColor())
} }
// key map // key map
keyMapMenu.SetTextColor(style.ForegroundColor()). keyMapMenu.SetTextColor(uiStyle.ForegroundColor()).
SetText(fmt.Sprintf(keyMapText, SetText(fmt.Sprintf(keyMapText,
fmt.Sprintf("%.6x", fmt.Sprintf("%.6x",
style.HighLightColor().TrueColor().Hex()))). uiStyle.HighLightColor().TrueColor().Hex()))).
SetBorderColor(style.HighLightColor()). SetBorderColor(uiStyle.HighLightColor()).
SetTitleColor(style.HighLightColor()) SetTitleColor(uiStyle.HighLightColor())
} }
func updateAllColor() { func updateAllColor() {
@ -247,37 +247,37 @@ func uiInit() {
srcLangDropDown.SetBorder(true) srcLangDropDown.SetBorder(true)
dstLangDropDown.SetBorder(true) dstLangDropDown.SetBorder(true)
themeDropDown.SetLabel("Theme: "). themeDropDown.SetLabel("Theme: ").
SetOptions(color.AllTheme, nil). SetOptions(style.AllTheme, nil).
SetCurrentOption(IndexOf(style.Theme, color.AllTheme)) SetCurrentOption(IndexOf(uiStyle.Theme, style.AllTheme))
hideBelowDropDown.SetLabel("Hide below: "). hideBelowDropDown.SetLabel("Hide below: ").
SetOptions([]string{"true", "false"}, nil). SetOptions([]string{"true", "false"}, nil).
SetCurrentOption( SetCurrentOption(
IndexOf(strconv.FormatBool(hideBelow), IndexOf(strconv.FormatBool(uiStyle.HideBelow),
[]string{"true", "false"})) []string{"true", "false"}))
transparentDropDown.SetLabel("Transparent: "). transparentDropDown.SetLabel("Transparent: ").
SetOptions([]string{"true", "false"}, nil). SetOptions([]string{"true", "false"}, nil).
SetCurrentOption( SetCurrentOption(
IndexOf(strconv.FormatBool(style.Transparent), IndexOf(strconv.FormatBool(uiStyle.Transparent),
[]string{"true", "false"})) []string{"true", "false"}))
srcBorderDropDown.SetLabel("Border Color: "). srcBorderDropDown.SetLabel("Border Color: ").
SetOptions(color.Palette, nil). SetOptions(style.Palette, nil).
SetCurrentOption( SetCurrentOption(
IndexOf(style.SrcBorderStr(), IndexOf(uiStyle.SrcBorderStr(),
color.Palette)). style.Palette)).
SetBorder(true). SetBorder(true).
SetTitle("Source") SetTitle("Source")
dstBorderDropDown.SetLabel("Border Color: "). dstBorderDropDown.SetLabel("Border Color: ").
SetOptions(color.Palette, nil). SetOptions(style.Palette, nil).
SetCurrentOption( SetCurrentOption(
IndexOf(style.DstBorderStr(), IndexOf(uiStyle.DstBorderStr(),
color.Palette)). style.Palette)).
SetBorder(true). SetBorder(true).
SetTitle("Destination") SetTitle("Destination")
// key map // key map
keyMapMenu.SetDynamicColors(true). keyMapMenu.SetDynamicColors(true).
SetText(fmt.Sprintf(keyMapText, SetText(fmt.Sprintf(keyMapText,
fmt.Sprintf("%.6x", style.HighLightColor().TrueColor().Hex()))). fmt.Sprintf("%.6x", uiStyle.HighLightColor().TrueColor().Hex()))).
SetBorder(true). SetBorder(true).
SetTitle("Key Map") SetTitle("Key Map")
@ -372,27 +372,27 @@ func uiInit() {
dstLangDropDown.SetDoneFunc(langDropDownHandler) dstLangDropDown.SetDoneFunc(langDropDownHandler)
themeDropDown.SetDoneFunc(styleDropDownHandler). themeDropDown.SetDoneFunc(styleDropDownHandler).
SetSelectedFunc(func(text string, index int) { SetSelectedFunc(func(text string, index int) {
style.Theme = text uiStyle.Theme = text
updateAllColor() updateAllColor()
}) })
transparentDropDown.SetDoneFunc(styleDropDownHandler). transparentDropDown.SetDoneFunc(styleDropDownHandler).
SetSelectedFunc(func(text string, index int) { SetSelectedFunc(func(text string, index int) {
style.Transparent, _ = strconv.ParseBool(text) uiStyle.Transparent, _ = strconv.ParseBool(text)
updateBackgroundColor() updateBackgroundColor()
}) })
hideBelowDropDown.SetDoneFunc(styleDropDownHandler). hideBelowDropDown.SetDoneFunc(styleDropDownHandler).
SetSelectedFunc(func(text string, index int) { SetSelectedFunc(func(text string, index int) {
hideBelow, _ = strconv.ParseBool(text) uiStyle.HideBelow, _ = strconv.ParseBool(text)
updateTranslateWindow() updateTranslateWindow()
}) })
srcBorderDropDown.SetDoneFunc(styleDropDownHandler). srcBorderDropDown.SetDoneFunc(styleDropDownHandler).
SetSelectedFunc(func(text string, index int) { SetSelectedFunc(func(text string, index int) {
style.SetSrcBorderColor(text) uiStyle.SetSrcBorderColor(text)
updateBorderColor() updateBorderColor()
}) })
dstBorderDropDown.SetDoneFunc(styleDropDownHandler). dstBorderDropDown.SetDoneFunc(styleDropDownHandler).
SetSelectedFunc(func(text string, index int) { SetSelectedFunc(func(text string, index int) {
style.SetDstBorderColor(text) uiStyle.SetDstBorderColor(text)
updateBorderColor() updateBorderColor()
}) })
keyMapMenu.SetDoneFunc(func(key tcell.Key) { keyMapMenu.SetDoneFunc(func(key tcell.Key) {
@ -426,16 +426,16 @@ func mainPageHandler(event *tcell.EventKey) *tcell.EventKey {
switch key { switch key {
case tcell.KeyCtrlT: case tcell.KeyCtrlT:
// Toggle transparent // Toggle transparent
style.Transparent = !style.Transparent uiStyle.Transparent = !uiStyle.Transparent
updateBackgroundColor() updateBackgroundColor()
transparentDropDown.SetCurrentOption( transparentDropDown.SetCurrentOption(
IndexOf(strconv.FormatBool(style.Transparent), IndexOf(strconv.FormatBool(uiStyle.Transparent),
[]string{"true", "false"})) []string{"true", "false"}))
case tcell.KeyCtrlBackslash: case tcell.KeyCtrlBackslash:
hideBelow = !hideBelow uiStyle.HideBelow = !uiStyle.HideBelow
updateTranslateWindow() updateTranslateWindow()
hideBelowDropDown.SetCurrentOption( hideBelowDropDown.SetCurrentOption(
IndexOf(strconv.FormatBool(hideBelow), IndexOf(strconv.FormatBool(uiStyle.HideBelow),
[]string{"true", "false"})) []string{"true", "false"}))
} }