Skip to content

Commit

Permalink
Implement streaming preview window (junegunn#2215)
Browse files Browse the repository at this point in the history
Fix junegunn#2212

    # Will start rendering after 200ms, update every 100ms
    fzf --preview 'for i in $(seq 100); do echo $i; sleep 0.01; done'

    # Should print "Loading .." message after 500ms
    fzf --preview 'sleep 1; for i in $(seq 100); do echo $i; sleep 0.01; done'

    # The first line should appear after 200ms
    fzf --preview 'date; sleep 2; date'

    # Should not render before enough lines for the scroll offset are ready
    rg --line-number --no-heading --color=always ^ |
      fzf --delimiter : --ansi --preview-window '+{2}-/2' \
          --preview 'sleep 1; bat --style=numbers --color=always --pager=never --highlight-line={2} {1}'
  • Loading branch information
junegunn authored Oct 18, 2020
1 parent 305896f commit faf68db
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 117 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
CHANGELOG
=========

0.24.0
------
- fzf can render preview window before the command completes
```sh
fzf --preview 'sleep 1; for i in $(seq 100); do echo $i; sleep 0.01; done'
```

0.23.1
------
- Added `--preview-window` options for disabling flags
Expand Down
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,26 +582,18 @@ and fzf will warn you about it. To suppress the warning message, we added

### Preview window

When the `--preview` option is set, fzf automatically starts an external process
with the current line as the argument and shows the result in the split window.
Your `$SHELL` is used to execute the command with `$SHELL -c COMMAND`.
When the `--preview` option is set, fzf automatically starts an external process
with the current line as the argument and shows the result in the split window.
Your `$SHELL` is used to execute the command with `$SHELL -c COMMAND`.
The window can be scrolled using the mouse or custom key bindings.

```bash
# {} is replaced to the single-quoted string of the focused line
fzf --preview 'cat {}'
```

Since the preview window is updated only after the process is complete, it's
important that the command finishes quickly.

```bash
# Use head instead of cat so that the command doesn't take too long to finish
fzf --preview 'head -100 {}'
```

Preview window supports ANSI colors, so you can use any program that
syntax-highlights the content of a file, such as
syntax-highlights the content of a file, such as
[Bat](https://github.com/sharkdp/bat) or
[Highlight](http://www.andre-simon.de/doku/highlight/en/highlight.php):

Expand Down
2 changes: 2 additions & 0 deletions src/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (
initialDelayTac = 100 * time.Millisecond
spinnerDuration = 100 * time.Millisecond
previewCancelWait = 500 * time.Millisecond
previewChunkDelay = 100 * time.Millisecond
previewDelayed = 500 * time.Millisecond
maxPatternLength = 300
maxMulti = math.MaxInt32

Expand Down
Loading

0 comments on commit faf68db

Please sign in to comment.