Merge branch 'rework-draw-system' of sloum/bombadillo into master
Merging in changes to increase response speed of application on slower terminal systems. Mostly modest changes that make sense for the codebase.
This commit is contained in:
commit
309a5e60f0
|
@ -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
|
// DrawAllWindows loops over every window in the Screen struct and
|
||||||
// draws it to screen in index order (smallest to largest)
|
// draws it to screen in index order (smallest to largest)
|
||||||
func (s Screen) DrawAllWindows() {
|
func (s Screen) DrawAllWindows() {
|
||||||
s.Clear()
|
|
||||||
for _, w := range s.Windows {
|
for _, w := range s.Windows {
|
||||||
if w.Show {
|
if w.Show {
|
||||||
w.DrawWindow()
|
w.DrawWindow()
|
||||||
|
@ -56,20 +55,25 @@ 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
|
// ReflashScreen checks for a screen resize and resizes windows if
|
||||||
// needed then redraws the screen. It takes a bool to decide whether
|
// needed then redraws the screen. It takes a bool to decide whether
|
||||||
// to redraw the full screen or just the content. On a resize
|
// to redraw the full screen or just the content. On a resize
|
||||||
// event, the full screen will always be redrawn.
|
// event, the full screen will always be redrawn.
|
||||||
func (s *Screen) ReflashScreen(clearScreen bool) {
|
func (s *Screen) ReflashScreen(clearScreen bool) {
|
||||||
|
s.DrawAllWindows()
|
||||||
|
|
||||||
if clearScreen {
|
if clearScreen {
|
||||||
s.DrawAllWindows()
|
|
||||||
s.DrawMsgBars()
|
s.DrawMsgBars()
|
||||||
} else {
|
s.ClearCommandArea()
|
||||||
for _, w := range s.Windows {
|
|
||||||
if w.Show {
|
|
||||||
w.DrawWindow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,14 +81,9 @@ func (s *Screen) ReflashScreen(clearScreen bool) {
|
||||||
// All MsgBars are looped over and drawn in index order (sm - lg).
|
// All MsgBars are looped over and drawn in index order (sm - lg).
|
||||||
func (s *Screen) DrawMsgBars() {
|
func (s *Screen) DrawMsgBars() {
|
||||||
for _, bar := range s.Bars {
|
for _, bar := range s.Bars {
|
||||||
MoveCursorTo(bar.row, 1)
|
|
||||||
Clear("line")
|
|
||||||
fmt.Print("\033[7m")
|
fmt.Print("\033[7m")
|
||||||
fmt.Print(strings.Repeat(" ", s.Width))
|
|
||||||
MoveCursorTo(bar.row, 1)
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
title := bar.title
|
title := bar.title
|
||||||
fmt.Print(title)
|
|
||||||
if len(bar.title) > s.Width {
|
if len(bar.title) > s.Width {
|
||||||
title = string(bar.title[:s.Width-3]) + "..."
|
title = string(bar.title[:s.Width-3]) + "..."
|
||||||
}
|
}
|
||||||
|
@ -94,6 +93,10 @@ func (s *Screen) DrawMsgBars() {
|
||||||
msg = string(bar.message[:s.Width-len(title)-3]) + "..."
|
msg = string(bar.message[:s.Width-len(title)-3]) + "..."
|
||||||
}
|
}
|
||||||
_, _ = buf.WriteString(msg)
|
_, _ = buf.WriteString(msg)
|
||||||
|
if buf.Len() < s.Width {
|
||||||
|
wsLength := s.Width - buf.Len()
|
||||||
|
_,_ = buf.WriteString(strings.Repeat(" ", wsLength))
|
||||||
|
}
|
||||||
|
|
||||||
MoveCursorTo(bar.row, 1)
|
MoveCursorTo(bar.row, 1)
|
||||||
fmt.Print(buf.String())
|
fmt.Print(buf.String())
|
||||||
|
|
Loading…
Reference in New Issue