v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-19 09:10:42 -07:00

add keyMapText

This commit is contained in:
eeeXun 2022-10-24 21:55:27 +08:00
parent 138c8b85f7
commit e09e846077
3 changed files with 94 additions and 24 deletions

View File

@ -5,9 +5,9 @@ import (
) )
var ( var (
AllTheme = []string{"Gruvbox", "Nord"} AllTheme = []string{"Gruvbox", "Nord"}
Palette = []string{"red", "green", "yellow", "blue", "purple", "cyan", "orange"} 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),
"fg": tcell.NewHexColor(0xebdbb2), "fg": tcell.NewHexColor(0xebdbb2),
@ -48,6 +48,7 @@ type Style struct {
prefixColor string prefixColor string
labelColor string labelColor string
pressColor string pressColor string
highLightColor string
Theme string Theme string
Transparent bool Transparent bool
} }
@ -60,6 +61,7 @@ func NewStyle() *Style {
prefixColor: "cyan", prefixColor: "cyan",
labelColor: "yellow", labelColor: "yellow",
pressColor: "purple", pressColor: "purple",
highLightColor: "orange",
} }
} }
@ -90,6 +92,10 @@ func (s Style) PressColor() tcell.Color {
return Themes[s.Theme][s.pressColor] return Themes[s.Theme][s.pressColor]
} }
func (s Style) HighLightColor() tcell.Color {
return Themes[s.Theme][s.highLightColor]
}
func (s Style) SrcBorderColor() tcell.Color { func (s Style) SrcBorderColor() tcell.Color {
return Themes[s.Theme][s.src.borderColor] return Themes[s.Theme][s.src.borderColor]
} }

View File

