diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2017-01-09 19:09:30 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2017-01-09 19:09:30 +0900 |
commit | 78a3f81972312d13d50e5b24dcabaa40284566b5 (patch) | |
tree | a817579db443d734caba820cdc08013ecb17e7c5 /src/tui | |
parent | d18b8e0d2c9987322e3a17b72a1db6c497cee947 (diff) |
Do not use \e[s and \e[u
Excerpt from http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html:
> - Save cursor position:
> \033[s
> - Restore cursor position:
> \033[u
>
> The latter two codes are NOT honoured by many terminal emulators. The
> only ones that I'm aware of that do are xterm and nxterm - even though
> the majority of terminal emulators are based on xterm code. As far as
> I can tell, rxvt, kvt, xiterm, and Eterm do not support them. They are
> supported on the console.
They are also unsupported by Neovim terminal.
Diffstat (limited to 'src/tui')
-rw-r--r-- | src/tui/light.go | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/src/tui/light.go b/src/tui/light.go index 1273c8fb..379680c1 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -33,7 +33,7 @@ func (r *LightRenderer) stderr(str string) { runes := []rune{} for len(bytes) > 0 { r, sz := utf8.DecodeRune(bytes) - if r == utf8.RuneError || r != '\x1b' && r != '\n' && r < 32 { + if r == utf8.RuneError || r != '\x1b' && r != '\n' && r != '\r' && r < 32 { runes = append(runes, '?') } else { runes = append(runes, r) @@ -71,6 +71,8 @@ type LightRenderer struct { escDelay int upOneLine bool queued string + y int + x int maxHeightFunc func(int) int } @@ -182,10 +184,29 @@ func (r *LightRenderer) Init() { } r.csi(fmt.Sprintf("%dA", r.MaxY()-1)) r.csi("G") - r.csi("s") + // r.csi("s") r.yoffset, _ = r.findOffset() } +func (r *LightRenderer) move(y int, x int) { + // w.csi("u") + if r.y < y { + r.csi(fmt.Sprintf("%dB", y-r.y)) + } else if r.y > y { + r.csi(fmt.Sprintf("%dA", r.y-y)) + } + r.stderr("\r") + if x > 0 { + r.csi(fmt.Sprintf("%dC", x)) + } + r.y = y + r.x = x +} + +func (r *LightRenderer) origin() { + r.move(0, 0) +} + func (r *LightRenderer) updateTerminalSize() { sizes := strings.Split(stty("size"), " ") if len(sizes) < 2 { @@ -470,7 +491,8 @@ func (r *LightRenderer) Resume() bool { } func (r *LightRenderer) Clear() { - r.csi("u") + // r.csi("u") + r.origin() r.csi("J") r.flush() } @@ -484,7 +506,8 @@ func (r *LightRenderer) Refresh() { } func (r *LightRenderer) Close() { - r.csi("u") + // r.csi("u") + r.origin() r.csi("J") if r.mouse { r.csi("?1000l") @@ -584,15 +607,7 @@ func (w *LightWindow) Move(y int, x int) { w.posx = x w.posy = y - w.csi("u") - y += w.Top() - if y > 0 { - w.csi(fmt.Sprintf("%dB", y)) - } - x += w.Left() - if x > 0 { - w.csi(fmt.Sprintf("%dC", x)) - } + w.renderer.move(w.Top()+y, w.Left()+x) } func (w *LightWindow) MoveAndClear(y int, x int) { |