From d83517f67ba638abed1d76541068413e60142194 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Thu, 26 Dec 2024 18:41:29 +0100 Subject: Refresh task view dynamically with Javascript This is more efficient, responsive, and user friendly. --- terminal.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'terminal.go') diff --git a/terminal.go b/terminal.go index 4660c1b..55eabb5 100644 --- a/terminal.go +++ b/terminal.go @@ -47,6 +47,16 @@ func (tw *terminalWriter) log(format string, v ...interface{}) { } } +// SerializeUpdates returns an update block for a client with a given last line, +// and the index of the first line in the update block. +func (tw *terminalWriter) SerializeUpdates(last int) (string, int) { + if last < 0 || last >= len(tw.lines) { + return "", last + } + top := tw.lines[last].updateGroup + return string(tw.Serialize(top)), top +} + func (tw *terminalWriter) Serialize(top int) []byte { var b bytes.Buffer for i := top; i < len(tw.lines); i++ { @@ -104,7 +114,7 @@ func (tw *terminalWriter) processPrint(r rune) { // Refresh update trackers, if necessary. if tw.lines[len(tw.lines)-1].updateGroup > tw.line { for i := tw.line; i < len(tw.lines); i++ { - tw.lines[i].updateGroup = tw.line + tw.lines[i].updateGroup = min(tw.lines[i].updateGroup, tw.line) } } -- cgit v1.2.3-70-g09d2