From 94db6053d5bbc34f76502eb3d5b1c8bc316ca98e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 27 Mar 2023 20:54:03 +0530 Subject: [PATCH] Turn off atomic update during direct transmission --- tools/tui/graphics/collection.go | 5 +++++ tools/tui/loop/api.go | 12 +++++++++++- tools/tui/loop/run.go | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/tui/graphics/collection.go b/tools/tui/graphics/collection.go index 9af6cb3cb..68d35667e 100644 --- a/tools/tui/graphics/collection.go +++ b/tools/tui/graphics/collection.go @@ -327,8 +327,13 @@ func (self *ImageCollection) new_graphics_command() *GraphicsCommand { } func transmit_by_escape_code(lp *loop.Loop, image_id uint32, temp_file_map map[uint32]*temp_resource, frame *images.ImageFrame, gc *GraphicsCommand) { + atomic := lp.IsAtomicUpdateActive() + lp.EndAtomicUpdate() gc.SetTransmission(GRT_transmission_direct) gc.WriteWithPayloadToLoop(lp, frame.Data()) + if atomic { + lp.StartAtomicUpdate() + } } func transmit_by_shm(lp *loop.Loop, image_id uint32, temp_file_map map[uint32]*temp_resource, frame *images.ImageFrame, gc *GraphicsCommand) { diff --git a/tools/tui/loop/api.go b/tools/tui/loop/api.go index 642ef554b..0802870bc 100644 --- a/tools/tui/loop/api.go +++ b/tools/tui/loop/api.go @@ -62,6 +62,7 @@ type Loop struct { on_SIGTSTP func() error style_cache map[string]func(...any) string style_ctx style.Context + atomic_update_active bool // Suspend the loop restoring terminal state. Call the return resume function to restore the loop Suspend func() (func() error, error) @@ -290,11 +291,20 @@ func (self *Loop) Beep() { } func (self *Loop) StartAtomicUpdate() { + if self.atomic_update_active { + self.EndAtomicUpdate() + } self.QueueWriteString(PENDING_UPDATE.EscapeCodeToSet()) + self.atomic_update_active = true } +func (self *Loop) IsAtomicUpdateActive() bool { return self.atomic_update_active } + func (self *Loop) EndAtomicUpdate() { - self.QueueWriteString(PENDING_UPDATE.EscapeCodeToReset()) + if self.atomic_update_active { + self.QueueWriteString(PENDING_UPDATE.EscapeCodeToReset()) + self.atomic_update_active = false + } } func (self *Loop) SetCursorShape(shape CursorShapes, blink bool) { diff --git a/tools/tui/loop/run.go b/tools/tui/loop/run.go index de7fed733..3143ecbed 100644 --- a/tools/tui/loop/run.go +++ b/tools/tui/loop/run.go @@ -286,6 +286,7 @@ func (self *Loop) run() (err error) { self.death_signal = SIGNULL self.escape_code_parser.Reset() self.exit_code = 0 + self.atomic_update_active = false self.timers = make([]*timer, 0, 1) no_timeout_channel := make(<-chan time.Time) finalizer := ""