Fix users being unable to exit help menu (#261)

Co-authored-by: makeworld
This commit is contained in:
David Jimenez 2021-12-08 01:18:08 +00:00 committed by GitHub
parent 76276f6d1f
commit 0ccf5e2c03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 66 additions and 45 deletions

View File

@ -29,7 +29,7 @@ var bkmkCh = make(chan bkmkAction)
var bkmkModalText string // The current text of the input field in the modal var bkmkModalText string // The current text of the input field in the modal
func bkmkInit() { func bkmkInit() {
panels.AddPanel("bkmk", bkmkModal, false, false) panels.AddPanel(PanelBookmarks, bkmkModal, false, false)
m := bkmkModal m := bkmkModal
if viper.GetBool("a-general.color") { if viper.GetBool("a-general.color") {
@ -111,13 +111,13 @@ func openBkmkModal(name string, exists bool) (string, bkmkAction) {
bkmkModalText = text bkmkModalText = text
}) })
panels.ShowPanel("bkmk") panels.ShowPanel(PanelBookmarks)
panels.SendToFront("bkmk") panels.SendToFront(PanelBookmarks)
App.SetFocus(bkmkModal) App.SetFocus(bkmkModal)
App.Draw() App.Draw()
action := <-bkmkCh action := <-bkmkCh
panels.HidePanel("bkmk") panels.HidePanel(PanelBookmarks)
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
App.Draw() App.Draw()

View File

@ -87,7 +87,7 @@ func Init(version, commit, builtBy string) {
}(tabs[curTab]) }(tabs[curTab])
}) })
panels.AddPanel("browser", browser, true, true) panels.AddPanel(PanelBrowser, browser, true, true)
helpInit() helpInit()
@ -276,9 +276,16 @@ func Init(version, commit, builtBy string) {
// It's focused on a modal right now, nothing should interrupt // It's focused on a modal right now, nothing should interrupt
return event return event
} }
_, ok = App.GetFocus().(*cview.Table) frontPanelName, _ := panels.GetFrontPanel()
if ok { if frontPanelName == PanelHelp {
// It's focused on help right now // It's focused on help right now
if config.TranslateKeyEvent(event) == config.CmdQuit {
// Allow quit key to work, but nothing else
Stop()
return nil
}
// Pass everything else directly, inhibiting other keybindings
// like for editing the URL
return event return event
} }

View File

