1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-12-04 14:46:29 -05:00

Compiles now

This commit is contained in:
makeworld 2020-12-25 18:34:03 -05:00
parent 82e33130d8
commit 39f19bf643
11 changed files with 35 additions and 93 deletions

View File

@ -3,7 +3,7 @@ package config
import ( import (
"strings" "strings"
"github.com/gdamore/tcell" "github.com/gdamore/tcell/v2"
"github.com/spf13/viper" "github.com/spf13/viper"
) )

View File

@ -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 var bkmkModalText string // The current text of the input field in the modal
func bkmkInit() { func bkmkInit() {
panels.AddPanel("bkmk", bkmkModal, false, false)
m := bkmkModal m := bkmkModal
if viper.GetBool("a-general.color") { if viper.GetBool("a-general.color") {
m.SetBackgroundColor(config.GetColor("bkmk_modal_bg")) m.SetBackgroundColor(config.GetColor("bkmk_modal_bg"))

View File

@ -87,10 +87,6 @@ func Init(version, commit, builtBy string) {
panels.AddPanel("browser", browser, true, true) panels.AddPanel("browser", browser, true, true)
tabRow.SetChangedFunc(func() {
App.Draw()
})
helpInit() helpInit()
layout.SetDirection(cview.FlexRow) layout.SetDirection(cview.FlexRow)

View File

@ -33,6 +33,9 @@ var dlChoiceCh = make(chan string)
var dlModal = cview.NewModal() var dlModal = cview.NewModal()
func dlInit() { func dlInit() {
panels.AddPanel("dlChoice", dlChoiceModal, false, false)
panels.AddPanel("dl", dlModal, false, false)
dlm := dlModal dlm := dlModal
chm := dlChoiceModal chm := dlChoiceModal
if viper.GetBool("a-general.color") { if viper.GetBool("a-general.color") {
@ -126,8 +129,7 @@ func dlChoice(text, u string, resp *gemini.Response) {
choice = "Open" choice = "Open"
} else { } else {
dlChoiceModal.SetText(text) dlChoiceModal.SetText(text)
tabPages.ShowPage("dlChoice") panels.ShowPanel("dlChoice")
tabPages.SendToFront("dlChoice")
App.SetFocus(dlChoiceModal) App.SetFocus(dlChoiceModal)
App.Draw() App.Draw()
choice = <-dlChoiceCh choice = <-dlChoiceCh
@ -141,12 +143,12 @@ func dlChoice(text, u string, resp *gemini.Response) {
return return
} }
if choice == "Open" { if choice == "Open" {
tabPages.HidePage("dlChoice") panels.HidePanel("dlChoice")
App.Draw() App.Draw()
open(u, resp) open(u, resp)
return return
} }
tabPages.SwitchToPage(strconv.Itoa(curTab)) browser.SetCurrentTab(strconv.Itoa(curTab))
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
App.Draw() App.Draw()
} }

View File

@ -95,7 +95,7 @@ func handleFavicon(t *tab, host, old string) {
defer func() { defer func() {
// Update display if needed // Update display if needed
if t.page.Favicon != old && isValidTab(t) { 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 != "" { if fav != "" {
t.page.Favicon = fav t.page.Favicon = fav
rewriteTabRow() // TODO update browser tab label
return return
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
"text/tabwriter"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
"github.com/makeworld-the-better-one/amfora/config" "github.com/makeworld-the-better-one/amfora/config"
@ -103,36 +104,16 @@ func helpInit() {
config.GetKeyBinding(config.CmdQuit), config.GetKeyBinding(config.CmdQuit),
) )
rows := strings.Count(helpCells, "\n") + 1 lines := strings.Split(helpCells, "\n")
cells := strings.Split( w := tabwriter.NewWriter(helpTable, 0, 8, 2, ' ', 0)
strings.ReplaceAll(helpCells, "\n", "|"), for i, line := range lines {
"|") cells := strings.Split(line, "|")
cell := 0 if i > 0 && len(cells[0]) > 0 {
extraRows := 0 // Rows continued from the previous, without spacing fmt.Fprintln(w, "\t")
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++
} }
fmt.Fprintf(w, "%s\t%s\n", cells[0], cells[1]) fmt.Fprintf(w, "%s\t%s\n", cells[0], cells[1])
} }
w.Flush() w.Flush()
browser.AddTab("help", "Help", helpTable) browser.AddTab("help", "Help", helpTable)
} }

View File

@ -40,9 +40,6 @@ func modalInit() {
panels.AddPanel("error", errorModal, false, false) panels.AddPanel("error", errorModal, false, false)
panels.AddPanel("input", inputModal, false, false) panels.AddPanel("input", inputModal, false, false)
panels.AddPanel("yesno", yesNoModal, 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 // Color setup
if viper.GetBool("a-general.color") { if viper.GetBool("a-general.color") {

View File

@ -1,15 +1,11 @@
package display package display
import ( import (
"fmt"
"net/url" "net/url"
"strconv"
"strings" "strings"
"github.com/makeworld-the-better-one/amfora/config"
"github.com/makeworld-the-better-one/amfora/renderer" "github.com/makeworld-the-better-one/amfora/renderer"
"github.com/makeworld-the-better-one/amfora/structs" "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. // 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() 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()
}

View File

@ -9,7 +9,7 @@ import (
"strings" "strings"
"time" "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/cache"
"github.com/makeworld-the-better-one/amfora/config" "github.com/makeworld-the-better-one/amfora/config"
"github.com/makeworld-the-better-one/amfora/renderer" "github.com/makeworld-the-better-one/amfora/renderer"
@ -230,19 +230,19 @@ func openSubscriptionModal(validFeed, subscribed bool) bool {
// Reuses yesNoModal // Reuses yesNoModal
if viper.GetBool("a-general.color") { if viper.GetBool("a-general.color") {
yesNoModal. m := yesNoModal
SetBackgroundColor(config.GetColor("subscription_modal_bg")). m.SetBackgroundColor(config.GetColor("subscription_modal_bg"))
SetTextColor(config.GetColor("subscription_modal_text")) m.SetTextColor(config.GetColor("subscription_modal_text"))
yesNoModal.GetFrame(). frame := yesNoModal.GetFrame()
SetBorderColor(config.GetColor("subscription_modal_text")). frame.SetBorderColor(config.GetColor("subscription_modal_text"))
SetTitleColor(config.GetColor("subscription_modal_text")) frame.SetTitleColor(config.GetColor("subscription_modal_text"))
} else { } else {
yesNoModal. m := yesNoModal
SetBackgroundColor(tcell.ColorBlack). m.SetBackgroundColor(tcell.ColorBlack)
SetTextColor(tcell.ColorWhite) m.SetTextColor(tcell.ColorWhite)
yesNoModal.GetFrame(). frame := yesNoModal.GetFrame()
SetBorderColor(tcell.ColorWhite). frame.SetBorderColor(tcell.ColorWhite)
SetTitleColor(tcell.ColorWhite) frame.SetTitleColor(tcell.ColorWhite)
} }
if validFeed { if validFeed {
yesNoModal.GetFrame().SetTitle("Feed Subscription") yesNoModal.GetFrame().SetTitle("Feed Subscription")
@ -260,13 +260,13 @@ func openSubscriptionModal(validFeed, subscribed bool) bool {
} }
} }
tabPages.ShowPage("yesno") panels.ShowPanel("yesno")
tabPages.SendToFront("yesno") panels.SendToFront("yesno")
App.SetFocus(yesNoModal) App.SetFocus(yesNoModal)
App.Draw() App.Draw()
resp := <-yesNoCh resp := <-yesNoCh
tabPages.SwitchToPage(strconv.Itoa(curTab)) browser.SetCurrentTab(strconv.Itoa(curTab))
App.SetFocus(tabs[curTab].view) App.SetFocus(tabs[curTab].view)
App.Draw() App.Draw()
return resp return resp

1
go.mod
View File

@ -5,7 +5,6 @@ go 1.14
require ( require (
github.com/dustin/go-humanize v1.0.0 github.com/dustin/go-humanize v1.0.0
github.com/fsnotify/fsnotify v1.4.9 // indirect 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/gdamore/tcell/v2 v2.1.0
github.com/google/go-cmp v0.5.0 // indirect github.com/google/go-cmp v0.5.0 // indirect
github.com/makeworld-the-better-one/go-gemini v0.11.0 github.com/makeworld-the-better-one/go-gemini v0.11.0

2
go.sum
View File

@ -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/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 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= 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.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 h1:UnSmozHgBkQi2PGsFr+rpdXuAPRRucMegpQp3Z3kDro=
github.com/gdamore/tcell/v2 v2.1.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA= github.com/gdamore/tcell/v2 v2.1.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=