From b9c68b4bd54fadb32d9e0a6d915c72d4e683c07c Mon Sep 17 00:00:00 2001 From: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com> Date: Fri, 14 Apr 2023 13:06:04 +0200 Subject: [PATCH] Fix wrap around issues with inplace logging (#334) ## Changes We deal with wraparounds for long lines of text in a bad way. This PR fixes that by saving the cursor position ## Tests Manually --- libs/cmdio/logger.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/cmdio/logger.go b/libs/cmdio/logger.go index f2d19f03..bc20cb59 100644 --- a/libs/cmdio/logger.go +++ b/libs/cmdio/logger.go @@ -46,9 +46,16 @@ func (l *Logger) Log(event Event) { switch l.Mode { case flags.ModeInplace: if l.isFirstEvent { - l.Writer.Write([]byte("\n")) + // save cursor location + l.Writer.Write([]byte("\033[s")) } - l.Writer.Write([]byte("\033[1F")) + + // move cursor to saved location + l.Writer.Write([]byte("\033[u")) + + // clear from cursor to end of screen + l.Writer.Write([]byte("\033[0J")) + l.Writer.Write([]byte(event.String())) l.Writer.Write([]byte("\n"))