diff --git a/config/keybindings.go b/config/keybindings.go index 8afd2e3..c01df35 100644 --- a/config/keybindings.go +++ b/config/keybindings.go @@ -3,7 +3,7 @@ package config import ( "strings" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "github.com/spf13/viper" ) diff --git a/display/bookmarks.go b/display/bookmarks.go index 16b2144..6bbdee0 100644 --- a/display/bookmarks.go +++ b/display/bookmarks.go @@ -21,6 +21,8 @@ var bkmkCh = make(chan int) // 1, 0, -1 for add/update, cancel, and remove var bkmkModalText string // The current text of the input field in the modal func bkmkInit() { + panels.AddPanel("bkmk", bkmkModal, false, false) + m := bkmkModal if viper.GetBool("a-general.color") { m.SetBackgroundColor(config.GetColor("bkmk_modal_bg")) diff --git a/display/display.go b/display/display.go index 801d516..433c3b6 100644 --- a/display/display.go +++ b/display/display.go @@ -87,10 +87,6 @@ func Init(version, commit, builtBy string) { panels.AddPanel("browser", browser, true, true) - tabRow.SetChangedFunc(func() { - App.Draw() - }) - helpInit() layout.SetDirection(cview.FlexRow) diff --git a/display/download.go b/display/download.go index 0853065..fd8e3f9 100644 --- a/display/download.go +++ b/display/download.go @@ -33,6 +33,9 @@ var dlChoiceCh = make(chan string) var dlModal = cview.NewModal() func dlInit() { + panels.AddPanel("dlChoice", dlChoiceModal, false, false) + panels.AddPanel("dl", dlModal, false, false) + dlm := dlModal chm := dlChoiceModal if viper.GetBool("a-general.color") { @@ -126,8 +129,7 @@ func dlChoice(text, u string, resp *gemini.Response) { choice = "Open" } else { dlChoiceModal.SetText(text) - tabPages.ShowPage("dlChoice") - tabPages.SendToFront("dlChoice") + panels.ShowPanel("dlChoice") App.SetFocus(dlChoiceModal) App.Draw() choice = <-dlChoiceCh @@ -141,12 +143,12 @@ func dlChoice(text, u string, resp *gemini.Response) { return } if choice == "Open" { - tabPages.HidePage("dlChoice") + panels.HidePanel("dlChoice") App.Draw() open(u, resp) return } - tabPages.SwitchToPage(strconv.Itoa(curTab)) + browser.SetCurrentTab(strconv.Itoa(curTab)) App.SetFocus(tabs[curTab].view) App.Draw() } diff --git a/display/handlers.go b/display/handlers.go index 21e3af3..952f49f 100644 --- a/display/handlers.go +++ b/display/handlers.go @@ -95,7 +95,7 @@ func handleFavicon(t *tab, host, old string) { defer func() { // Update display if needed if t.page.Favicon != old && isValidTab(t) { - rewriteTabRow() + // TODO update browser tab label } }() @@ -117,7 +117,7 @@ func handleFavicon(t *tab, host, old string) { } if fav != "" { t.page.Favicon = fav - rewriteTabRow() + // TODO update browser tab label return } diff --git a/display/help.go b/display/help.go index 8c9d1aa..0e45e5e 100644 --- a/display/help.go +++ b/display/help.go @@ -4,6 +4,7 @@ import ( "fmt" "strconv" "strings" + "text/tabwriter" "github.com/gdamore/tcell/v2" "github.com/makeworld-the-better-one/amfora/config" @@ -103,36 +104,16 @@ func helpInit() { config.GetKeyBinding(config.CmdQuit), ) - rows := strings.Count(helpCells, "\n") + 1 - cells := strings.Split( - strings.ReplaceAll(helpCells, "\n", "|"), - "|") - cell := 0 - extraRows := 0 // Rows continued from the previous, without spacing - for r := 0; r < rows; r++ { - for c := 0; c < 2; c++ { - var tableCell *cview.TableCell - if c == 0 { - // First column, the keybinding - tableCell = cview.NewTableCell(" " + cells[cell]). - SetAttributes(tcell.AttrBold). - SetAlign(cview.AlignLeft) - } else { - tableCell = cview.NewTableCell(" " + cells[cell]) - } - if c == 0 && cells[cell] == "" || (cell > 0 && cells[cell-1] == "" && c == 1) { - // The keybinding column for this row was blank, meaning the explanation - // column is continued from the previous row. - // The row should be added without any spacing rows - helpTable.SetCell(((2*r)-extraRows/2)-1, c, tableCell) - extraRows++ - } else { - helpTable.SetCell((2*r)-extraRows/2, c, tableCell) // Every other row, for readability - } - cell++ + lines := strings.Split(helpCells, "\n") + w := tabwriter.NewWriter(helpTable, 0, 8, 2, ' ', 0) + for i, line := range lines { + cells := strings.Split(line, "|") + if i > 0 && len(cells[0]) > 0 { + fmt.Fprintln(w, "\t") } fmt.Fprintf(w, "%s\t%s\n", cells[0], cells[1]) } + w.Flush() browser.AddTab("help", "Help", helpTable) } diff --git a/display/modals.go b/display/modals.go index d0c2cbd..6043df5 100644 --- a/display/modals.go +++ b/display/modals.go @@ -40,9 +40,6 @@ func modalInit() { panels.AddPanel("error", errorModal, false, false) panels.AddPanel("input", inputModal, false, false) panels.AddPanel("yesno", yesNoModal, false, false) - panels.AddPanel("bkmk", bkmkModal, false, false) - panels.AddPanel("dlChoice", dlChoiceModal, false, false) - panels.AddPanel("dl", dlModal, false, false) // Color setup if viper.GetBool("a-general.color") { diff --git a/display/private.go b/display/private.go index 1ead234..b721e76 100644 --- a/display/private.go +++ b/display/private.go @@ -1,15 +1,11 @@ package display import ( - "fmt" "net/url" - "strconv" "strings" - "github.com/makeworld-the-better-one/amfora/config" "github.com/makeworld-the-better-one/amfora/renderer" "github.com/makeworld-the-better-one/amfora/structs" - "github.com/spf13/viper" ) // This file contains the functions that aren't part of the public API. @@ -144,32 +140,3 @@ func goURL(t *tab, u string) { t.applyBottomBar() } } - -// rewriteTabRow clears the tabRow and writes all the tabs number/favicons into it. -func rewriteTabRow() { - tabRow.Clear() - if viper.GetBool("a-general.color") { - for i := 0; i < NumTabs(); i++ { - char := strconv.Itoa(i + 1) - if tabs[i].page.Favicon != "" { - char = tabs[i].page.Favicon - } - fmt.Fprintf(tabRow, `["%d"][%s] %s [%s][""]|`, - i, - config.GetColorString("tab_num"), - char, - config.GetColorString("tab_divider"), - ) - } - } else { - for i := 0; i < NumTabs(); i++ { - char := strconv.Itoa(i + 1) - if tabs[i].page.Favicon != "" { - char = tabs[i].page.Favicon - } - fmt.Fprintf(tabRow, `["%d"] %s [""]|`, i, char) - } - } - tabRow.Highlight(strconv.Itoa(curTab)).ScrollToHighlight() - App.Draw() -} diff --git a/display/subscriptions.go b/display/subscriptions.go index 7c5ffbe..b2bf1c7 100644 --- a/display/subscriptions.go +++ b/display/subscriptions.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "github.com/makeworld-the-better-one/amfora/cache" "github.com/makeworld-the-better-one/amfora/config" "github.com/makeworld-the-better-one/amfora/renderer" @@ -230,19 +230,19 @@ func openSubscriptionModal(validFeed, subscribed bool) bool { // Reuses yesNoModal if viper.GetBool("a-general.color") { - yesNoModal. - SetBackgroundColor(config.GetColor("subscription_modal_bg")). - SetTextColor(config.GetColor("subscription_modal_text")) - yesNoModal.GetFrame(). - SetBorderColor(config.GetColor("subscription_modal_text")). - SetTitleColor(config.GetColor("subscription_modal_text")) + m := yesNoModal + m.SetBackgroundColor(config.GetColor("subscription_modal_bg")) + m.SetTextColor(config.GetColor("subscription_modal_text")) + frame := yesNoModal.GetFrame() + frame.SetBorderColor(config.GetColor("subscription_modal_text")) + frame.SetTitleColor(config.GetColor("subscription_modal_text")) } else { - yesNoModal. - SetBackgroundColor(tcell.ColorBlack). - SetTextColor(tcell.ColorWhite) - yesNoModal.GetFrame(). - SetBorderColor(tcell.ColorWhite). - SetTitleColor(tcell.ColorWhite) + m := yesNoModal + m.SetBackgroundColor(tcell.ColorBlack) + m.SetTextColor(tcell.ColorWhite) + frame := yesNoModal.GetFrame() + frame.SetBorderColor(tcell.ColorWhite) + frame.SetTitleColor(tcell.ColorWhite) } if validFeed { yesNoModal.GetFrame().SetTitle("Feed Subscription") @@ -260,13 +260,13 @@ func openSubscriptionModal(validFeed, subscribed bool) bool { } } - tabPages.ShowPage("yesno") - tabPages.SendToFront("yesno") + panels.ShowPanel("yesno") + panels.SendToFront("yesno") App.SetFocus(yesNoModal) App.Draw() resp := <-yesNoCh - tabPages.SwitchToPage(strconv.Itoa(curTab)) + browser.SetCurrentTab(strconv.Itoa(curTab)) App.SetFocus(tabs[curTab].view) App.Draw() return resp diff --git a/go.mod b/go.mod index 24c599e..c4480aa 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.14 require ( github.com/dustin/go-humanize v1.0.0 github.com/fsnotify/fsnotify v1.4.9 // indirect - github.com/gdamore/tcell v1.4.0 github.com/gdamore/tcell/v2 v2.1.0 github.com/google/go-cmp v0.5.0 // indirect github.com/makeworld-the-better-one/go-gemini v0.11.0 diff --git a/go.sum b/go.sum index 24cb67a..25c053e 100644 --- a/go.sum +++ b/go.sum @@ -50,8 +50,6 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= -github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU= -github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0= github.com/gdamore/tcell/v2 v2.0.0-dev/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA= github.com/gdamore/tcell/v2 v2.1.0 h1:UnSmozHgBkQi2PGsFr+rpdXuAPRRucMegpQp3Z3kDro= github.com/gdamore/tcell/v2 v2.1.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=