From d1f24830f4f550836a818ab373410cd0af0033d6 Mon Sep 17 00:00:00 2001 From: makeworld Date: Fri, 1 Jan 2021 01:02:09 -0500 Subject: [PATCH] Fix tab row flashing --- README.md | 2 +- display/display.go | 13 +++++-------- display/tab.go | 26 ++++++++++++-------------- go.mod | 2 ++ go.sum | 4 ++-- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index a144138..729ff7b 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ You can also check out [all the issues with the bug label](https://github.com/ma ## Libraries Amfora ❤️ open source! -- [cview](https://gitlab.com/tslocum/cview/) for the TUI +- My [cview fork](https://gitlab.com/makeworld-the-better-one/cview/) for the TUI - pull request [here](https://gitlab.com/tslocum/cview/-/merge_requests/12) - It's a fork of [tview](https://github.com/rivo/tview) with PRs merged and active support - It uses [tcell](https://github.com/gdamore/tcell) for low level terminal operations - [Viper](https://github.com/spf13/viper) for configuration and TOFU storing diff --git a/display/display.go b/display/display.go index 6160ea6..d33bf3a 100644 --- a/display/display.go +++ b/display/display.go @@ -82,18 +82,15 @@ func Init(version, commit, builtBy string) { // Make sure the current tab content is reformatted when the terminal size changes go func(t *tab) { - reformatMu.Lock() - // Lock the app to prevent screen updates until this is done, because calling - // browser.AddTab updates the display + reformatMu.Lock() // Only allow one reformat job at a time for i := range tabs { - // Overwrite tabs with a new, differently sized, left margin - browser.AddTab(strconv.Itoa(i), makeTabLabel(strconv.Itoa(i+1)), makeContentLayout(tabs[i].view)) + // Overwrite all tabs with a new, differently sized, left margin + // TODO: Should only the current tab's margin be changed, just like how + // reformatPageAndSetView is only called for the current tab? + browser.SetTabItem(strconv.Itoa(i), makeContentLayout(tabs[i].view)) if tabs[i] == t { // Reformat page ASAP, in the middle of loop - // TODO The per-tab mutext is unnecessary if the global one is used - t.reformatMu.Lock() // Only one reformat job per tab reformatPageAndSetView(t, t.page) - t.reformatMu.Unlock() } } App.Draw() diff --git a/display/tab.go b/display/tab.go index c5c618c..9052bd9 100644 --- a/display/tab.go +++ b/display/tab.go @@ -3,7 +3,6 @@ package display import ( "strconv" "strings" - "sync" "github.com/gdamore/tcell/v2" "github.com/makeworld-the-better-one/amfora/config" @@ -25,23 +24,21 @@ type tabHistory struct { // tab hold the information needed for each browser tab. type tab struct { - page *structs.Page - view *cview.TextView - history *tabHistory - mode tabMode - reformatMu *sync.Mutex // Mutex for reformatting, so there's only one reformat job at once - barLabel string // The bottomBar label for the tab - barText string // The bottomBar text for the tab + page *structs.Page + view *cview.TextView + history *tabHistory + mode tabMode + barLabel string // The bottomBar label for the tab + barText string // The bottomBar text for the tab } // makeNewTab initializes an tab struct with no content. func makeNewTab() *tab { t := tab{ - page: &structs.Page{Mode: structs.ModeOff}, - view: cview.NewTextView(), - history: &tabHistory{}, - reformatMu: &sync.Mutex{}, - mode: tabModeDone, + page: &structs.Page{Mode: structs.ModeOff}, + view: cview.NewTextView(), + history: &tabHistory{}, + mode: tabModeDone, } t.view.SetDynamicColors(true) t.view.SetRegions(true) @@ -53,7 +50,8 @@ func makeNewTab() *tab { App.Draw() }) t.view.SetDoneFunc(func(key tcell.Key) { - // Altered from: https://gitlab.com/tslocum/cview/-/blob/1f765c8695c3f4b35dae57f469d3aee0b1adbde7/demos/textview/main.go + // Altered from: + // https://gitlab.com/tslocum/cview/-/blob/1f765c8695c3f4b35dae57f469d3aee0b1adbde7/demos/textview/main.go // Handles being able to select and "click" links with the enter and tab keys tab := curTab // Don't let it change in the middle of the code diff --git a/go.mod b/go.mod index c3f0380..fb4282d 100644 --- a/go.mod +++ b/go.mod @@ -30,3 +30,5 @@ require ( replace github.com/mmcdole/gofeed => github.com/makeworld-the-better-one/gofeed v1.1.1-0.20201123002655-c0c6354134fe replace github.com/schollz/progressbar/v3 => github.com/makeworld-the-better-one/progressbar/v3 v3.3.5-0.20201220005701-b036c4d38568 + +replace gitlab.com/tslocum/cview => gitlab.com/makeworld-the-better-one/cview v1.5.3-0.20210101054702-a6023214767d diff --git a/go.sum b/go.sum index c2dac1f..be17aae 100644 --- a/go.sum +++ b/go.sum @@ -232,10 +232,10 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69 github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/urfave/cli v1.22.3/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +gitlab.com/makeworld-the-better-one/cview v1.5.3-0.20210101054702-a6023214767d h1:LV3HpIaWzpLvq4pSQ84FGaY+VKHKr71nreh3vowf3k4= +gitlab.com/makeworld-the-better-one/cview v1.5.3-0.20210101054702-a6023214767d/go.mod h1:aXQjdMGBcA0t7wmEHIeW0tkbjKt1xFcX+ZFTWBZ0jdE= gitlab.com/tslocum/cbind v0.1.4 h1:cbZXPPcieXspk8cShoT6efz7HAT8yMNQcofYWNizis4= gitlab.com/tslocum/cbind v0.1.4/go.mod h1:RvwYE3auSjBNlCmWeGspzn+jdLUVQ8C2QGC+0nP9ChI= -gitlab.com/tslocum/cview v1.5.3-0.20201228180808-c34e0954618b h1:uk7iPAMwl9ZbDeohojQuXEw7rmAM8CrqmCEBJCUkYZU= -gitlab.com/tslocum/cview v1.5.3-0.20201228180808-c34e0954618b/go.mod h1:aXQjdMGBcA0t7wmEHIeW0tkbjKt1xFcX+ZFTWBZ0jdE= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=