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
Provenance
- Commit
d7b61ed- Tree
f86613d- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
87fc1c8
5 files changed+44 added−9 removed
modified:man/man1/fzf.1+16 added-4 removed
19 unmodified lines20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22 THE 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"25 26 .SH NAME27 fzf - a command-line fuzzy finder28 162 unmodified lines191 .SS Layout192 .TP193 .BI "--height=" "[~]HEIGHT[%]"194 Display fzf window below the cursor with the given height instead of using195-the full screen. When prefixed with \fB~\fR, fzf will automatically determine196-the height in the range according to the input size. Note that adaptive height197-is not compatible with top/bottom margin and padding given in percent size.195+the full screen.196+197+If a negative value is specified, the height is calculated as the terminal198+height minus the given value.199+200+ fzf --height=-1201+202+When prefixed with \fB~\fR, fzf will automatically determine the height in the203+range according to the input size. Note that adaptive height is not compatible204+with top/bottom margin and padding given in percent size. It is also not205+compatible with a negative height value.206+207+ # Will not take up 100% of the screen208+ seq 5 | fzf --height=~100%209+210 .TP211 .BI "--min-height=" "HEIGHT"212 Minimum height when \fB--height\fR is given in percent (default: 10).213 Ignored when \fB--height\fR is not specified.1168 unmodified linesmodified:src/core.go+1 added-1 removed
198 unmodified lines199 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 linesmodified:src/options.go+10 added
55 unmodified lines56 57 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 lines158 type heightSpec struct {159 size float64160 percent bool161 auto bool162+ inverse bool163 }164 165 type sizeSpec struct {166 size float641221 unmodified lines1388 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+ }1399 1400 size := parseSize(str, 100, "height")1401 heightSpec.size = size.size1402 heightSpec.percent = size.percent769 unmodified linesmodified:src/terminal.go+10 added-3 removed
592 unmodified lines593 return []string{`-`, `\`, `|`, `/`, `-`, `\`, `|`, `/`}594 }595 596 func 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 }609 610 // NewTerminal returns new Terminal object611 func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {213 unmodified lines825 }826 return extra827 }828 822-func (t *Terminal) MaxFitAndPad(opts *Options) (int, int) {829+func (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, padHeight3236 unmodified linesmodified:CHANGELOG.md+7 added-1 removed
1 CHANGELOG2 =========3 4-0.44.24+0.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 match1774 unmodified lines