diff options
Diffstat (limited to 'popups.go')
| -rw-r--r-- | popups.go | 157 |
1 files changed, 157 insertions, 0 deletions
@@ -70,6 +70,10 @@ func showModelSelectionPopup() { pages.RemovePage("modelSelectionPopup") return nil } + if event.Key() == tcell.KeyRune && event.Rune() == 'x' { + pages.RemovePage("modelSelectionPopup") + return nil + } return event }) modal := func(p tview.Primitive, width, height int) tview.Primitive { @@ -163,6 +167,10 @@ func showAPILinkSelectionPopup() { pages.RemovePage("apiLinkSelectionPopup") return nil } + if event.Key() == tcell.KeyRune && event.Rune() == 'x' { + pages.RemovePage("apiLinkSelectionPopup") + return nil + } return event }) modal := func(p tview.Primitive, width, height int) tview.Primitive { @@ -229,6 +237,10 @@ func showUserRoleSelectionPopup() { pages.RemovePage("userRoleSelectionPopup") return nil } + if event.Key() == tcell.KeyRune && event.Rune() == 'x' { + pages.RemovePage("userRoleSelectionPopup") + return nil + } return event }) modal := func(p tview.Primitive, width, height int) tview.Primitive { @@ -297,6 +309,10 @@ func showBotRoleSelectionPopup() { pages.RemovePage("botRoleSelectionPopup") return nil } + if event.Key() == tcell.KeyRune && event.Rune() == 'x' { + pages.RemovePage("botRoleSelectionPopup") + return nil + } return event }) modal := func(p tview.Primitive, width, height int) tview.Primitive { @@ -322,6 +338,16 @@ func showFileCompletionPopup(filter string) { if len(complMatches) == 0 { return } + // If only one match, auto-complete without showing popup + if len(complMatches) == 1 { + currentText := textArea.GetText() + atIdx := strings.LastIndex(currentText, "@") + if atIdx >= 0 { + before := currentText[:atIdx] + textArea.SetText(before+complMatches[0], true) + } + return + } widget := tview.NewList().ShowSecondaryText(false). SetSelectedBackgroundColor(tcell.ColorGray) widget.SetTitle("file completion").SetBorder(true) @@ -337,6 +363,17 @@ func showFileCompletionPopup(filter string) { } pages.RemovePage("fileCompletionPopup") }) + widget.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { + if event.Key() == tcell.KeyEscape { + pages.RemovePage("fileCompletionPopup") + return nil + } + if event.Key() == tcell.KeyRune && event.Rune() == 'x' { + pages.RemovePage("fileCompletionPopup") + return nil + } + return event + }) modal := func(p tview.Primitive, width, height int) tview.Primitive { return tview.NewFlex(). AddItem(nil, 0, 1, false). @@ -350,3 +387,123 @@ func showFileCompletionPopup(filter string) { pages.AddPage("fileCompletionPopup", modal(widget, 80, 20), true, true) app.SetFocus(widget) } + +func updateWidgetColors(theme tview.Theme) { + bgColor := theme.PrimitiveBackgroundColor + fgColor := theme.PrimaryTextColor + borderColor := theme.BorderColor + titleColor := theme.TitleColor + + textView.SetBackgroundColor(bgColor) + textView.SetTextColor(fgColor) + textView.SetBorderColor(borderColor) + textView.SetTitleColor(titleColor) + + textArea.SetBackgroundColor(bgColor) + textArea.SetBorderColor(borderColor) + textArea.SetTitleColor(titleColor) + textArea.SetTextStyle(tcell.StyleDefault.Background(bgColor).Foreground(fgColor)) + textArea.SetPlaceholderStyle(tcell.StyleDefault.Background(bgColor).Foreground(fgColor)) + // Force textarea refresh by restoring text (SetTextStyle doesn't trigger redraw) + textArea.SetText(textArea.GetText(), true) + + editArea.SetBackgroundColor(bgColor) + editArea.SetBorderColor(borderColor) + editArea.SetTitleColor(titleColor) + editArea.SetTextStyle(tcell.StyleDefault.Background(bgColor).Foreground(fgColor)) + editArea.SetPlaceholderStyle(tcell.StyleDefault.Background(bgColor).Foreground(fgColor)) + // Force textarea refresh by restoring text (SetTextStyle doesn't trigger redraw) + editArea.SetText(editArea.GetText(), true) + + statusLineWidget.SetBackgroundColor(bgColor) + statusLineWidget.SetTextColor(fgColor) + statusLineWidget.SetBorderColor(borderColor) + statusLineWidget.SetTitleColor(titleColor) + + helpView.SetBackgroundColor(bgColor) + helpView.SetTextColor(fgColor) + helpView.SetBorderColor(borderColor) + helpView.SetTitleColor(titleColor) + + searchField.SetBackgroundColor(bgColor) + searchField.SetBorderColor(borderColor) + searchField.SetTitleColor(titleColor) +} + +// showColorschemeSelectionPopup creates a modal popup to select a colorscheme +func showColorschemeSelectionPopup() { + // Get the list of available colorschemes + schemeNames := make([]string, 0, len(colorschemes)) + for name := range colorschemes { + schemeNames = append(schemeNames, name) + } + slices.Sort(schemeNames) + // Check for empty options list + if len(schemeNames) == 0 { + logger.Warn("no colorschemes available for selection") + message := "No colorschemes available." + if err := notifyUser("Empty list", message); err != nil { + logger.Error("failed to send notification", "error", err) + } + return + } + // Create a list primitive + schemeListWidget := tview.NewList().ShowSecondaryText(false). + SetSelectedBackgroundColor(tcell.ColorGray) + schemeListWidget.SetTitle("Select Colorscheme").SetBorder(true) + + currentScheme := "default" + for name := range colorschemes { + if tview.Styles == colorschemes[name] { + currentScheme = name + break + } + } + currentSchemeIndex := -1 + for i, scheme := range schemeNames { + if scheme == currentScheme { + currentSchemeIndex = i + } + schemeListWidget.AddItem(scheme, "", 0, nil) + } + // Set the current selection if found + if currentSchemeIndex != -1 { + schemeListWidget.SetCurrentItem(currentSchemeIndex) + } + schemeListWidget.SetSelectedFunc(func(index int, mainText string, secondaryText string, shortcut rune) { + // Update the colorscheme + if theme, ok := colorschemes[mainText]; ok { + tview.Styles = theme + go func() { + app.QueueUpdateDraw(func() { + updateWidgetColors(theme) + }) + }() + } + // Remove the popup page + pages.RemovePage("colorschemeSelectionPopup") + }) + schemeListWidget.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { + if event.Key() == tcell.KeyEscape { + pages.RemovePage("colorschemeSelectionPopup") + return nil + } + if event.Key() == tcell.KeyRune && event.Rune() == 'x' { + pages.RemovePage("colorschemeSelectionPopup") + return nil + } + return event + }) + modal := func(p tview.Primitive, width, height int) tview.Primitive { + return tview.NewFlex(). + AddItem(nil, 0, 1, false). + AddItem(tview.NewFlex().SetDirection(tview.FlexRow). + AddItem(nil, 0, 1, false). + AddItem(p, height, 1, true). + AddItem(nil, 0, 1, false), width, 1, true). + AddItem(nil, 0, 1, false) + } + // Add modal page and make it visible + pages.AddPage("colorschemeSelectionPopup", modal(schemeListWidget, 40, len(schemeNames)+2), true, true) + app.SetFocus(schemeListWidget) +} |