@ -33,8 +33,8 @@ var dlChoiceCh = make(chan string)
var dlModal = cview.NewModal() var dlModal = cview.NewModal()
func dlInit() { func dlInit() {
panels.AddPanel("dl", dlModal, false, false) panels.AddPanel(PanelDownload, dlModal, false, false)
panels.AddPanel("dlChoice", dlChoiceModal, false, false) panels.AddPanel(PanelDownloadChoiceModal, dlChoiceModal, false, false)
dlm := dlModal dlm := dlModal
chm := dlChoiceModal chm := dlChoiceModal
@ -96,7 +96,7 @@ func dlInit() {
frame.SetTitle(" Download ") frame.SetTitle(" Download ")
dlm.SetDoneFunc(func(buttonIndex int, buttonLabel string) { dlm.SetDoneFunc(func(buttonIndex int, buttonLabel string) {
if buttonLabel == "Ok" { if buttonLabel == "Ok" {
panels.HidePanel("dl") panels.HidePanel(PanelDownload)
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
App.Draw() App.Draw()
} }
@ -141,29 +141,29 @@ func dlChoice(text, u string, resp *gemini.Response) {
choice = "Open" choice = "Open"
} else { } else {
dlChoiceModal.SetText(text) dlChoiceModal.SetText(text)
panels.ShowPanel("dlChoice") panels.ShowPanel(PanelDownloadChoiceModal)
panels.SendToFront("dlChoice") panels.SendToFront(PanelDownloadChoiceModal)
App.SetFocus(dlChoiceModal) App.SetFocus(dlChoiceModal)
App.Draw() App.Draw()
choice = <-dlChoiceCh choice = <-dlChoiceCh
} }
if choice == "Download" { if choice == "Download" {
panels.HidePanel("dlChoice") panels.HidePanel(PanelDownloadChoiceModal)
App.Draw() App.Draw()
downloadURL(config.DownloadsDir, u, resp) downloadURL(config.DownloadsDir, u, resp)
resp.Body.Close() // Only close when the file is downloaded resp.Body.Close() // Only close when the file is downloaded
return return
} }
if choice == "Open" { if choice == "Open" {
panels.HidePanel("dlChoice") panels.HidePanel(PanelDownloadChoiceModal)
App.Draw() App.Draw()
open(u, resp) open(u, resp)
return return
} }
// They chose the "Cancel" button // They chose the "Cancel" button
panels.HidePanel("dlChoice") panels.HidePanel(PanelDownloadChoiceModal)
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
App.Draw() App.Draw()
} }
@ -200,7 +200,7 @@ func open(u string, resp *gemini.Response) {
return return
} }
panels.HidePanel("dl") panels.HidePanel(PanelDownload)
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
App.Draw() App.Draw()
@ -267,15 +267,15 @@ func downloadURL(dir, u string, resp *gemini.Response) string {
// Display // Display
dlModal.ClearButtons() dlModal.ClearButtons()
dlModal.AddButtons([]string{"Downloading..."}) dlModal.AddButtons([]string{"Downloading..."})
panels.ShowPanel("dl") panels.ShowPanel(PanelDownload)
panels.SendToFront("dl") panels.SendToFront(PanelDownload)
App.SetFocus(dlModal) App.SetFocus(dlModal)
App.Draw() App.Draw()
_, err = io.Copy(io.MultiWriter(f, bar), resp.Body) _, err = io.Copy(io.MultiWriter(f, bar), resp.Body)
done = true done = true
if err != nil { if err != nil {
panels.HidePanel("dl") panels.HidePanel(PanelDownload)
Error("Download Error", err.Error()) Error("Download Error", err.Error())
f.Close() f.Close()
os.Remove(savePath) // Remove partial file os.Remove(savePath) // Remove partial file

View File

@ -55,8 +55,8 @@ var helpTable = cview.NewTextView()
// Help displays the help and keybindings. // Help displays the help and keybindings.
func Help() { func Help() {
helpTable.ScrollToBeginning() helpTable.ScrollToBeginning()
panels.ShowPanel("help") panels.ShowPanel(PanelHelp)
panels.SendToFront("help") panels.SendToFront(PanelHelp)
App.SetFocus(helpTable) App.SetFocus(helpTable)
} }
@ -67,7 +67,7 @@ func helpInit() {
helpTable.SetPadding(0, 0, 1, 1) helpTable.SetPadding(0, 0, 1, 1)
helpTable.SetDoneFunc(func(key tcell.Key) { helpTable.SetDoneFunc(func(key tcell.Key) {
if key == tcell.KeyEsc || key == tcell.KeyEnter { if key == tcell.KeyEsc || key == tcell.KeyEnter {
panels.HidePanel("help") panels.HidePanel(PanelHelp)
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
App.Draw() App.Draw()
} }
@ -122,5 +122,5 @@ func helpInit() {
w.Flush() w.Flush()
panels.AddPanel("help", helpTable, true, false) panels.AddPanel(PanelHelp, helpTable, true, false)
} }

View File

@ -36,10 +36,10 @@ func modalInit() {
yesNoModal.AddButtons([]string{"Yes", "No"}) yesNoModal.AddButtons([]string{"Yes", "No"})
panels.AddPanel("info", infoModal, false, false) panels.AddPanel(PanelInfoModal, infoModal, false, false)
panels.AddPanel("error", errorModal, false, false) panels.AddPanel(PanelErrorModal, errorModal, false, false)
panels.AddPanel("input", inputModal, false, false) panels.AddPanel(PanelInputModal, inputModal, false, false)
panels.AddPanel("yesno", yesNoModal, false, false) panels.AddPanel(PanelYesNoModal, yesNoModal, false, false)
// Color setup // Color setup
if viper.GetBool("a-general.color") { if viper.GetBool("a-general.color") {
@ -142,7 +142,7 @@ func modalInit() {
frame.SetTitleAlign(cview.AlignCenter) frame.SetTitleAlign(cview.AlignCenter)
frame.SetTitle(" Info ") frame.SetTitle(" Info ")
infoModal.SetDoneFunc(func(buttonIndex int, buttonLabel string) { infoModal.SetDoneFunc(func(buttonIndex int, buttonLabel string) {
panels.HidePanel("info") panels.HidePanel(PanelInfoModal)
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
App.Draw() App.Draw()
}) })
@ -150,7 +150,7 @@ func modalInit() {
errorModal.SetBorder(true) errorModal.SetBorder(true)
errorModal.GetFrame().SetTitleAlign(cview.AlignCenter) errorModal.GetFrame().SetTitleAlign(cview.AlignCenter)
errorModal.SetDoneFunc(func(buttonIndex int, buttonLabel string) { errorModal.SetDoneFunc(func(buttonIndex int, buttonLabel string) {
panels.HidePanel("error") panels.HidePanel(PanelErrorModal)
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
App.Draw() App.Draw()
errorModalDone <- struct{}{} errorModalDone <- struct{}{}
@ -198,8 +198,8 @@ func Error(title, text string) {
errorModal.GetFrame().SetTitle(title) errorModal.GetFrame().SetTitle(title)
errorModal.SetText(text) errorModal.SetText(text)
panels.ShowPanel("error") panels.ShowPanel(PanelErrorModal)
panels.SendToFront("error") panels.SendToFront(PanelErrorModal)
App.SetFocus(errorModal) App.SetFocus(errorModal)
App.Draw() App.Draw()
@ -209,8 +209,8 @@ func Error(title, text string) {
// Info displays some info on the screen in a modal. // Info displays some info on the screen in a modal.
func Info(s string) { func Info(s string) {
infoModal.SetText(s) infoModal.SetText(s)
panels.ShowPanel("info") panels.ShowPanel(PanelInfoModal)
panels.SendToFront("info") panels.SendToFront(PanelInfoModal)
App.SetFocus(infoModal) App.SetFocus(infoModal)
App.Draw() App.Draw()
} }
@ -240,14 +240,14 @@ func Input(prompt string, sensitive bool) (string, bool) {
} }
inputModal.SetText(prompt + " ") inputModal.SetText(prompt + " ")
panels.ShowPanel("input") panels.ShowPanel(PanelInputModal)
panels.SendToFront("input") panels.SendToFront(PanelInputModal)
App.SetFocus(inputModal) App.SetFocus(inputModal)
App.Draw() App.Draw()
resp := <-inputCh resp := <-inputCh
panels.HidePanel("input") panels.HidePanel(PanelInputModal)
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
App.Draw() App.Draw()
@ -276,13 +276,13 @@ func YesNo(prompt string) bool {
} }
yesNoModal.GetFrame().SetTitle("") yesNoModal.GetFrame().SetTitle("")
yesNoModal.SetText(prompt) yesNoModal.SetText(prompt)
panels.ShowPanel("yesno") panels.ShowPanel(PanelYesNoModal)
panels.SendToFront("yesno") panels.SendToFront(PanelYesNoModal)
App.SetFocus(yesNoModal) App.SetFocus(yesNoModal)
App.Draw() App.Draw()
resp := <-yesNoCh resp := <-yesNoCh
panels.HidePanel("yesno") panels.HidePanel(PanelYesNoModal)
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
App.Draw() App.Draw()
return resp return resp
@ -314,13 +314,13 @@ func Tofu(host string, expiry time.Time) bool {
humanize.Time(expiry), humanize.Time(expiry),
), ),
) )
panels.ShowPanel("yesno") panels.ShowPanel(PanelYesNoModal)
panels.SendToFront("yesno") panels.SendToFront(PanelYesNoModal)
App.SetFocus(yesNoModal) App.SetFocus(yesNoModal)
App.Draw() App.Draw()
resp := <-yesNoCh resp := <-yesNoCh
panels.HidePanel("yesno") panels.HidePanel(PanelYesNoModal)
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
App.Draw() App.Draw()
return resp return resp

14
display/panels.go Normal file
View File

@ -0,0 +1,14 @@
package display
const (
PanelBrowser = "browser"
PanelBookmarks = "bkmk"
PanelDownload = "dl"
PanelDownloadChoiceModal = "dlChoice"
PanelHelp = "help"
PanelYesNoModal = "yesno"
PanelInfoModal = "info"
PanelErrorModal = "error"
PanelInputModal = "input"
)

View File

@ -260,13 +260,13 @@ func openSubscriptionModal(validFeed, subscribed bool) bool {
} }
} }
panels.ShowPanel("yesno") panels.ShowPanel(PanelYesNoModal)
panels.SendToFront("yesno") panels.SendToFront(PanelYesNoModal)
App.SetFocus(yesNoModal) App.SetFocus(yesNoModal)
App.Draw() App.Draw()
resp := <-yesNoCh resp := <-yesNoCh
panels.HidePanel("yesno") panels.HidePanel(PanelYesNoModal)
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
App.Draw() App.Draw()
return resp return resp