mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2025-02-02 12:08:34 +00:00
Enhance --min-height option to take number followed by +
This commit is contained in:
parent
b83dd6c6b4
commit
eb0257d48f
@ -53,6 +53,15 @@ CHANGELOG
|
|||||||
# Load 'ps -ef' output on start and reload it on CTRL-R
|
# Load 'ps -ef' output on start and reload it on CTRL-R
|
||||||
fzf --bind 'start,ctrl-r:reload:ps -ef'
|
fzf --bind 'start,ctrl-r:reload:ps -ef'
|
||||||
```
|
```
|
||||||
|
- `--min-height` option now takes a number followed by `+`, which tells fzf to show at least that many items in the list section. The default value is now changed to `10+`.
|
||||||
|
```sh
|
||||||
|
# You will only see the input section which takes 3 lines
|
||||||
|
fzf --style=full --height 1% --min-height 3
|
||||||
|
|
||||||
|
# You will see 3 items in the list section
|
||||||
|
fzf --style full --height 1% --min-height 3+
|
||||||
|
```
|
||||||
|
- Shell integration scripts were updated to use `--min-height 20+` by default
|
||||||
- Added `bell` action to ring the terminal bell
|
- Added `bell` action to ring the terminal bell
|
||||||
```sh
|
```sh
|
||||||
# Press CTRL-Y to copy the current line to the clipboard and ring the bell
|
# Press CTRL-Y to copy the current line to the clipboard and ring the bell
|
||||||
|
@ -336,9 +336,12 @@ Adaptive height has the following limitations:
|
|||||||
* It will not find the right size when there are multi-line items
|
* It will not find the right size when there are multi-line items
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-min\-height=" "HEIGHT"
|
.BI "\-\-min\-height=" "HEIGHT[+]"
|
||||||
Minimum height when \fB\-\-height\fR is given in percent (default: 10).
|
Minimum height when \fB\-\-height\fR is given as a percentage.
|
||||||
Ignored when \fB\-\-height\fR is not specified.
|
Add \fB+\fR to automatically increase the value according to the other
|
||||||
|
layout options so that the specified number of items are visible in the list
|
||||||
|
section (default: \fB10+\fR).
|
||||||
|
Ignored when \fB\-\-height\fR is not specified or set as an absolute value.
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-tmux" "[=[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]][,border-native]]"
|
.BI "\-\-tmux" "[=[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]][,border-native]]"
|
||||||
Start fzf in a tmux popup (default \fBcenter,50%\fR). Requires tmux 3.3 or
|
Start fzf in a tmux popup (default \fBcenter,50%\fR). Requires tmux 3.3 or
|
||||||
|
@ -37,7 +37,7 @@ bind '"\e[0n": redraw-current-line' 2> /dev/null
|
|||||||
__fzf_defaults() {
|
__fzf_defaults() {
|
||||||
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
echo "--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore $1"
|
echo "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"
|
||||||
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
|
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
|
||||||
echo "${FZF_DEFAULT_OPTS-} $2"
|
echo "${FZF_DEFAULT_OPTS-} $2"
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ if [[ -o interactive ]]; then
|
|||||||
__fzf_defaults() {
|
__fzf_defaults() {
|
||||||
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
echo "--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore $1"
|
echo "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"
|
||||||
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
|
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
|
||||||
echo "${FZF_DEFAULT_OPTS-} $2"
|
echo "${FZF_DEFAULT_OPTS-} $2"
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ if [[ $- =~ i ]]; then
|
|||||||
__fzf_defaults() {
|
__fzf_defaults() {
|
||||||
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
echo "--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore $1"
|
echo "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"
|
||||||
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
|
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
|
||||||
echo "${FZF_DEFAULT_OPTS-} $2"
|
echo "${FZF_DEFAULT_OPTS-} $2"
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ function fzf_key_bindings
|
|||||||
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
||||||
echo "--height $FZF_TMUX_HEIGHT --bind=ctrl-z:ignore" $argv[1]
|
echo "--height $FZF_TMUX_HEIGHT --min-height 20+ --bind=ctrl-z:ignore" $argv[1]
|
||||||
test -r "$FZF_DEFAULT_OPTS_FILE"; and string collect -N -- <$FZF_DEFAULT_OPTS_FILE
|
test -r "$FZF_DEFAULT_OPTS_FILE"; and string collect -N -- <$FZF_DEFAULT_OPTS_FILE
|
||||||
echo $FZF_DEFAULT_OPTS $argv[2]
|
echo $FZF_DEFAULT_OPTS $argv[2]
|
||||||
end
|
end
|
||||||
|
@ -41,7 +41,7 @@ if [[ -o interactive ]]; then
|
|||||||
__fzf_defaults() {
|
__fzf_defaults() {
|
||||||
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
echo "--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore $1"
|
echo "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"
|
||||||
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
|
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
|
||||||
echo "${FZF_DEFAULT_OPTS-} $2"
|
echo "${FZF_DEFAULT_OPTS-} $2"
|
||||||
}
|
}
|
||||||
|
@ -69,8 +69,9 @@ Usage: fzf [options]
|
|||||||
minus the given value.
|
minus the given value.
|
||||||
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 when --height is given as a percentage.
|
||||||
(default: 10 or above depending on the other options)
|
Add '+' to automatically increase the value
|
||||||
|
according to the other layout options (default: 10+).
|
||||||
--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 +674,7 @@ func defaultOptions() *Options {
|
|||||||
Theme: theme,
|
Theme: theme,
|
||||||
Black: false,
|
Black: false,
|
||||||
Bold: true,
|
Bold: true,
|
||||||
MinHeight: -1,
|
MinHeight: -10,
|
||||||
Layout: layoutDefault,
|
Layout: layoutDefault,
|
||||||
Cycle: false,
|
Cycle: false,
|
||||||
Wrap: false,
|
Wrap: false,
|
||||||
@ -2662,9 +2663,23 @@ func parseOptions(index *int, opts *Options, allArgs []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case "--min-height":
|
case "--min-height":
|
||||||
if opts.MinHeight, err = nextInt("height required: HEIGHT"); err != nil {
|
expr, err := nextString("minimum height required: HEIGHT[+]")
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
auto := false
|
||||||
|
if strings.HasSuffix(expr, "+") {
|
||||||
|
expr = expr[:len(expr)-1]
|
||||||
|
auto = true
|
||||||
|
}
|
||||||
|
num, err := atoi(expr)
|
||||||
|
if err != nil || num < 0 {
|
||||||
|
return errors.New("minimum height must be a non-negative integer")
|
||||||
|
}
|
||||||
|
if auto {
|
||||||
|
num *= -1
|
||||||
|
}
|
||||||
|
opts.MinHeight = num
|
||||||
case "--no-height":
|
case "--no-height":
|
||||||
opts.Height = heightSpec{}
|
opts.Height = heightSpec{}
|
||||||
case "--no-margin":
|
case "--no-margin":
|
||||||
@ -3220,8 +3235,7 @@ func postProcessOptions(opts *Options) error {
|
|||||||
|
|
||||||
// Sets --min-height automatically
|
// Sets --min-height automatically
|
||||||
if opts.Height.size > 0 && opts.Height.percent && opts.MinHeight < 0 {
|
if opts.Height.size > 0 && opts.Height.percent && opts.MinHeight < 0 {
|
||||||
// 10 items and 1 prompt line
|
opts.MinHeight = -opts.MinHeight + 1 + borderLines(opts.BorderShape) + borderLines(opts.ListBorderShape) + borderLines(opts.InputBorderShape)
|
||||||
opts.MinHeight = 10 + 1 + borderLines(opts.BorderShape) + borderLines(opts.ListBorderShape) + borderLines(opts.InputBorderShape)
|
|
||||||
if len(opts.Header) > 0 {
|
if len(opts.Header) > 0 {
|
||||||
opts.MinHeight += borderLines(opts.HeaderBorderShape) + len(opts.Header)
|
opts.MinHeight += borderLines(opts.HeaderBorderShape) + len(opts.Header)
|
||||||
}
|
}
|
||||||
|
@ -845,4 +845,35 @@ class TestLayout < TestInteractive
|
|||||||
assert lines[1]&.end_with?('1000││')
|
assert lines[1]&.end_with?('1000││')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_min_height_no_auto
|
||||||
|
tmux.send_keys %(seq 100 | #{FZF} --border sharp --style full:sharp --height 1% --min-height 5), :Enter
|
||||||
|
|
||||||
|
block = <<~BLOCK
|
||||||
|
┌───────
|
||||||
|
│ ┌─────
|
||||||
|
│ │ >
|
||||||
|
│ └─────
|
||||||
|
└───────
|
||||||
|
BLOCK
|
||||||
|
tmux.until { assert_block(block, _1) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_min_height_auto
|
||||||
|
tmux.send_keys %(seq 100 | #{FZF} --style full:sharp --height 1% --min-height 5+), :Enter
|
||||||
|
|
||||||
|
block = <<~BLOCK
|
||||||
|
┌─────────
|
||||||
|
│ 5
|
||||||
|
│ 4
|
||||||
|
│ 3
|
||||||
|
│ 2
|
||||||
|
│ > 1
|
||||||
|
└─────────
|
||||||
|
┌─────────
|
||||||
|
│ >
|
||||||
|
└─────────
|
||||||
|
BLOCK
|
||||||
|
tmux.until { assert_block(block, _1) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user