Skip to content

Commit

Permalink
Add 'noinfo' option to hide scroll offset information in preview window
Browse files Browse the repository at this point in the history
fzf --preview 'seq 1000' --preview-window noinfo

Close #2525
  • Loading branch information
junegunn committed Sep 12, 2024
1 parent 2286edb commit 952276d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
7 changes: 5 additions & 2 deletions man/man1/fzf.1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
..
.TH fzf 1 "Aug 2024" "fzf 0.55.0" "fzf - a command-line fuzzy finder"
.TH fzf 1 "Sep 2024" "fzf 0.56.0" "fzf - a command-line fuzzy finder"

.SH NAME
fzf - a command-line fuzzy finder
Expand Down Expand Up @@ -756,7 +756,7 @@ default value 0 (or \fBcenter\fR) will put the label at the center of the
border line.

.TP
.BI "\-\-preview\-window=" "[POSITION][,SIZE[%]][,border\-BORDER_OPT][,[no]wrap][,[no]follow][,[no]cycle][,[no]hidden][,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES][,default][,<SIZE_THRESHOLD(ALTERNATIVE_LAYOUT)]"
.BI "\-\-preview\-window=" "[POSITION][,SIZE[%]][,border\-BORDER_OPT][,[no]wrap][,[no]follow][,[no]cycle][,[no]info][,[no]hidden][,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES][,default][,<SIZE_THRESHOLD(ALTERNATIVE_LAYOUT)]"

.RS
.B POSITION: (default: right)
Expand Down Expand Up @@ -790,6 +790,9 @@ e.g.

* Cyclic scrolling is enabled with \fBcycle\fR flag.

* To hide the scroll offset information on the top right corner, specify
\fBnoinfo\fR.

* To change the style of the border of the preview window, specify one of
the options for \fB\-\-border\fR with \fBborder\-\fR prefix.
e.g. \fBborder\-rounded\fR (border with rounded edges, default),
Expand Down
11 changes: 8 additions & 3 deletions src/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ Usage: fzf [options]
--preview=COMMAND Command to preview highlighted line ({})
--preview-window=OPT Preview window layout (default: right:50%)
[up|down|left|right][,SIZE[%]]
[,[no]wrap][,[no]cycle][,[no]follow][,[no]hidden]
[,border-BORDER_OPT]
[,[no]wrap][,[no]cycle][,[no]follow][,[no]info]
[,[no]hidden][,border-BORDER_OPT]
[,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES]
[,default][,<SIZE_THRESHOLD(ALTERNATIVE_LAYOUT)]
--preview-label=LABEL
Expand Down Expand Up @@ -271,6 +271,7 @@ type previewOpts struct {
wrap bool
cycle bool
follow bool
info bool
border tui.BorderShape
headerLines int
threshold int
Expand Down Expand Up @@ -508,7 +509,7 @@ func filterNonEmpty(input []string) []string {
}

func defaultPreviewOpts(command string) previewOpts {
return previewOpts{command, posRight, sizeSpec{50, true}, "", false, false, false, false, tui.DefaultBorderShape, 0, 0, nil}
return previewOpts{command, posRight, sizeSpec{50, true}, "", false, false, false, false, true, tui.DefaultBorderShape, 0, 0, nil}
}

func defaultOptions() *Options {
Expand Down Expand Up @@ -1789,6 +1790,10 @@ func parsePreviewWindowImpl(opts *previewOpts, input string) error {
opts.follow = true
case "nofollow":
opts.follow = false
case "info":
opts.info = true
case "noinfo":
opts.info = false
default:
if headerRegex.MatchString(token) {
if opts.headerLines, err = atoi(token[1:]); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2507,7 +2507,7 @@ func (t *Terminal) renderPreviewSpinner() {
spin := t.previewer.spinner
if len(spin) > 0 || t.previewer.scrollable {
maxWidth := t.pwindow.Width()
if !t.previewer.scrollable {
if !t.previewer.scrollable || !t.previewOpts.info {
if maxWidth > 0 {
t.pwindow.Move(0, maxWidth-1)
t.pwindow.CPrint(tui.ColPreviewSpinner, spin)
Expand Down
9 changes: 9 additions & 0 deletions test/test_go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3378,6 +3378,15 @@ def test_boundary_match
assert_equal expected, result
end
end

def test_preview_window_noinfo
# │ 1 ││
tmux.send_keys %(#{FZF} --preview 'seq 1000' --preview-window top,noinfo --scrollbar), :Enter
tmux.until do |lines|
assert lines[1]&.start_with?('│ 1')
assert lines[1]&.end_with?(' ││')
end
end
end

module TestShell
Expand Down

0 comments on commit 952276d

Please sign in to comment.