From 01ccccbf24a8e453e036bf08b7052ac47baa1ff7 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Thu, 21 Sep 2023 22:26:07 +0200 Subject: terminal: draw even if underlying command has died After the command running in the terminal has exited, the tcell-term buffer still contains the last status of its virtual tty. If a virtual terminal is visible, draw it even after its command has exited. Calling tcellterm.VT.Draw() does not interact with the underlying process at all, it only accesses the screen buffer. This should fix incomplete drawing of message parts when using a pager that exits after printing contents (e.g. `less -F`). Also, it should fix redrawing of such message part contents after switching tabs back and forth. Reported-by: Julio B Signed-off-by: Robin Jarry Tested-by: Julio B --- widgets/terminal.go | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'widgets') diff --git a/widgets/terminal.go b/widgets/terminal.go index 47bf0e7a..96919515 100644 --- a/widgets/terminal.go +++ b/widgets/terminal.go @@ -53,7 +53,7 @@ func (term *Terminal) closeErr(err error) { if atomic.SwapInt32(&term.closed, closed) == closed { return } - if term.vterm != nil && err == nil { + if term.vterm != nil { // Stop receiving events term.vterm.Detach() term.vterm.Close() @@ -61,9 +61,6 @@ func (term *Terminal) closeErr(err error) { if term.OnClose != nil { term.OnClose(err) } - if term.ctx != nil { - term.ctx.HideCursor() - } ui.Invalidate() } @@ -78,13 +75,10 @@ func (term *Terminal) Invalidate() { } func (term *Terminal) Draw(ctx *ui.Context) { - if term.isClosed() { - return - } term.vterm.SetSurface(ctx.View()) w, h := ctx.View().Size() - if term.ctx != nil { + if !term.isClosed() && term.ctx != nil { ow, oh := term.ctx.View().Size() if w != ow || h != oh { term.vterm.Resize(w, h) @@ -103,29 +97,22 @@ func (term *Terminal) Draw(ctx *ui.Context) { term.OnStart() } } - term.draw() -} - -func (term *Terminal) Show(visible bool) { - term.visible = visible -} - -func (term *Terminal) draw() { - if term.isClosed() { - return - } term.vterm.Draw() - if term.focus && term.ctx != nil { + if term.focus { y, x, style, vis := term.vterm.Cursor() - if vis { - term.ctx.SetCursor(x, y) - term.ctx.SetCursorStyle(style) + if vis && !term.isClosed() { + ctx.SetCursor(x, y) + ctx.SetCursorStyle(style) } else { - term.ctx.HideCursor() + ctx.HideCursor() } } } +func (term *Terminal) Show(visible bool) { + term.visible = visible +} + func (term *Terminal) MouseEvent(localX int, localY int, event tcell.Event) { ev, ok := event.(*tcell.EventMouse) if !ok { -- cgit