Use alternate screen only when the value of height is 100%

Do not automatically decide to use alternate screen when the value of
height exceeds the height of the terminal.

    # Use alternate screen
    fzf
    fzf --height 100%
    fzf --no-height

    # Still use current screen
    fzf --height 10000
pull/870/head
Junegunn Choi 7 years ago
parent 53348feb89
commit 6fd4be580b
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -295,7 +295,14 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
strongAttr = tui.AttrRegular strongAttr = tui.AttrRegular
} }
var renderer tui.Renderer var renderer tui.Renderer
if opts.Height.size > 0 { if opts.Height.size == 0 || opts.Height.percent && opts.Height.size == 100 {
if tui.HasFullscreenRenderer() {
renderer = tui.NewFullscreenRenderer(opts.Theme, opts.Black, opts.Mouse)
} else {
renderer = tui.NewLightRenderer(opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit,
true, func(h int) int { return h })
}
} else {
maxHeightFunc := func(termHeight int) int { maxHeightFunc := func(termHeight int) int {
var maxHeight int var maxHeight int
if opts.Height.percent { if opts.Height.percent {
@ -316,12 +323,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
} }
return util.Min(termHeight, util.Max(maxHeight, effectiveMinHeight)) return util.Min(termHeight, util.Max(maxHeight, effectiveMinHeight))
} }
renderer = tui.NewLightRenderer(opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit, maxHeightFunc) renderer = tui.NewLightRenderer(opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit, false, maxHeightFunc)
} else if tui.HasFullscreenRenderer() {
renderer = tui.NewFullscreenRenderer(opts.Theme, opts.Black, opts.Mouse)
} else {
renderer = tui.NewLightRenderer(opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit,
func(h int) int { return h })
} }
wordRubout := "[^[:alnum:]][[:alnum:]]" wordRubout := "[^[:alnum:]][[:alnum:]]"
wordNext := "[[:alnum:]][^[:alnum:]]|(.$)" wordNext := "[[:alnum:]][^[:alnum:]]|(.$)"

@ -107,7 +107,7 @@ type LightWindow struct {
bg Color bg Color
} }
func NewLightRenderer(theme *ColorTheme, forceBlack bool, mouse bool, tabstop int, clearOnExit bool, maxHeightFunc func(int) int) Renderer { func NewLightRenderer(theme *ColorTheme, forceBlack bool, mouse bool, tabstop int, clearOnExit bool, fullscreen bool, maxHeightFunc func(int) int) Renderer {
r := LightRenderer{ r := LightRenderer{
theme: theme, theme: theme,
forceBlack: forceBlack, forceBlack: forceBlack,
@ -116,7 +116,7 @@ func NewLightRenderer(theme *ColorTheme, forceBlack bool, mouse bool, tabstop in
ttyin: openTtyIn(), ttyin: openTtyIn(),
yoffset: 0, yoffset: 0,
tabstop: tabstop, tabstop: tabstop,
fullscreen: false, fullscreen: fullscreen,
upOneLine: false, upOneLine: false,
maxHeightFunc: maxHeightFunc} maxHeightFunc: maxHeightFunc}
return &r return &r
@ -176,11 +176,7 @@ func (r *LightRenderer) Init() {
} }
r.origState = origState r.origState = origState
terminal.MakeRaw(fd) terminal.MakeRaw(fd)
terminalHeight, capHeight := r.updateTerminalSize() 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)
if r.fullscreen { if r.fullscreen {
@ -242,20 +238,15 @@ func getEnv(name string, defaultValue int) int {
return atoi(env, defaultValue) return atoi(env, defaultValue)
} }
func (r *LightRenderer) updateTerminalSize() (int, int) { func (r *LightRenderer) updateTerminalSize() {
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
if r.fullscreen { r.height = r.maxHeightFunc(height)
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) {

Loading…
Cancel
Save