From f8b74a9a9f1b607e20f7b5654e85b03be34ce0ed Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 16 Jul 2024 08:26:37 -0500 Subject: ui: add :redraw command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a :redraw command to force a repaint of the entire screen. Changelog-added: New `:redraw` command to force a repaint of the screen. Requested-by: Remko Tronçon Signed-off-by: Tim Culverhouse Tested-by: Koni Marti Acked-by: Robin Jarry --- lib/ui/ui.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/ui/ui.go b/lib/ui/ui.go index 0825b5b5..c20eac37 100644 --- a/lib/ui/ui.go +++ b/lib/ui/ui.go @@ -45,6 +45,7 @@ var state struct { dirty uint32 // == 1 if render has been queued in Redraw channel // == 1 if suspend is pending suspending uint32 + refresh uint32 // == 1 if a refresh has been queued } func Initialize(content DrawableInteractive) error { @@ -122,6 +123,12 @@ func Close() { state.vx.Close() } +func QueueRefresh() { + if atomic.SwapUint32(&state.refresh, 1) != 1 { + Invalidate() + } +} + func Render() { if atomic.SwapUint32(&state.dirty, 0) != 0 { state.vx.Window().Clear() @@ -133,7 +140,12 @@ func Render() { // if the Draw resulted in a popover, draw it state.popover.Draw(state.ctx) } - state.vx.Render() + switch atomic.SwapUint32(&state.refresh, 0) { + case 0: + state.vx.Render() + case 1: + state.vx.Refresh() + } } } -- cgit