summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-01-27 20:33:47 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-01-27 20:33:47 +0900
commit51c207448da6eb1cea3352d72c2d22682f604b6d (patch)
tree9b8a8a682899cae9614b481bbad00eb776caa8fd /src
parenta6a558da3090b067ca65fe3f42aca9f0e75801a3 (diff)
downloadfzf-51c207448da6eb1cea3352d72c2d22682f604b6d.tar.gz
Set the default value of --min-height depending on other options
Diffstat (limited to 'src')
-rw-r--r--src/options.go50
-rw-r--r--src/terminal.go12
2 files changed, 49 insertions, 13 deletions
diff --git a/src/options.go b/src/options.go
index 79a70825..9c0bd2ed 100644
--- a/src/options.go
+++ b/src/options.go
@@ -70,7 +70,7 @@ Usage: fzf [options]
If prefixed with '~', fzf will determine the height
according to the input size.
--min-height=HEIGHT Minimum height for percent --height is given in percent
- (default: 10)
+ (default: 10 or above depending on the other options)
--tmux[=OPTS] Start fzf in a tmux popup (requires tmux 3.3+)
[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]
[,border-native] (default: center,50%)
@@ -673,7 +673,7 @@ func defaultOptions() *Options {
Theme: theme,
Black: false,
Bold: true,
- MinHeight: 10,
+ MinHeight: -1,
Layout: layoutDefault,
Cycle: false,
Wrap: false,
@@ -3038,6 +3038,21 @@ func validateOptions(opts *Options) error {
return nil
}
+func noSeparatorLine(style infoStyle, separator bool) bool {
+ switch style {
+ case infoInline:
+ return true
+ case infoHidden, infoInlineRight:
+ return !separator
+ }
+ return false
+}
+
+func (opts *Options) noSeparatorLine() bool {
+ sep := opts.Separator == nil && !opts.InputBorderShape.Visible() || opts.Separator != nil && len(*opts.Separator) > 0
+ return noSeparatorLine(opts.InfoStyle, sep)
+}
+
// This function can have side-effects and alter some global states.
// So we run it on fzf.Run and not on ParseOptions.
func postProcessOptions(opts *Options) error {
@@ -3203,6 +3218,37 @@ func postProcessOptions(opts *Options) error {
opts.Height = heightSpec{}
}
+ // Sets --min-height automatically
+ if opts.Height.size > 0 && opts.Height.percent && opts.MinHeight < 0 {
+ // 10 items and 1 prompt line
+ opts.MinHeight = 10 + 1 + borderLines(opts.BorderShape) + borderLines(opts.ListBorderShape) + borderLines(opts.InputBorderShape)
+ if len(opts.Header) > 0 {
+ opts.MinHeight += borderLines(opts.HeaderBorderShape) + len(opts.Header)
+ }
+ if opts.HeaderLines > 0 {
+ borderShape := opts.HeaderBorderShape
+ if opts.HeaderLinesShape.Visible() {
+ borderShape = opts.HeaderLinesShape
+ }
+ opts.MinHeight += borderLines(borderShape) + opts.HeaderLines
+ }
+ if !opts.noSeparatorLine() {
+ opts.MinHeight++
+ }
+ if len(opts.Preview.command) > 0 && (opts.Preview.position == posUp || opts.Preview.position == posDown) && opts.Preview.Visible() && opts.Preview.position == posUp {
+ borderShape := opts.Preview.border
+ if opts.Preview.border == tui.BorderLine {
+ borderShape = tui.BorderTop
+ }
+ opts.MinHeight += borderLines(borderShape) + 10
+ }
+ for _, s := range []sizeSpec{opts.Margin[0], opts.Margin[2], opts.Padding[0], opts.Padding[2]} {
+ if !s.percent {
+ opts.MinHeight += int(s.size)
+ }
+ }
+ }
+
if err := opts.initProfiling(); err != nil {
return errors.New("failed to start pprof profiles: " + err.Error())
}
diff --git a/src/terminal.go b/src/terminal.go
index af6c8a8c..da3b863c 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -799,7 +799,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
if previewBox != nil && opts.Preview.aboveOrBelow() {
effectiveMinHeight += 1 + borderLines(opts.Preview.Border())
}
- if noSeparatorLine(opts.InfoStyle, opts.Separator == nil || uniseg.StringWidth(*opts.Separator) > 0) {
+ if opts.noSeparatorLine() {
effectiveMinHeight--
}
effectiveMinHeight += borderLines(opts.BorderShape)
@@ -1264,16 +1264,6 @@ func (t *Terminal) parsePrompt(prompt string) (func(), int) {
return output, promptLen
}
-func noSeparatorLine(style infoStyle, separator bool) bool {
- switch style {
- case infoInline:
- return true
- case infoHidden, infoInlineRight:
- return !separator
- }
- return false
-}
-
func (t *Terminal) noSeparatorLine() bool {
return noSeparatorLine(t.infoStyle, t.separatorLen > 0)
}