From 340af463cd9c52c0a3a7ea5688035bba1cd29f6a Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 10 Jan 2017 01:04:36 +0900 Subject: [PATCH] Add --min-height option for percent --height --- man/man1/fzf.1 | 4 ++++ src/options.go | 10 +++++++++- src/terminal.go | 9 +++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index 1bcfb63..98c1c79 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -138,6 +138,10 @@ Label characters for \fBjump\fR and \fBjump-accept\fR Display fzf window below the cursor with the given height instead of using fullscreen. .TP +.BI "--min-height=" "HEIGHT" +Minimum height when \fB--height\fR is given in percent (default: 10). +Ignored when \fB--height\fR is not specified. +.TP .B "--reverse" Reverse orientation .TP diff --git a/src/options.go b/src/options.go index f34ee84..cbb0155 100644 --- a/src/options.go +++ b/src/options.go @@ -50,6 +50,8 @@ const usage = `usage: fzf [options] Layout --height=HEIGHT[%] Display fzf window below the cursor with the given height instead of using fullscreen + --min-height=HEIGHT Minimum height when --height is given in percent + (default: 10) --reverse Reverse orientation --margin=MARGIN Screen margin (TRBL / TB,RL / T,RL,B / T,R,B,L) --inline-info Display finder info inline with the query @@ -153,6 +155,7 @@ type Options struct { Black bool Bold bool Height sizeSpec + MinHeight int Reverse bool Cycle bool Hscroll bool @@ -200,6 +203,7 @@ func defaultOptions() *Options { Theme: tui.EmptyTheme(), Black: false, Bold: true, + MinHeight: 10, Reverse: false, Cycle: false, Hscroll: true, @@ -1023,7 +1027,9 @@ func parseOptions(opts *Options, allArgs []string) { parsePreviewWindow(&opts.Preview, nextString(allArgs, &i, "preview window layout required: [up|down|left|right][:SIZE[%]][:wrap][:hidden]")) case "--height": - opts.Height = parseHeight(nextString(allArgs, &i, "height required: [HEIGHT[%]]")) + opts.Height = parseHeight(nextString(allArgs, &i, "height required: HEIGHT[%]")) + case "--min-height": + opts.MinHeight = nextInt(allArgs, &i, "height required: HEIGHT") case "--no-height": opts.Height = sizeSpec{} case "--no-margin": @@ -1054,6 +1060,8 @@ func parseOptions(opts *Options, allArgs []string) { opts.Sort = 1 // Don't care } else if match, value := optString(arg, "--height="); match { opts.Height = parseHeight(value) + } else if match, value := optString(arg, "--min-height="); match { + opts.MinHeight = atoi(value) } else if match, value := optString(arg, "--toggle-sort="); match { parseToggleSort(opts.Keymap, value) } else if match, value := optString(arg, "--expect="); match { diff --git a/src/terminal.go b/src/terminal.go index c653327..ce63adf 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -275,14 +275,15 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal { maxHeightFunc := func(termHeight int) int { var maxHeight int if opts.Height.percent { - maxHeight = int(opts.Height.size * float64(termHeight) / 100.0) + maxHeight = util.Min(termHeight, + util.Max(int(opts.Height.size*float64(termHeight)/100.0), opts.MinHeight)) } else { - maxHeight = util.Min(int(opts.Height.size), termHeight) + maxHeight = util.Min(termHeight, int(opts.Height.size)) } if opts.InlineInfo { - return util.Max(maxHeight, 3) + return util.Max(maxHeight, minHeight-1) } - return util.Max(maxHeight, 4) + return util.Max(maxHeight, minHeight) } renderer = tui.NewLightRenderer(opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, maxHeightFunc) } else {