mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-29 14:00:29 -07:00
add orange color
This commit is contained in:
parent
c658c23b41
commit
138c8b85f7
4
color.go
4
color.go
@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
AllTheme = []string{"Gruvbox", "Nord"}
|
AllTheme = []string{"Gruvbox", "Nord"}
|
||||||
Palette = []string{"red", "green", "yellow", "blue", "purple", "cyan"}
|
Palette = []string{"red", "green", "yellow", "blue", "purple", "cyan", "orange"}
|
||||||
Themes = map[string]map[string]tcell.Color{
|
Themes = map[string]map[string]tcell.Color{
|
||||||
"Gruvbox": {
|
"Gruvbox": {
|
||||||
"bg": tcell.NewHexColor(0x282828),
|
"bg": tcell.NewHexColor(0x282828),
|
||||||
@ -18,6 +18,7 @@ var (
|
|||||||
"blue": tcell.NewHexColor(0x83a598),
|
"blue": tcell.NewHexColor(0x83a598),
|
||||||
"purple": tcell.NewHexColor(0xd3869b),
|
"purple": tcell.NewHexColor(0xd3869b),
|
||||||
"cyan": tcell.NewHexColor(0x8ec07c),
|
"cyan": tcell.NewHexColor(0x8ec07c),
|
||||||
|
"orange": tcell.NewHexColor(0xfe8019),
|
||||||
},
|
},
|
||||||
"Nord": {
|
"Nord": {
|
||||||
"bg": tcell.NewHexColor(0x3b4252),
|
"bg": tcell.NewHexColor(0x3b4252),
|
||||||
@ -29,6 +30,7 @@ var (
|
|||||||
"blue": tcell.NewHexColor(0x81a1c1),
|
"blue": tcell.NewHexColor(0x81a1c1),
|
||||||
"purple": tcell.NewHexColor(0xb48ead),
|
"purple": tcell.NewHexColor(0xb48ead),
|
||||||
"cyan": tcell.NewHexColor(0x8fbcbb),
|
"cyan": tcell.NewHexColor(0x8fbcbb),
|
||||||
|
"orange": tcell.NewHexColor(0xd08770),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -27,7 +27,7 @@ func configInit() {
|
|||||||
config.Set("destination.language", "Chinese (Traditional)")
|
config.Set("destination.language", "Chinese (Traditional)")
|
||||||
config.Set("destination.borderColor", "blue")
|
config.Set("destination.borderColor", "blue")
|
||||||
if _, err = os.Stat(defaultConfigPath); os.IsNotExist(err) {
|
if _, err = os.Stat(defaultConfigPath); os.IsNotExist(err) {
|
||||||
os.Mkdir(defaultConfigPath, os.ModePerm)
|
os.MkdirAll(defaultConfigPath, os.ModePerm)
|
||||||
}
|
}
|
||||||
config.SafeWriteConfig()
|
config.SafeWriteConfig()
|
||||||
}
|
}
|
||||||
|
4
main.go
4
main.go
@ -10,8 +10,8 @@ var (
|
|||||||
translator = NewTranslator()
|
translator = NewTranslator()
|
||||||
// UI
|
// UI
|
||||||
app = tview.NewApplication()
|
app = tview.NewApplication()
|
||||||
srcBox = tview.NewTextArea()
|
srcInput = tview.NewTextArea()
|
||||||
dstBox = tview.NewTextView()
|
dstOutput = tview.NewTextView()
|
||||||
srcLangDropDown = tview.NewDropDown()
|
srcLangDropDown = tview.NewDropDown()
|
||||||
dstLangDropDown = tview.NewDropDown()
|
dstLangDropDown = tview.NewDropDown()
|
||||||
langCycle = NewUICycle(srcLangDropDown, dstLangDropDown)
|
langCycle = NewUICycle(srcLangDropDown, dstLangDropDown)
|
||||||
|
64
ui.go
64
ui.go
@ -39,12 +39,12 @@ func (ui *UICycle) GetCurrentUI() tview.Primitive {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateBackgroundColor() {
|
func updateBackgroundColor() {
|
||||||
// box
|
// input/output
|
||||||
srcBox.SetBackgroundColor(style.BackgroundColor())
|
srcInput.SetBackgroundColor(style.BackgroundColor())
|
||||||
srcBox.SetTextStyle(tcell.StyleDefault.
|
srcInput.SetTextStyle(tcell.StyleDefault.
|
||||||
Background(style.BackgroundColor()).
|
Background(style.BackgroundColor()).
|
||||||
Foreground(style.ForegroundColor()))
|
Foreground(style.ForegroundColor()))
|
||||||
dstBox.SetBackgroundColor(style.BackgroundColor())
|
dstOutput.SetBackgroundColor(style.BackgroundColor())
|
||||||
|
|
||||||
// dropdown
|
// dropdown
|
||||||
srcLangDropDown.SetBackgroundColor(style.BackgroundColor())
|
srcLangDropDown.SetBackgroundColor(style.BackgroundColor())
|
||||||
@ -92,10 +92,10 @@ func updateBackgroundColor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateBorderColor() {
|
func updateBorderColor() {
|
||||||
// box
|
// input/output
|
||||||
srcBox.SetBorderColor(style.SrcBorderColor()).
|
srcInput.SetBorderColor(style.SrcBorderColor()).
|
||||||
SetTitleColor(style.SrcBorderColor())
|
SetTitleColor(style.SrcBorderColor())
|
||||||
dstBox.SetBorderColor(style.DstBorderColor()).
|
dstOutput.SetBorderColor(style.DstBorderColor()).
|
||||||
SetTitleColor(style.DstBorderColor())
|
SetTitleColor(style.DstBorderColor())
|
||||||
|
|
||||||
// dropdown
|
// dropdown
|
||||||
@ -110,11 +110,11 @@ func updateBorderColor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateNonConfigColor() {
|
func updateNonConfigColor() {
|
||||||
// box
|
// input/output
|
||||||
srcBox.SetSelectedStyle(tcell.StyleDefault.
|
srcInput.SetSelectedStyle(tcell.StyleDefault.
|
||||||
Background(style.SelectedColor()).
|
Background(style.SelectedColor()).
|
||||||
Foreground(style.ForegroundColor()))
|
Foreground(style.ForegroundColor()))
|
||||||
dstBox.SetTextColor(style.ForegroundColor())
|
dstOutput.SetTextColor(style.ForegroundColor())
|
||||||
|
|
||||||
// dropdown
|
// dropdown
|
||||||
srcLangDropDown.SetFieldBackgroundColor(style.SelectedColor()).
|
srcLangDropDown.SetFieldBackgroundColor(style.SelectedColor()).
|
||||||
@ -163,8 +163,8 @@ func updateAllColor() {
|
|||||||
|
|
||||||
// Update title and option
|
// Update title and option
|
||||||
func updateTitle() {
|
func updateTitle() {
|
||||||
srcBox.SetTitle(translator.srcLang)
|
srcInput.SetTitle(translator.srcLang)
|
||||||
dstBox.SetTitle(translator.dstLang)
|
dstOutput.SetTitle(translator.dstLang)
|
||||||
srcLangDropDown.SetCurrentOption(IndexOf(translator.srcLang, Lang))
|
srcLangDropDown.SetCurrentOption(IndexOf(translator.srcLang, Lang))
|
||||||
srcLangDropDown.SetTitle(translator.srcLang)
|
srcLangDropDown.SetTitle(translator.srcLang)
|
||||||
dstLangDropDown.SetCurrentOption(IndexOf(translator.dstLang, Lang))
|
dstLangDropDown.SetCurrentOption(IndexOf(translator.dstLang, Lang))
|
||||||
@ -183,9 +183,9 @@ func attachButton() *tview.Flex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func uiInit() {
|
func uiInit() {
|
||||||
// box
|
// input/output
|
||||||
srcBox.SetBorder(true)
|
srcInput.SetBorder(true)
|
||||||
dstBox.SetBorder(true)
|
dstOutput.SetBorder(true)
|
||||||
|
|
||||||
// dropdown
|
// dropdown
|
||||||
srcLangDropDown.SetBorder(true)
|
srcLangDropDown.SetBorder(true)
|
||||||
@ -213,8 +213,8 @@ func uiInit() {
|
|||||||
|
|
||||||
// window
|
// window
|
||||||
translateWindow.SetDirection(tview.FlexColumn).
|
translateWindow.SetDirection(tview.FlexColumn).
|
||||||
AddItem(srcBox, 0, 1, true).
|
AddItem(srcInput, 0, 1, true).
|
||||||
AddItem(dstBox, 0, 1, false)
|
AddItem(dstOutput, 0, 1, false)
|
||||||
langWindow.SetDirection(tview.FlexRow).
|
langWindow.SetDirection(tview.FlexRow).
|
||||||
AddItem(nil, 0, 1, false).
|
AddItem(nil, 0, 1, false).
|
||||||
AddItem(tview.NewFlex().SetDirection(tview.FlexColumn).
|
AddItem(tview.NewFlex().SetDirection(tview.FlexColumn).
|
||||||
@ -259,13 +259,13 @@ func uiInit() {
|
|||||||
srcLangDropDown.SetDoneFunc(langDropDownHandler).
|
srcLangDropDown.SetDoneFunc(langDropDownHandler).
|
||||||
SetSelectedFunc(func(text string, index int) {
|
SetSelectedFunc(func(text string, index int) {
|
||||||
translator.srcLang = text
|
translator.srcLang = text
|
||||||
srcBox.SetTitle(text)
|
srcInput.SetTitle(text)
|
||||||
srcLangDropDown.SetTitle(text)
|
srcLangDropDown.SetTitle(text)
|
||||||
})
|
})
|
||||||
dstLangDropDown.SetDoneFunc(langDropDownHandler).
|
dstLangDropDown.SetDoneFunc(langDropDownHandler).
|
||||||
SetSelectedFunc(func(text string, index int) {
|
SetSelectedFunc(func(text string, index int) {
|
||||||
translator.dstLang = text
|
translator.dstLang = text
|
||||||
dstBox.SetTitle(text)
|
dstOutput.SetTitle(text)
|
||||||
dstLangDropDown.SetTitle(text)
|
dstLangDropDown.SetTitle(text)
|
||||||
})
|
})
|
||||||
themeDropDown.SetDoneFunc(styleDropDownHandler).
|
themeDropDown.SetDoneFunc(styleDropDownHandler).
|
||||||
@ -350,41 +350,41 @@ func translatePageHandler(event *tcell.EventKey) *tcell.EventKey {
|
|||||||
mainPage.ShowPage("langPage")
|
mainPage.ShowPage("langPage")
|
||||||
app.SetFocus(langCycle.GetCurrentUI())
|
app.SetFocus(langCycle.GetCurrentUI())
|
||||||
case tcell.KeyCtrlJ:
|
case tcell.KeyCtrlJ:
|
||||||
message := srcBox.GetText()
|
message := srcInput.GetText()
|
||||||
if len(message) > 0 {
|
if len(message) > 0 {
|
||||||
// Only translate when message exist
|
// Only translate when message exist
|
||||||
result, err := translator.Translate(message)
|
result, err := translator.Translate(message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dstBox.SetText(err.Error())
|
dstOutput.SetText(err.Error())
|
||||||
} else {
|
} else {
|
||||||
dstBox.SetText(result)
|
dstOutput.SetText(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case tcell.KeyCtrlQ:
|
case tcell.KeyCtrlQ:
|
||||||
srcBox.SetText("", true)
|
srcInput.SetText("", true)
|
||||||
case tcell.KeyCtrlS:
|
case tcell.KeyCtrlS:
|
||||||
translator.srcLang, translator.dstLang = translator.dstLang, translator.srcLang
|
translator.srcLang, translator.dstLang = translator.dstLang, translator.srcLang
|
||||||
updateTitle()
|
updateTitle()
|
||||||
srcText := srcBox.GetText()
|
srcText := srcInput.GetText()
|
||||||
dstText := dstBox.GetText(false)
|
dstText := dstOutput.GetText(false)
|
||||||
if len(dstText) > 0 {
|
if len(dstText) > 0 {
|
||||||
// GetText of Box contains "\n" if it has words
|
// GetText of Box contains "\n" if it has words
|
||||||
srcBox.SetText(dstText[:len(dstText)-1], true)
|
srcInput.SetText(dstText[:len(dstText)-1], true)
|
||||||
} else {
|
} else {
|
||||||
srcBox.SetText(dstText, true)
|
srcInput.SetText(dstText, true)
|
||||||
}
|
}
|
||||||
dstBox.SetText(srcText)
|
dstOutput.SetText(srcText)
|
||||||
case tcell.KeyCtrlO:
|
case tcell.KeyCtrlO:
|
||||||
// Play source sound
|
// Play source sound
|
||||||
if translator.soundLock.Available() {
|
if translator.soundLock.Available() {
|
||||||
message := srcBox.GetText()
|
message := srcInput.GetText()
|
||||||
if len(message) > 0 {
|
if len(message) > 0 {
|
||||||
// Only play when message exist
|
// Only play when message exist
|
||||||
translator.soundLock.Acquire()
|
translator.soundLock.Acquire()
|
||||||
go func() {
|
go func() {
|
||||||
err := translator.PlaySound(translator.srcLang, message)
|
err := translator.PlaySound(translator.srcLang, message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
srcBox.SetText(err.Error(), true)
|
srcInput.SetText(err.Error(), true)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@ -393,14 +393,14 @@ func translatePageHandler(event *tcell.EventKey) *tcell.EventKey {
|
|||||||
case tcell.KeyCtrlP:
|
case tcell.KeyCtrlP:
|
||||||
// Play destination sound
|
// Play destination sound
|
||||||
if translator.soundLock.Available() {
|
if translator.soundLock.Available() {
|
||||||
message := dstBox.GetText(false)
|
message := dstOutput.GetText(false)
|
||||||
if len(message) > 0 {
|
if len(message) > 0 {
|
||||||
// Only play when message exist
|
// Only play when message exist
|
||||||
translator.soundLock.Acquire()
|
translator.soundLock.Acquire()
|
||||||
go func() {
|
go func() {
|
||||||
err := translator.PlaySound(translator.dstLang, message)
|
err := translator.PlaySound(translator.dstLang, message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dstBox.SetText(err.Error())
|
dstOutput.SetText(err.Error())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user