Skip to content
Myr

Add support for negative --height

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

fzf --height=-1 Close #3487

authored by Junegunn Choi · committed by Junegunn Choi · parent 87fc1c8 · Browse files · 5 files+44 added−9 removed
This commit

State

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

Diff stats

5 files+44 added−9 removed

  • other:+44 added−9 removed

5 files+44 added−9 removed

modified:man/man1/fzf.1+16 added-4 removed
19 unmodified lines
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22THE SOFTWARE.23..24.TH fzf 1 "Nov 2023" "fzf 0.44.1" "fzf - a command-line fuzzy finder"24.TH fzf 1 "Dec 2023" "fzf 0.45.0" "fzf - a command-line fuzzy finder"2526.SH NAME27fzf - a command-line fuzzy finder28
162 unmodified lines
191.SS Layout192.TP193.BI "--height=" "[~]HEIGHT[%]"194Display fzf window below the cursor with the given height instead of using195the full screen. When prefixed with \fB~\fR, fzf will automatically determine196the height in the range according to the input size. Note that adaptive height197is not compatible with top/bottom margin and padding given in percent size.195the full screen.196197If a negative value is specified, the height is calculated as the terminal198height minus the given value.199200 fzf --height=-1201202When prefixed with \fB~\fR, fzf will automatically determine the height in the203range according to the input size. Note that adaptive height is not compatible204with top/bottom margin and padding given in percent size. It is also not205compatible with a negative height value.206207 # Will not take up 100% of the screen208 seq 5 | fzf --height=~100%209210.TP211.BI "--min-height=" "HEIGHT"212Minimum height when \fB--height\fR is given in percent (default: 10).213Ignored when \fB--height\fR is not specified.
1168 unmodified lines
modified:src/core.go+1 added-1 removed
198 unmodified lines
199 maxFit := 0 // Maximum number of items that can fit on screen200 padHeight := 0201 heightUnknown := opts.Height.auto202 if heightUnknown {203 maxFit, padHeight = terminal.MaxFitAndPad(opts)203 maxFit, padHeight = terminal.MaxFitAndPad()204 }205 deferred := opts.Select1 || opts.Exit0206 go terminal.Loop()207 if !deferred && !heightUnknown {
171 unmodified lines
modified:src/options.go+10 added
55 unmodified lines
5657 Layout58 --height=[~]HEIGHT[%] Display fzf window below the cursor with the given59 height instead of using fullscreen.60 A negative value is calcalated as the terminal height61 minus the given value.62 If prefixed with '~', fzf will determine the height63 according to the input size.64 --min-height=HEIGHT Minimum height when --height is given in percent65 (default: 10)
92 unmodified lines
158type heightSpec struct {159 size float64160 percent bool161 auto bool162 inverse bool163}164165type sizeSpec struct {166 size float64
1221 unmodified lines
1388 if strings.HasPrefix(str, "~") {1389 heightSpec.auto = true1390 str = str[1:]1391 }1392 if strings.HasPrefix(str, "-") {1393 if heightSpec.auto {1394 errorExit("negative(-) height is not compatible with adaptive(~) height")1395 }1396 heightSpec.inverse = true1397 str = str[1:]1398 }13991400 size := parseSize(str, 100, "height")1401 heightSpec.size = size.size1402 heightSpec.percent = size.percent
769 unmodified lines
modified:src/terminal.go+10 added-3 removed
592 unmodified lines
593 return []string{`-`, `\`, `|`, `/`, `-`, `\`, `|`, `/`}594}595596func evaluateHeight(opts *Options, termHeight int) int {597 size := opts.Height.size598 if opts.Height.percent {599 if opts.Height.inverse {600 size = 100 - size601 }598 return util.Max(int(opts.Height.size*float64(termHeight)/100.0), opts.MinHeight)602 return util.Max(int(size*float64(termHeight)/100.0), opts.MinHeight)603 }604 if opts.Height.inverse {605 size = float64(termHeight) - size606 }600 return int(opts.Height.size)607 return int(size)608}609610// NewTerminal returns new Terminal object611func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
213 unmodified lines
825 }826 return extra827}828822func (t *Terminal) MaxFitAndPad(opts *Options) (int, int) {829func (t *Terminal) MaxFitAndPad() (int, int) {830 _, screenHeight, marginInt, paddingInt := t.adjustMarginAndPadding()831 padHeight := marginInt[0] + marginInt[2] + paddingInt[0] + paddingInt[2]832 fit := screenHeight - padHeight - t.extraLines()833 return fit, padHeight
3236 unmodified lines
modified:CHANGELOG.md+7 added-1 removed
1CHANGELOG2=========340.44.240.45.05------6- Added support for negative height7 ```sh8 # Terminal height minus 1, so you can still see the command line9 fzf --height=-110 ```11 - This handles a terminal resize better than `--height=$(($(tput lines) - 1))`12- Added `accept-or-print-query` action that acts like `accept` but prints the13 current query when there's no match for the query14 ```sh15 # You can make CTRL-R paste the current query when there's no match
1774 unmodified lines