diff --git a/color.go b/color.go index bb0ea2d..aa0de37 100644 --- a/color.go +++ b/color.go @@ -5,9 +5,9 @@ import ( ) var ( - AllTheme = []string{"Gruvbox", "Nord"} - Palette = []string{"red", "green", "yellow", "blue", "purple", "cyan", "orange"} - Themes = map[string]map[string]tcell.Color{ + AllTheme = []string{"Gruvbox", "Nord"} + Palette = []string{"red", "green", "yellow", "blue", "purple", "cyan", "orange"} + Themes = map[string]map[string]tcell.Color{ "Gruvbox": { "bg": tcell.NewHexColor(0x282828), "fg": tcell.NewHexColor(0xebdbb2), @@ -48,6 +48,7 @@ type Style struct { prefixColor string labelColor string pressColor string + highLightColor string Theme string Transparent bool } @@ -60,6 +61,7 @@ func NewStyle() *Style { prefixColor: "cyan", labelColor: "yellow", pressColor: "purple", + highLightColor: "orange", } } @@ -90,6 +92,10 @@ 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] } diff --git a/main.go b/main.go index d81a87d..ab2c5af 100644 --- a/main.go +++ b/main.go @@ -20,12 +20,14 @@ var ( srcBorderDropDown = tview.NewDropDown() dstBorderDropDown = tview.NewDropDown() styleCycle = NewUICycle(themeDropDown, transparentDropDown, srcBorderDropDown, dstBorderDropDown) + keyMapMenu = tview.NewTextView() langButton = tview.NewButton("(1)Language") styleButton = tview.NewButton("(2)Style") - menuButton = tview.NewButton("(3)KeyMap") + keyMapButton = tview.NewButton("(3)KeyMap") translateWindow = tview.NewFlex() langWindow = tview.NewFlex() styleWindow = tview.NewFlex() + keyMapWindow = tview.NewFlex() mainPage = tview.NewPages() // settings config = viper.New() @@ -40,6 +42,7 @@ func main() { mainPage.AddPage("translatePage", translateWindow, true, true) mainPage.AddPage("langPage", langWindow, true, false) mainPage.AddPage("stylePage", styleWindow, true, false) + mainPage.AddPage("keyMapPage", keyMapWindow, true, false) if err := app.SetRoot(mainPage, true). EnableMouse(true).Run(); err != nil { diff --git a/ui.go b/ui.go index b7d237f..54f4993 100644 --- a/ui.go +++ b/ui.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" "strconv" @@ -38,6 +39,31 @@ func (ui *UICycle) GetCurrentUI() tview.Primitive { return ui.widget[ui.index] } +const ( + keyMapText string = `[#%[1]s][-] + Exit program. +[#%[1]s][-] + Toggle pop out window. +[#%[1]s][-] + Translate from left window to right window. +[#%[1]s][-] + Swap language. +[#%[1]s][-] + Clear all text in left window. +[#%[1]s][-] + Play sound on left window. +[#%[1]s][-] + Play sound on right window. +[#%[1]s][-] + Stop play sound. +[#%[1]s][-] + Toggle transparent. +[#%[1]s], [-] + Cycle through the pop out widget. +[#%[1]s]<1>, <2>, <3>[-] + Switch pop out window.` +) + func updateBackgroundColor() { // input/output srcInput.SetBackgroundColor(style.BackgroundColor()) @@ -89,6 +115,9 @@ func updateBackgroundColor() { tcell.StyleDefault. Background(style.SelectedColor()). Foreground(style.PrefixColor())) + + // key map + keyMapMenu.SetBackgroundColor(style.BackgroundColor()) } func updateBorderColor() { @@ -149,10 +178,15 @@ func updateNonConfigColor() { SetBackgroundColorActivated(style.PressColor()). SetLabelColorActivated(style.ForegroundColor()). SetBackgroundColor(style.SelectedColor()) - menuButton.SetLabelColor(style.ForegroundColor()). + keyMapButton.SetLabelColor(style.ForegroundColor()). SetBackgroundColorActivated(style.PressColor()). SetLabelColorActivated(style.ForegroundColor()). SetBackgroundColor(style.SelectedColor()) + + // key map + keyMapMenu.SetTextColor(style.ForegroundColor()). + SetBorderColor(style.HighLightColor()). + SetTitleColor(style.HighLightColor()) } func updateAllColor() { @@ -178,7 +212,7 @@ func attachButton() *tview.Flex { AddItem(nil, 18, 1, false). AddItem(styleButton, 8, 1, true). AddItem(nil, 18, 1, false). - AddItem(menuButton, 9, 1, true). + AddItem(keyMapButton, 9, 1, true). AddItem(nil, 0, 1, false) } @@ -211,6 +245,13 @@ func uiInit() { dstBorderDropDown.SetBorder(true). 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 translateWindow.SetDirection(tview.FlexColumn). AddItem(srcInput, 0, 1, true). @@ -247,14 +288,24 @@ func uiInit() { 20, 1, true). AddItem(attachButton(), 1, 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() updateTitle() // handler - mainPage.SetInputCapture(mainpageHandler) - langWindow.SetInputCapture(langWindowHandler) - styleWindow.SetInputCapture(styleWindowHandler) + mainPage.SetInputCapture(mainPageHandler) + langWindow.SetInputCapture(popOutWindowHandler) + styleWindow.SetInputCapture(popOutWindowHandler) + keyMapWindow.SetInputCapture(popOutWindowHandler) translateWindow.SetInputCapture(translatePageHandler) srcLangDropDown.SetDoneFunc(langDropDownHandler). SetSelectedFunc(func(text string, index int) { @@ -288,19 +339,32 @@ func uiInit() { style.SetDstBorderColor(text) updateBorderColor() }) + keyMapMenu.SetDoneFunc(func(key tcell.Key) { + switch key { + case tcell.KeyEsc: + mainPage.HidePage("keyMapPage") + } + }) langButton.SetSelectedFunc(func() { mainPage.HidePage("stylePage") + mainPage.HidePage("keyMapPage") mainPage.ShowPage("langPage") app.SetFocus(langCycle.GetCurrentUI()) }) styleButton.SetSelectedFunc(func() { mainPage.HidePage("langPage") + mainPage.HidePage("keyMapPage") mainPage.ShowPage("stylePage") 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() switch key { @@ -316,27 +380,24 @@ func mainpageHandler(event *tcell.EventKey) *tcell.EventKey { return event } -func langWindowHandler(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 { +func popOutWindowHandler(event *tcell.EventKey) *tcell.EventKey { ch := event.Rune() switch ch { case '1': mainPage.HidePage("stylePage") + mainPage.HidePage("keyMapPage") mainPage.ShowPage("langPage") 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