mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2025-01-11 10:38:12 +00:00
Use alternate screen if --height needs the entire screen
- 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
This commit is contained in:
parent
2a669e9a17
commit
6ccc12c332
@ -79,6 +79,7 @@ type LightRenderer struct {
|
|||||||
yoffset int
|
yoffset int
|
||||||
tabstop int
|
tabstop int
|
||||||
escDelay int
|
escDelay int
|
||||||
|
fullscreen bool
|
||||||
upOneLine bool
|
upOneLine bool
|
||||||
queued string
|
queued string
|
||||||
y int
|
y int
|
||||||
@ -106,8 +107,9 @@ func NewLightRenderer(theme *ColorTheme, forceBlack bool, mouse bool, tabstop in
|
|||||||
forceBlack: forceBlack,
|
forceBlack: forceBlack,
|
||||||
mouse: mouse,
|
mouse: mouse,
|
||||||
ttyin: openTtyIn(),
|
ttyin: openTtyIn(),
|
||||||
yoffset: -1,
|
yoffset: 0,
|
||||||
tabstop: tabstop,
|
tabstop: tabstop,
|
||||||
|
fullscreen: false,
|
||||||
upOneLine: false,
|
upOneLine: false,
|
||||||
maxHeightFunc: maxHeightFunc}
|
maxHeightFunc: maxHeightFunc}
|
||||||
return &r
|
return &r
|
||||||
@ -179,16 +181,24 @@ func (r *LightRenderer) Init() {
|
|||||||
}
|
}
|
||||||
r.origState = origState
|
r.origState = origState
|
||||||
terminal.MakeRaw(fd)
|
terminal.MakeRaw(fd)
|
||||||
r.updateTerminalSize()
|
terminalHeight, capHeight := r.updateTerminalSize()
|
||||||
|
if capHeight == terminalHeight {
|
||||||
|
r.fullscreen = true
|
||||||
|
r.height = terminalHeight
|
||||||
|
}
|
||||||
initTheme(r.theme, r.defaultTheme(), r.forceBlack)
|
initTheme(r.theme, r.defaultTheme(), r.forceBlack)
|
||||||
|
|
||||||
_, x := r.findOffset()
|
if r.fullscreen {
|
||||||
if x > 0 {
|
r.smcup()
|
||||||
r.upOneLine = true
|
} else {
|
||||||
r.makeSpace()
|
_, x := r.findOffset()
|
||||||
}
|
if x > 0 {
|
||||||
for i := 1; i < r.MaxY(); i++ {
|
r.upOneLine = true
|
||||||
r.makeSpace()
|
r.makeSpace()
|
||||||
|
}
|
||||||
|
for i := 1; i < r.MaxY(); i++ {
|
||||||
|
r.makeSpace()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.mouse {
|
if r.mouse {
|
||||||
@ -198,7 +208,7 @@ func (r *LightRenderer) Init() {
|
|||||||
r.csi("G")
|
r.csi("G")
|
||||||
r.csi("K")
|
r.csi("K")
|
||||||
// r.csi("s")
|
// r.csi("s")
|
||||||
if r.mouse {
|
if !r.fullscreen && r.mouse {
|
||||||
r.yoffset, _ = r.findOffset()
|
r.yoffset, _ = r.findOffset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,15 +246,20 @@ func getEnv(name string, defaultValue int) int {
|
|||||||
return atoi(env, defaultValue)
|
return atoi(env, defaultValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LightRenderer) updateTerminalSize() {
|
func (r *LightRenderer) updateTerminalSize() (int, int) {
|
||||||
width, height, err := terminal.GetSize(r.fd())
|
width, height, err := terminal.GetSize(r.fd())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
r.width = width
|
r.width = width
|
||||||
r.height = r.maxHeightFunc(height)
|
if r.fullscreen {
|
||||||
|
r.height = height
|
||||||
|
} else {
|
||||||
|
r.height = r.maxHeightFunc(height)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
r.width = getEnv("COLUMNS", defaultWidth)
|
r.width = getEnv("COLUMNS", defaultWidth)
|
||||||
r.height = r.maxHeightFunc(getEnv("LINES", defaultHeight))
|
r.height = r.maxHeightFunc(getEnv("LINES", defaultHeight))
|
||||||
}
|
}
|
||||||
|
return height, r.height
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LightRenderer) getch(nonblock bool) (int, bool) {
|
func (r *LightRenderer) getch(nonblock bool) (int, bool) {
|
||||||
@ -470,7 +485,7 @@ func (r *LightRenderer) escSequence(sz *int) Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *LightRenderer) mouseSequence(sz *int) Event {
|
func (r *LightRenderer) mouseSequence(sz *int) Event {
|
||||||
if len(r.buffer) < 6 || r.yoffset < 0 {
|
if len(r.buffer) < 6 || !r.mouse {
|
||||||
return Event{Invalid, 0, nil}
|
return Event{Invalid, 0, nil}
|
||||||
}
|
}
|
||||||
*sz = 6
|
*sz = 6
|
||||||
@ -509,15 +524,31 @@ func (r *LightRenderer) mouseSequence(sz *int) Event {
|
|||||||
return Event{Invalid, 0, nil}
|
return Event{Invalid, 0, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) smcup() {
|
||||||
|
r.csi("?1049h")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) rmcup() {
|
||||||
|
r.csi("?1049l")
|
||||||
|
}
|
||||||
|
|
||||||
func (r *LightRenderer) Pause() {
|
func (r *LightRenderer) Pause() {
|
||||||
terminal.Restore(r.fd(), r.origState)
|
terminal.Restore(r.fd(), r.origState)
|
||||||
r.csi("?1049h")
|
if r.fullscreen {
|
||||||
|
r.rmcup()
|
||||||
|
} else {
|
||||||
|
r.smcup()
|
||||||
|
}
|
||||||
r.flush()
|
r.flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LightRenderer) Resume() bool {
|
func (r *LightRenderer) Resume() bool {
|
||||||
terminal.MakeRaw(r.fd())
|
terminal.MakeRaw(r.fd())
|
||||||
r.csi("?1049l")
|
if r.fullscreen {
|
||||||
|
r.smcup()
|
||||||
|
} else {
|
||||||
|
r.rmcup()
|
||||||
|
}
|
||||||
r.flush()
|
r.flush()
|
||||||
// Should redraw
|
// Should redraw
|
||||||
return true
|
return true
|
||||||
@ -540,14 +571,18 @@ func (r *LightRenderer) Refresh() {
|
|||||||
|
|
||||||
func (r *LightRenderer) Close() {
|
func (r *LightRenderer) Close() {
|
||||||
// r.csi("u")
|
// r.csi("u")
|
||||||
r.origin()
|
if r.fullscreen {
|
||||||
r.csi("J")
|
r.rmcup()
|
||||||
|
} else {
|
||||||
|
r.origin()
|
||||||
|
r.csi("J")
|
||||||
|
if r.upOneLine {
|
||||||
|
r.csi("A")
|
||||||
|
}
|
||||||
|
}
|
||||||
if r.mouse {
|
if r.mouse {
|
||||||
r.csi("?1000l")
|
r.csi("?1000l")
|
||||||
}
|
}
|
||||||
if r.upOneLine {
|
|
||||||
r.csi("A")
|
|
||||||
}
|
|
||||||
r.flush()
|
r.flush()
|
||||||
terminal.Restore(r.fd(), r.origState)
|
terminal.Restore(r.fd(), r.origState)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user