mirror of
https://github.com/junegunn/fzf.git
synced 2025-07-26 09:42:02 -07:00
Set the default value of --min-height depending on other options
This commit is contained in:
@@ -93,7 +93,7 @@ fzf --height=40% --layout=reverse --info=inline --border --margin=1 --padding=1
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
*(See `Layout` section of the man page to see the full list of options)*
|
*(See man page to see the full list of options)*
|
||||||
|
|
||||||
But you definitely don't want to repeat `--height=40% --layout=reverse
|
But you definitely don't want to repeat `--height=40% --layout=reverse
|
||||||
--info=inline --border --margin=1 --padding=1` every time you use fzf. You
|
--info=inline --border --margin=1 --padding=1` every time you use fzf. You
|
||||||
|
@@ -70,7 +70,7 @@ Usage: fzf [options]
|
|||||||
If prefixed with '~', fzf will determine the height
|
If prefixed with '~', fzf will determine the height
|
||||||
according to the input size.
|
according to the input size.
|
||||||
--min-height=HEIGHT Minimum height for percent --height is given in percent
|
--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+)
|
--tmux[=OPTS] Start fzf in a tmux popup (requires tmux 3.3+)
|
||||||
[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]
|
[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]
|
||||||
[,border-native] (default: center,50%)
|
[,border-native] (default: center,50%)
|
||||||
@@ -673,7 +673,7 @@ func defaultOptions() *Options {
|
|||||||
Theme: theme,
|
Theme: theme,
|
||||||
Black: false,
|
Black: false,
|
||||||
Bold: true,
|
Bold: true,
|
||||||
MinHeight: 10,
|
MinHeight: -1,
|
||||||
Layout: layoutDefault,
|
Layout: layoutDefault,
|
||||||
Cycle: false,
|
Cycle: false,
|
||||||
Wrap: false,
|
Wrap: false,
|
||||||
@@ -3038,6 +3038,21 @@ func validateOptions(opts *Options) error {
|
|||||||
return nil
|
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.
|
// This function can have side-effects and alter some global states.
|
||||||
// So we run it on fzf.Run and not on ParseOptions.
|
// So we run it on fzf.Run and not on ParseOptions.
|
||||||
func postProcessOptions(opts *Options) error {
|
func postProcessOptions(opts *Options) error {
|
||||||
@@ -3203,6 +3218,37 @@ func postProcessOptions(opts *Options) error {
|
|||||||
opts.Height = heightSpec{}
|
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 {
|
if err := opts.initProfiling(); err != nil {
|
||||||
return errors.New("failed to start pprof profiles: " + err.Error())
|
return errors.New("failed to start pprof profiles: " + err.Error())
|
||||||
}
|
}
|
||||||
|
@@ -799,7 +799,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
|
|||||||
if previewBox != nil && opts.Preview.aboveOrBelow() {
|
if previewBox != nil && opts.Preview.aboveOrBelow() {
|
||||||
effectiveMinHeight += 1 + borderLines(opts.Preview.Border())
|
effectiveMinHeight += 1 + borderLines(opts.Preview.Border())
|
||||||
}
|
}
|
||||||
if noSeparatorLine(opts.InfoStyle, opts.Separator == nil || uniseg.StringWidth(*opts.Separator) > 0) {
|
if opts.noSeparatorLine() {
|
||||||
effectiveMinHeight--
|
effectiveMinHeight--
|
||||||
}
|
}
|
||||||
effectiveMinHeight += borderLines(opts.BorderShape)
|
effectiveMinHeight += borderLines(opts.BorderShape)
|
||||||
@@ -1264,16 +1264,6 @@ func (t *Terminal) parsePrompt(prompt string) (func(), int) {
|
|||||||
return output, promptLen
|
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 {
|
func (t *Terminal) noSeparatorLine() bool {
|
||||||
return noSeparatorLine(t.infoStyle, t.separatorLen > 0)
|
return noSeparatorLine(t.infoStyle, t.separatorLen > 0)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user