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 (
"strings"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/v2"
"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
func bkmkInit() {
panels.AddPanel("bkmk", bkmkModal, false, false)
m := bkmkModal
if viper.GetBool("a-general.color") {
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)
tabRow.SetChangedFunc(func() {
App.Draw()
})
helpInit()
layout.SetDirection(cview.FlexRow)

View File

@ -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()
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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") {

View File

@ -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()
}

View File

@ -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

1
go.mod
View File

@ -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

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/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=