mirror of
https://github.com/junegunn/fzf.git
synced 2026-01-20 18:14:41 +08:00
@@ -200,7 +200,7 @@ func Run(opts *Options, version string, revision string) {
|
||||
padHeight := 0
|
||||
heightUnknown := opts.Height.auto
|
||||
if heightUnknown {
|
||||
maxFit, padHeight = terminal.MaxFitAndPad(opts)
|
||||
maxFit, padHeight = terminal.MaxFitAndPad()
|
||||
}
|
||||
deferred := opts.Select1 || opts.Exit0
|
||||
go terminal.Loop()
|
||||
|
||||
@@ -57,6 +57,8 @@ const usage = `usage: fzf [options]
|
||||
Layout
|
||||
--height=[~]HEIGHT[%] Display fzf window below the cursor with the given
|
||||
height instead of using fullscreen.
|
||||
A negative value is calcalated as the terminal height
|
||||
minus the given value.
|
||||
If prefixed with '~', fzf will determine the height
|
||||
according to the input size.
|
||||
--min-height=HEIGHT Minimum height when --height is given in percent
|
||||
@@ -157,6 +159,7 @@ type heightSpec struct {
|
||||
size float64
|
||||
percent bool
|
||||
auto bool
|
||||
inverse bool
|
||||
}
|
||||
|
||||
type sizeSpec struct {
|
||||
@@ -1386,6 +1389,13 @@ func parseHeight(str string) heightSpec {
|
||||
heightSpec.auto = true
|
||||
str = str[1:]
|
||||
}
|
||||
if strings.HasPrefix(str, "-") {
|
||||
if heightSpec.auto {
|
||||
errorExit("negative(-) height is not compatible with adaptive(~) height")
|
||||
}
|
||||
heightSpec.inverse = true
|
||||
str = str[1:]
|
||||
}
|
||||
|
||||
size := parseSize(str, 100, "height")
|
||||
heightSpec.size = size.size
|
||||
|
||||
@@ -594,10 +594,17 @@ func makeSpinner(unicode bool) []string {
|
||||
}
|
||||
|
||||
func evaluateHeight(opts *Options, termHeight int) int {
|
||||
size := opts.Height.size
|
||||
if opts.Height.percent {
|
||||
return util.Max(int(opts.Height.size*float64(termHeight)/100.0), opts.MinHeight)
|
||||
if opts.Height.inverse {
|
||||
size = 100 - size
|
||||
}
|
||||
return util.Max(int(size*float64(termHeight)/100.0), opts.MinHeight)
|
||||
}
|
||||
return int(opts.Height.size)
|
||||
if opts.Height.inverse {
|
||||
size = float64(termHeight) - size
|
||||
}
|
||||
return int(size)
|
||||
}
|
||||
|
||||
// NewTerminal returns new Terminal object
|
||||
@@ -819,7 +826,7 @@ func (t *Terminal) extraLines() int {
|
||||
return extra
|
||||
}
|
||||
|
||||
func (t *Terminal) MaxFitAndPad(opts *Options) (int, int) {
|
||||
func (t *Terminal) MaxFitAndPad() (int, int) {
|
||||
_, screenHeight, marginInt, paddingInt := t.adjustMarginAndPadding()
|
||||
padHeight := marginInt[0] + marginInt[2] + paddingInt[0] + paddingInt[2]
|
||||
fit := screenHeight - padHeight - t.extraLines()
|
||||
|
||||
Reference in New Issue
Block a user