From ede7bfb90105b7df5bf115a837e307ac3f2540fe Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 16 Jan 2017 02:26:36 +0900 Subject: Optimize LightRenderer for slow terminals --- src/tui/light.go | 23 ++++++++++++++++++----- src/tui/ncurses.go | 4 ++++ src/tui/tcell.go | 4 ++++ src/tui/tui.go | 1 + 4 files changed, 27 insertions(+), 5 deletions(-) (limited to 'src/tui') diff --git a/src/tui/light.go b/src/tui/light.go index 2e99aa3f..075fd6bc 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -32,13 +32,18 @@ func openTtyIn() *os.File { return in } -// FIXME: Need better handling of non-displayable characters func (r *LightRenderer) stderr(str string) { + r.stderrInternal(str, true) +} + +// FIXME: Need better handling of non-displayable characters +func (r *LightRenderer) stderrInternal(str string, allowNLCR bool) { bytes := []byte(str) runes := []rune{} for len(bytes) > 0 { r, sz := utf8.DecodeRune(bytes) - if r == utf8.RuneError || r != '\x1b' && r != '\n' && r != '\r' && r < 32 { + if r == utf8.RuneError || r < 32 && + r != '\x1b' && (!allowNLCR || r != '\n' && r != '\r') { runes = append(runes, '?') } else { runes = append(runes, r) @@ -553,6 +558,10 @@ func (r *LightRenderer) DoesAutoWrap() bool { return true } +func (r *LightRenderer) IsOptimized() bool { + return false +} + func (r *LightRenderer) NewWindow(top int, left int, width int, height int, border bool) Window { w := &LightWindow{ renderer: r, @@ -594,6 +603,10 @@ func (w *LightWindow) stderr(str string) { w.renderer.stderr(str) } +func (w *LightWindow) stderrInternal(str string, allowNLCR bool) { + w.renderer.stderrInternal(str, allowNLCR) +} + func (w *LightWindow) Top() int { return w.top } @@ -703,7 +716,7 @@ func (w *LightWindow) CPrint(pair ColorPair, attr Attr, text string) { } else { w.csiColor(pair.Fg(), pair.Bg(), attr) } - w.stderr(text) + w.stderrInternal(text, false) w.csi("m") } @@ -711,7 +724,7 @@ func (w *LightWindow) cprint2(fg Color, bg Color, attr Attr, text string) { if w.csiColor(fg, bg, attr) { defer w.csi("m") } - w.stderr(text) + w.stderrInternal(text, false) } type wrappedLine struct { @@ -754,7 +767,7 @@ func (w *LightWindow) fill(str string, onMove func()) FillReturn { } return FillNextLine } - w.stderr(wl.text) + w.stderrInternal(wl.text, false) w.posx += wl.displayWidth if j < len(lines)-1 || i < len(allLines)-1 { if w.posy+1 >= w.height { diff --git a/src/tui/ncurses.go b/src/tui/ncurses.go index db7cd83f..0978ea8a 100644 --- a/src/tui/ncurses.go +++ b/src/tui/ncurses.go @@ -279,6 +279,10 @@ func (r *FullscreenRenderer) DoesAutoWrap() bool { return true } +func (r *FullscreenRenderer) IsOptimized() bool { + return true +} + func (w *CursesWindow) Fill(str string) FillReturn { if C.waddstr(w.impl, C.CString(str)) == C.OK { return FillContinue diff --git a/src/tui/tcell.go b/src/tui/tcell.go index 8de6fe35..c898a383 100644 --- a/src/tui/tcell.go +++ b/src/tui/tcell.go @@ -158,6 +158,10 @@ func (r *FullscreenRenderer) DoesAutoWrap() bool { return false } +func (r *FullscreenRenderer) IsOptimized() bool { + return false +} + func (r *FullscreenRenderer) Clear() { _screen.Sync() _screen.Clear() diff --git a/src/tui/tui.go b/src/tui/tui.go index 4760a382..fd4a21e3 100644 --- a/src/tui/tui.go +++ b/src/tui/tui.go @@ -204,6 +204,7 @@ type Renderer interface { MaxX() int MaxY() int DoesAutoWrap() bool + IsOptimized() bool NewWindow(top int, left int, width int, height int, border bool) Window } -- cgit v1.2.3