@ -20,12 +20,14 @@ var (
srcBorderDropDown = tview.NewDropDown() srcBorderDropDown = tview.NewDropDown()
dstBorderDropDown = tview.NewDropDown() dstBorderDropDown = tview.NewDropDown()
styleCycle = NewUICycle(themeDropDown, transparentDropDown, srcBorderDropDown, dstBorderDropDown) styleCycle = NewUICycle(themeDropDown, transparentDropDown, srcBorderDropDown, dstBorderDropDown)
keyMapMenu = tview.NewTextView()
langButton = tview.NewButton("(1)Language") langButton = tview.NewButton("(1)Language")
styleButton = tview.NewButton("(2)Style") styleButton = tview.NewButton("(2)Style")
menuButton = tview.NewButton("(3)KeyMap") keyMapButton = tview.NewButton("(3)KeyMap")
translateWindow = tview.NewFlex() translateWindow = tview.NewFlex()
langWindow = tview.NewFlex() langWindow = tview.NewFlex()
styleWindow = tview.NewFlex() styleWindow = tview.NewFlex()
keyMapWindow = tview.NewFlex()
mainPage = tview.NewPages() mainPage = tview.NewPages()
// settings // settings
config = viper.New() config = viper.New()
@ -40,6 +42,7 @@ func main() {
mainPage.AddPage("translatePage", translateWindow, true, true) mainPage.AddPage("translatePage", translateWindow, true, true)
mainPage.AddPage("langPage", langWindow, true, false) mainPage.AddPage("langPage", langWindow, true, false)
mainPage.AddPage("stylePage", styleWindow, true, false) mainPage.AddPage("stylePage", styleWindow, true, false)
mainPage.AddPage("keyMapPage", keyMapWindow, true, false)
if err := app.SetRoot(mainPage, true). if err := app.SetRoot(mainPage, true).
EnableMouse(true).Run(); err != nil { EnableMouse(true).Run(); err != nil {

101
ui.go
View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
"github.com/rivo/tview" "github.com/rivo/tview"
"strconv" "strconv"
@ -38,6 +39,31 @@ func (ui *UICycle) GetCurrentUI() tview.Primitive {
return ui.widget[ui.index] return ui.widget[ui.index]
} }
const (
keyMapText string = `[#%[1]s]<C-c>[-]
Exit program.
[#%[1]s]<Esc>[-]
Toggle pop out window.
[#%[1]s]<C-j>[-]
Translate from left window to right window.
[#%[1]s]<C-s>[-]
Swap language.
[#%[1]s]<C-q>[-]
Clear all text in left window.
[#%[1]s]<C-o>[-]
Play sound on left window.
[#%[1]s]<C-p>[-]
Play sound on right window.
[#%[1]s]<C-x>[-]
Stop play sound.
[#%[1]s]<C-t>[-]
Toggle transparent.
[#%[1]s]<Tab>, <S-Tab>[-]
Cycle through the pop out widget.
[#%[1]s]<1>, <2>, <3>[-]
Switch pop out window.`
)
func updateBackgroundColor() { func updateBackgroundColor() {
// input/output // input/output
srcInput.SetBackgroundColor(style.BackgroundColor()) srcInput.SetBackgroundColor(style.BackgroundColor())
@ -89,6 +115,9 @@ func updateBackgroundColor() {
tcell.StyleDefault. tcell.StyleDefault.
Background(style.SelectedColor()). Background(style.SelectedColor()).
Foreground(style.PrefixColor())) Foreground(style.PrefixColor()))
// key map
keyMapMenu.SetBackgroundColor(style.BackgroundColor())
} }
func updateBorderColor() { func updateBorderColor() {
@ -149,10 +178,15 @@ func updateNonConfigColor() {
SetBackgroundColorActivated(style.PressColor()). SetBackgroundColorActivated(style.PressColor()).
SetLabelColorActivated(style.ForegroundColor()). SetLabelColorActivated(style.ForegroundColor()).
SetBackgroundColor(style.SelectedColor()) SetBackgroundColor(style.SelectedColor())
menuButton.SetLabelColor(style.ForegroundColor()). keyMapButton.SetLabelColor(style.ForegroundColor()).
SetBackgroundColorActivated(style.PressColor()). SetBackgroundColorActivated(style.PressColor()).
SetLabelColorActivated(style.ForegroundColor()). SetLabelColorActivated(style.ForegroundColor()).
SetBackgroundColor(style.SelectedColor()) SetBackgroundColor(style.SelectedColor())
// key map
keyMapMenu.SetTextColor(style.ForegroundColor()).
SetBorderColor(style.HighLightColor()).
SetTitleColor(style.HighLightColor())
} }
func updateAllColor() { func updateAllColor() {
@ -178,7 +212,7 @@ func attachButton() *tview.Flex {
AddItem(nil, 18, 1, false). AddItem(nil, 18, 1, false).
AddItem(styleButton, 8, 1, true). AddItem(styleButton, 8, 1, true).
AddItem(nil, 18, 1, false). AddItem(nil, 18, 1, false).
AddItem(menuButton, 9, 1, true). AddItem(keyMapButton, 9, 1, true).
AddItem(nil, 0, 1, false) AddItem(nil, 0, 1, false)
} }
@ -211,6 +245,13 @@ func uiInit() {
dstBorderDropDown.SetBorder(true). dstBorderDropDown.SetBorder(true).
SetTitle("Destination") SetTitle("Destination")
// key map
keyMapMenu.SetBorder(true).
SetTitle("Key Map")
keyMapMenu.SetDynamicColors(true).
SetText(fmt.Sprintf(keyMapText,
fmt.Sprintf("%.6x", style.HighLightColor().TrueColor().Hex())))
// window // window
translateWindow.SetDirection(tview.FlexColumn). translateWindow.SetDirection(tview.FlexColumn).
AddItem(srcInput, 0, 1, true). AddItem(srcInput, 0, 1, true).
@ -247,14 +288,24 @@ func uiInit() {
20, 1, true). 20, 1, true).
AddItem(attachButton(), 1, 1, false). AddItem(attachButton(), 1, 1, false).
AddItem(nil, 0, 1, false) AddItem(nil, 0, 1, false)
keyMapWindow.SetDirection(tview.FlexRow).
AddItem(nil, 0, 1, false).
AddItem(tview.NewFlex().SetDirection(tview.FlexColumn).
AddItem(nil, 0, 1, false).
AddItem(keyMapMenu, 64, 1, true).
AddItem(nil, 0, 1, false),
20, 1, true).
AddItem(attachButton(), 1, 1, false).
AddItem(nil, 0, 1, false)
updateAllColor() updateAllColor()
updateTitle() updateTitle()
// handler // handler
mainPage.SetInputCapture(mainpageHandler) mainPage.SetInputCapture(mainPageHandler)
langWindow.SetInputCapture(langWindowHandler) langWindow.SetInputCapture(popOutWindowHandler)
styleWindow.SetInputCapture(styleWindowHandler) styleWindow.SetInputCapture(popOutWindowHandler)
keyMapWindow.SetInputCapture(popOutWindowHandler)
translateWindow.SetInputCapture(translatePageHandler) translateWindow.SetInputCapture(translatePageHandler)
srcLangDropDown.SetDoneFunc(langDropDownHandler). srcLangDropDown.SetDoneFunc(langDropDownHandler).
SetSelectedFunc(func(text string, index int) { SetSelectedFunc(func(text string, index int) {
@ -288,19 +339,32 @@ func uiInit() {
style.SetDstBorderColor(text) style.SetDstBorderColor(text)
updateBorderColor() updateBorderColor()
}) })
keyMapMenu.SetDoneFunc(func(key tcell.Key) {
switch key {
case tcell.KeyEsc:
mainPage.HidePage("keyMapPage")
}
})
langButton.SetSelectedFunc(func() { langButton.SetSelectedFunc(func() {
mainPage.HidePage("stylePage") mainPage.HidePage("stylePage")
mainPage.HidePage("keyMapPage")
mainPage.ShowPage("langPage") mainPage.ShowPage("langPage")
app.SetFocus(langCycle.GetCurrentUI()) app.SetFocus(langCycle.GetCurrentUI())
}) })
styleButton.SetSelectedFunc(func() { styleButton.SetSelectedFunc(func() {
mainPage.HidePage("langPage") mainPage.HidePage("langPage")
mainPage.HidePage("keyMapPage")
mainPage.ShowPage("stylePage") mainPage.ShowPage("stylePage")
app.SetFocus(styleCycle.GetCurrentUI()) app.SetFocus(styleCycle.GetCurrentUI())
}) })
keyMapButton.SetSelectedFunc(func() {
mainPage.HidePage("langPage")
mainPage.HidePage("stylePage")
mainPage.ShowPage("keyMapPage")
})
} }
func mainpageHandler(event *tcell.EventKey) *tcell.EventKey { func mainPageHandler(event *tcell.EventKey) *tcell.EventKey {
key := event.Key() key := event.Key()
switch key { switch key {
@ -316,27 +380,24 @@ func mainpageHandler(event *tcell.EventKey) *tcell.EventKey {
return event return event
} }
func langWindowHandler(event *tcell.EventKey) *tcell.EventKey { func popOutWindowHandler(event *tcell.EventKey) *tcell.EventKey {
ch := event.Rune()
switch ch {
case '2':
mainPage.HidePage("langPage")
mainPage.ShowPage("stylePage")
app.SetFocus(styleCycle.GetCurrentUI())
}
return event
}
func styleWindowHandler(event *tcell.EventKey) *tcell.EventKey {
ch := event.Rune() ch := event.Rune()
switch ch { switch ch {
case '1': case '1':
mainPage.HidePage("stylePage") mainPage.HidePage("stylePage")
mainPage.HidePage("keyMapPage")
mainPage.ShowPage("langPage") mainPage.ShowPage("langPage")
app.SetFocus(langCycle.GetCurrentUI()) app.SetFocus(langCycle.GetCurrentUI())
case '2':
mainPage.HidePage("langPage")
mainPage.HidePage("keyMapPage")
mainPage.ShowPage("stylePage")
app.SetFocus(styleCycle.GetCurrentUI())
case '3':
mainPage.HidePage("langPage")
mainPage.HidePage("stylePage")
mainPage.ShowPage("keyMapPage")
} }
return event return event