Skip to content
Myr

Use alternate screen if --height needs the entire screen

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Remove unnecessary scrolling - Allow us to use `--height 100%` under Neovim terminal for 24-bit colors Related: - #789 - https://github.com/neovim/neovim/issues/4151

authored by Junegunn Choi · committed by Junegunn Choi · parent 2a669e9 · Browse files · 1 file+55 added−20 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+55 added−20 removed

  • other:+55 added−20 removed

1 file+55 added−20 removed

modified:src/tui/light.go+55 added-20 removed
77 unmodified lines
78 height int79 yoffset int80 tabstop int81 escDelay int82 fullscreen bool83 upOneLine bool84 queued string85 y int86 x int
19 unmodified lines
106 theme: theme,107 forceBlack: forceBlack,108 mouse: mouse,109 ttyin: openTtyIn(),109 yoffset: -1,110 yoffset: 0,111 tabstop: tabstop,112 fullscreen: false,113 upOneLine: false,114 maxHeightFunc: maxHeightFunc}115 return &r116}
63 unmodified lines
180 errorExit(err.Error())181 }182 r.origState = origState183 terminal.MakeRaw(fd)182 r.updateTerminalSize()184 terminalHeight, capHeight := r.updateTerminalSize()185 if capHeight == terminalHeight {186 r.fullscreen = true187 r.height = terminalHeight188 }189 initTheme(r.theme, r.defaultTheme(), r.forceBlack)190191 if r.fullscreen {192 r.smcup()193 } else {185 _, x := r.findOffset()186 if x > 0 {187 r.upOneLine = true188 r.makeSpace()194 _, x := r.findOffset()195 if x > 0 {196 r.upOneLine = true197 r.makeSpace()198 }199 for i := 1; i < r.MaxY(); i++ {200 r.makeSpace()201 }202 }190 for i := 1; i < r.MaxY(); i++ {191 r.makeSpace()192 }203204 if r.mouse {205 r.csi("?1000h")206 }207 r.csi(fmt.Sprintf("%dA", r.MaxY()-1))208 r.csi("G")209 r.csi("K")210 // r.csi("s")201 if r.mouse {211 if !r.fullscreen && r.mouse {212 r.yoffset, _ = r.findOffset()213 }214}215
29 unmodified lines
245 }246 return atoi(env, defaultValue)247}248239func (r *LightRenderer) updateTerminalSize() {249func (r *LightRenderer) updateTerminalSize() (int, int) {250 width, height, err := terminal.GetSize(r.fd())251 if err == nil {252 r.width = width253 if r.fullscreen {254 r.height = height255 } else {243 r.height = r.maxHeightFunc(height)256 r.height = r.maxHeightFunc(height)257 }258 } else {259 r.width = getEnv("COLUMNS", defaultWidth)260 r.height = r.maxHeightFunc(getEnv("LINES", defaultHeight))261 }262 return height, r.height263}264265func (r *LightRenderer) getch(nonblock bool) (int, bool) {266 b := make([]byte, 1)
217 unmodified lines
484 return Event{Invalid, 0, nil}485}486487func (r *LightRenderer) mouseSequence(sz *int) Event {473 if len(r.buffer) < 6 || r.yoffset < 0 {488 if len(r.buffer) < 6 || !r.mouse {489 return Event{Invalid, 0, nil}490 }491 *sz = 6492 switch r.buffer[3] {
30 unmodified lines
523 }524 return Event{Invalid, 0, nil}525}526527func (r *LightRenderer) smcup() {528 r.csi("?1049h")529}530531func (r *LightRenderer) rmcup() {532 r.csi("?1049l")533}534535func (r *LightRenderer) Pause() {536 terminal.Restore(r.fd(), r.origState)514 r.csi("?1049h")537 if r.fullscreen {538 r.rmcup()539 } else {540 r.smcup()541 }542 r.flush()543}544545func (r *LightRenderer) Resume() bool {546 terminal.MakeRaw(r.fd())520 r.csi("?1049l")547 if r.fullscreen {548 r.smcup()549 } else {550 r.rmcup()551 }552 r.flush()553 // Should redraw554 return true555}
14 unmodified lines
570}571572func (r *LightRenderer) Close() {573 // r.csi("u")574 if r.fullscreen {575 r.rmcup()576 } else {543 r.origin()544 r.csi("J")577 r.origin()578 r.csi("J")579 if r.upOneLine {580 r.csi("A")581 }582 }583 if r.mouse {584 r.csi("?1000l")585 }548 if r.upOneLine {549 r.csi("A")550 }586 r.flush()587 terminal.Restore(r.fd(), r.origState)588}589
272 unmodified lines