From 5a82541dee0afc74ba0b746d45b0dc6333f5e8d3 Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Fri, 31 May 2019 21:50:05 -0700 Subject: [PATCH 1/3] Minor reworking of the draw system. Should create less screen flicker. --- cui/screen.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cui/screen.go b/cui/screen.go index f79df2d..cb2ba53 100644 --- a/cui/screen.go +++ b/cui/screen.go @@ -39,7 +39,7 @@ func (s *Screen) AddMsgBar(row int, title, msg string, showTitle bool) { // DrawAllWindows loops over every window in the Screen struct and // draws it to screen in index order (smallest to largest) func (s Screen) DrawAllWindows() { - s.Clear() + // s.Clear() for _, w := range s.Windows { if w.Show { w.DrawWindow() @@ -77,14 +77,9 @@ func (s *Screen) ReflashScreen(clearScreen bool) { // All MsgBars are looped over and drawn in index order (sm - lg). func (s *Screen) DrawMsgBars() { for _, bar := range s.Bars { - MoveCursorTo(bar.row, 1) - Clear("line") fmt.Print("\033[7m") - fmt.Print(strings.Repeat(" ", s.Width)) - MoveCursorTo(bar.row, 1) var buf bytes.Buffer title := bar.title - fmt.Print(title) if len(bar.title) > s.Width { title = string(bar.title[:s.Width-3]) + "..." } @@ -94,6 +89,10 @@ func (s *Screen) DrawMsgBars() { msg = string(bar.message[:s.Width-len(title)-3]) + "..." } _, _ = buf.WriteString(msg) + if buf.Len() < s.Width { + wsLength := s.Width - buf.Len() + _,_ = buf.WriteString(strings.Repeat(" ", wsLength)) + } MoveCursorTo(bar.row, 1) fmt.Print(buf.String()) From 43b9953c8078475fc64c60509e8a6d2e42d40b34 Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Fri, 31 May 2019 22:34:59 -0700 Subject: [PATCH 2/3] Clarifying comment --- cui/screen.go | 17 +++++++++++------ main.go | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cui/screen.go b/cui/screen.go index cb2ba53..2db53bc 100644 --- a/cui/screen.go +++ b/cui/screen.go @@ -39,7 +39,6 @@ func (s *Screen) AddMsgBar(row int, title, msg string, showTitle bool) { // DrawAllWindows loops over every window in the Screen struct and // draws it to screen in index order (smallest to largest) func (s Screen) DrawAllWindows() { - // s.Clear() for _, w := range s.Windows { if w.Show { w.DrawWindow() @@ -56,6 +55,15 @@ func (s Screen) Clear() { } } +// Clears message/error/command area +func (s *Screen) ClearCommandArea() { + MoveCursorTo(s.Height-1, 1) + Clear("line") + MoveCursorTo(s.Height, 1) + Clear("line") + MoveCursorTo(s.Height-1, 1) +} + // ReflashScreen checks for a screen resize and resizes windows if // needed then redraws the screen. It takes a bool to decide whether // to redraw the full screen or just the content. On a resize @@ -64,12 +72,9 @@ func (s *Screen) ReflashScreen(clearScreen bool) { if clearScreen { s.DrawAllWindows() s.DrawMsgBars() + s.ClearCommandArea() } else { - for _, w := range s.Windows { - if w.Show { - w.DrawWindow() - } - } + s.DrawAllWindows() } } diff --git a/main.go b/main.go index dd6fe5f..015fe78 100644 --- a/main.go +++ b/main.go @@ -471,6 +471,7 @@ func handleResize() { screen.DrawAllWindows() screen.DrawMsgBars() + screen.ClearCommandArea() } } From 70ad392945f4883732c12988affefa516aa72052 Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Fri, 31 May 2019 22:41:48 -0700 Subject: [PATCH 3/3] Simplified method code --- cui/screen.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cui/screen.go b/cui/screen.go index 2db53bc..2513a9c 100644 --- a/cui/screen.go +++ b/cui/screen.go @@ -69,12 +69,11 @@ func (s *Screen) ClearCommandArea() { // to redraw the full screen or just the content. On a resize // event, the full screen will always be redrawn. func (s *Screen) ReflashScreen(clearScreen bool) { + s.DrawAllWindows() + if clearScreen { - s.DrawAllWindows() s.DrawMsgBars() s.ClearCommandArea() - } else { - s.DrawAllWindows() } }