mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-14 06:13:47 -05:00
Compare commits
61 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
beb2de2dd9 | ||
|
|
2a8b65e105 | ||
|
|
62a916bc24 | ||
|
|
c47b833e7b | ||
|
|
09b0958b5f | ||
|
|
3a4c3d3e58 | ||
|
|
7484292e63 | ||
|
|
687c2741b8 | ||
|
|
2fb285e530 | ||
|
|
16f6473938 | ||
|
|
66546208b2 | ||
|
|
532274045e | ||
|
|
9347c72fb6 | ||
|
|
e90bb7169c | ||
|
|
8a2c41e183 | ||
|
|
59fb65293a | ||
|
|
e7718b92b7 | ||
|
|
cdfaf761df | ||
|
|
1a9ea6f738 | ||
|
|
945c1c8597 | ||
|
|
e4d0f7acd5 | ||
|
|
250496c953 | ||
|
|
e47dc758c9 | ||
|
|
b92a843c5f | ||
|
|
91bea9c5b3 | ||
|
|
d75bb5cbe1 | ||
|
|
2671259fdb | ||
|
|
2024010119 | ||
|
|
412040f77e | ||
|
|
d210660ce8 | ||
|
|
863a12562b | ||
|
|
5da606a9ac | ||
|
|
8d20f3d5c4 | ||
|
|
5d360180af | ||
|
|
f0fbed6007 | ||
|
|
519de7c833 | ||
|
|
97ccef1a04 | ||
|
|
c4df0dd06e | ||
|
|
cd114c6818 | ||
|
|
1707b8cdba | ||
|
|
41d4d70b98 | ||
|
|
0e999482cb | ||
|
|
65b2c06027 | ||
|
|
d7b61ede07 | ||
|
|
87fc1c84b8 | ||
|
|
d4b5f12383 | ||
|
|
eb62b0d665 | ||
|
|
91387a741b | ||
|
|
e8b34cb00d | ||
|
|
82954258c1 | ||
|
|
50f092551b | ||
|
|
c36a64be68 | ||
|
|
a343b20775 | ||
|
|
a714e76ae1 | ||
|
|
d21d5c9510 | ||
|
|
cd6788a2bb | ||
|
|
6b99399c41 | ||
|
|
952b6af445 | ||
|
|
7c674ad7fa | ||
|
|
d7d2ac3951 | ||
|
|
29e67d307a |
6
.github/workflows/codeql-analysis.yml
vendored
6
.github/workflows/codeql-analysis.yml
vendored
@@ -33,12 +33,12 @@ jobs:
|
|||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v2
|
uses: github/codeql-action/init@v3
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
|
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v2
|
uses: github/codeql-action/autobuild@v3
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v2
|
uses: github/codeql-action/analyze@v3
|
||||||
|
|||||||
2
.github/workflows/depsreview.yaml
vendored
2
.github/workflows/depsreview.yaml
vendored
@@ -11,4 +11,4 @@ jobs:
|
|||||||
- name: 'Checkout Repository'
|
- name: 'Checkout Repository'
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: 'Dependency Review'
|
- name: 'Dependency Review'
|
||||||
uses: actions/dependency-review-action@v3
|
uses: actions/dependency-review-action@v4
|
||||||
|
|||||||
2
.github/workflows/linux.yml
vendored
2
.github/workflows/linux.yml
vendored
@@ -20,7 +20,7 @@ jobs:
|
|||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.19
|
go-version: 1.19
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/macos.yml
vendored
2
.github/workflows/macos.yml
vendored
@@ -20,7 +20,7 @@ jobs:
|
|||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.18
|
go-version: 1.18
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/typos.yml
vendored
2
.github/workflows/typos.yml
vendored
@@ -7,4 +7,4 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: crate-ci/typos@v1.16.4
|
- uses: crate-ci/typos@v1.17.2
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
golang 1.20.4
|
golang 1.21.6
|
||||||
|
|||||||
72
ADVANCED.md
72
ADVANCED.md
@@ -1,8 +1,8 @@
|
|||||||
Advanced fzf examples
|
Advanced fzf examples
|
||||||
======================
|
======================
|
||||||
|
|
||||||
* *Last update: 2023/05/26*
|
* *Last update: 2024/01/20*
|
||||||
* *Requires fzf 0.41.0 or above*
|
* *Requires fzf 0.46.0 or above*
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -16,17 +16,20 @@ Advanced fzf examples
|
|||||||
* [Dynamic reloading of the list](#dynamic-reloading-of-the-list)
|
* [Dynamic reloading of the list](#dynamic-reloading-of-the-list)
|
||||||
* [Updating the list of processes by pressing CTRL-R](#updating-the-list-of-processes-by-pressing-ctrl-r)
|
* [Updating the list of processes by pressing CTRL-R](#updating-the-list-of-processes-by-pressing-ctrl-r)
|
||||||
* [Toggling between data sources](#toggling-between-data-sources)
|
* [Toggling between data sources](#toggling-between-data-sources)
|
||||||
|
* [Toggling with a single key binding](#toggling-with-a-single-key-binding)
|
||||||
* [Ripgrep integration](#ripgrep-integration)
|
* [Ripgrep integration](#ripgrep-integration)
|
||||||
* [Using fzf as the secondary filter](#using-fzf-as-the-secondary-filter)
|
* [Using fzf as the secondary filter](#using-fzf-as-the-secondary-filter)
|
||||||
* [Using fzf as interactive Ripgrep launcher](#using-fzf-as-interactive-ripgrep-launcher)
|
* [Using fzf as interactive Ripgrep launcher](#using-fzf-as-interactive-ripgrep-launcher)
|
||||||
* [Switching to fzf-only search mode](#switching-to-fzf-only-search-mode)
|
* [Switching to fzf-only search mode](#switching-to-fzf-only-search-mode)
|
||||||
* [Switching between Ripgrep mode and fzf mode](#switching-between-ripgrep-mode-and-fzf-mode)
|
* [Switching between Ripgrep mode and fzf mode](#switching-between-ripgrep-mode-and-fzf-mode)
|
||||||
|
* [Switching between Ripgrep mode and fzf mode using a single key binding](#switching-between-ripgrep-mode-and-fzf-mode-using-a-single-key-binding)
|
||||||
* [Log tailing](#log-tailing)
|
* [Log tailing](#log-tailing)
|
||||||
* [Key bindings for git objects](#key-bindings-for-git-objects)
|
* [Key bindings for git objects](#key-bindings-for-git-objects)
|
||||||
* [Files listed in `git status`](#files-listed-in-git-status)
|
* [Files listed in `git status`](#files-listed-in-git-status)
|
||||||
* [Branches](#branches)
|
* [Branches](#branches)
|
||||||
* [Commit hashes](#commit-hashes)
|
* [Commit hashes](#commit-hashes)
|
||||||
* [Color themes](#color-themes)
|
* [Color themes](#color-themes)
|
||||||
|
* [fzf Theme Playground](#fzf-theme-playground)
|
||||||
* [Generating fzf color theme from Vim color schemes](#generating-fzf-color-theme-from-vim-color-schemes)
|
* [Generating fzf color theme from Vim color schemes](#generating-fzf-color-theme-from-vim-color-schemes)
|
||||||
|
|
||||||
<!-- vim-markdown-toc -->
|
<!-- vim-markdown-toc -->
|
||||||
@@ -208,6 +211,30 @@ find * | fzf --prompt 'All> ' \
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
### Toggling with a single key binding
|
||||||
|
|
||||||
|
The above example uses two different key bindings to toggle between two modes,
|
||||||
|
but can we just use a single key binding?
|
||||||
|
|
||||||
|
To make a key binding behave differently each time it is pressed, we need:
|
||||||
|
|
||||||
|
1. a way to store the current state. i.e. "which mode are we in?"
|
||||||
|
2. and a way to dynamically perform different actions depending on the state.
|
||||||
|
|
||||||
|
The following example shows how to 1. store the current mode in the prompt
|
||||||
|
string, 2. and use this information (`$FZF_PROMPT`) to determine which
|
||||||
|
actions to perform using the `transform` action.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
fd --type file |
|
||||||
|
fzf --prompt 'Files> ' \
|
||||||
|
--header 'CTRL-T: Switch between Files/Directories' \
|
||||||
|
--bind 'ctrl-t:transform:[[ ! $FZF_PROMPT =~ Files ]] &&
|
||||||
|
echo "change-prompt(Files> )+reload(fd --type file)" ||
|
||||||
|
echo "change-prompt(Directories> )+reload(fd --type directory)"' \
|
||||||
|
--preview '[[ $FZF_PROMPT =~ Files ]] && bat --color=always {} || tree -C {}'
|
||||||
|
```
|
||||||
|
|
||||||
Ripgrep integration
|
Ripgrep integration
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
@@ -442,6 +469,41 @@ INITIAL_QUERY="${*:-}"
|
|||||||
[0.30.0]: https://github.com/junegunn/fzf/blob/master/CHANGELOG.md#0300
|
[0.30.0]: https://github.com/junegunn/fzf/blob/master/CHANGELOG.md#0300
|
||||||
[0.36.0]: https://github.com/junegunn/fzf/blob/master/CHANGELOG.md#0360
|
[0.36.0]: https://github.com/junegunn/fzf/blob/master/CHANGELOG.md#0360
|
||||||
|
|
||||||
|
### Switching between Ripgrep mode and fzf mode using a single key binding
|
||||||
|
|
||||||
|
In contrast to the previous version, we use just one hotkey to toggle between
|
||||||
|
ripgrep and fzf mode. This is achieved by using the `$FZF_PROMPT` as a state
|
||||||
|
within the `transform` action, a feature introduced in [fzf 0.45.0][0.45.0]. A
|
||||||
|
more detailed explanation of this feature can be found in a previous section -
|
||||||
|
[Toggling with a single keybinding](#toggling-with-a-single-key-binding).
|
||||||
|
|
||||||
|
[0.45.0]: https://github.com/junegunn/fzf/blob/master/CHANGELOG.md#0450
|
||||||
|
|
||||||
|
When using the `transform` action, the placeholder (`\{q}`) should be escaped to
|
||||||
|
prevent immediate evaluation.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Switch between Ripgrep mode and fzf filtering mode (CTRL-T)
|
||||||
|
rm -f /tmp/rg-fzf-{r,f}
|
||||||
|
RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
|
||||||
|
INITIAL_QUERY="${*:-}"
|
||||||
|
: | fzf --ansi --disabled --query "$INITIAL_QUERY" \
|
||||||
|
--bind "start:reload:$RG_PREFIX {q}" \
|
||||||
|
--bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
|
||||||
|
--bind 'ctrl-t:transform:[[ ! $FZF_PROMPT =~ ripgrep ]] &&
|
||||||
|
echo "rebind(change)+change-prompt(1. ripgrep> )+disable-search+transform-query:echo \{q} > /tmp/rg-fzf-f; cat /tmp/rg-fzf-r" ||
|
||||||
|
echo "unbind(change)+change-prompt(2. fzf> )+enable-search+transform-query:echo \{q} > /tmp/rg-fzf-r; cat /tmp/rg-fzf-f"' \
|
||||||
|
--color "hl:-1:underline,hl+:-1:underline:reverse" \
|
||||||
|
--prompt '1. ripgrep> ' \
|
||||||
|
--delimiter : \
|
||||||
|
--header 'CTRL-T: Switch between ripgrep/fzf' \
|
||||||
|
--preview 'bat --color=always {1} --highlight-line {2}' \
|
||||||
|
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3' \
|
||||||
|
--bind 'enter:become(vim {1} +{2})'
|
||||||
|
```
|
||||||
|
|
||||||
Log tailing
|
Log tailing
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
@@ -571,6 +633,12 @@ export FZF_DEFAULT_OPTS='--color=bg+:#293739,bg:#1B1D1E,border:#808080,spinner:#
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
### fzf Theme Playground
|
||||||
|
|
||||||
|
[fzf Theme Playground](https://vitormv.github.io/fzf-themes/) created by
|
||||||
|
[Vitor Mello](https://github.com/vitormv) is a webpage where you can
|
||||||
|
interactively create fzf themes.
|
||||||
|
|
||||||
### Generating fzf color theme from Vim color schemes
|
### Generating fzf color theme from Vim color schemes
|
||||||
|
|
||||||
The Vim plugin of fzf can generate `--color` option from the current color
|
The Vim plugin of fzf can generate `--color` option from the current color
|
||||||
|
|||||||
4
BUILD.md
4
BUILD.md
@@ -34,8 +34,8 @@ make release
|
|||||||
Third-party libraries used
|
Third-party libraries used
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
- [mattn/go-runewidth](https://github.com/mattn/go-runewidth)
|
- [rivo/uniseg](https://github.com/rivo/uniseg)
|
||||||
- Licensed under [MIT](http://mattn.mit-license.org)
|
- Licensed under [MIT](https://raw.githubusercontent.com/rivo/uniseg/master/LICENSE.txt)
|
||||||
- [mattn/go-shellwords](https://github.com/mattn/go-shellwords)
|
- [mattn/go-shellwords](https://github.com/mattn/go-shellwords)
|
||||||
- Licensed under [MIT](http://mattn.mit-license.org)
|
- Licensed under [MIT](http://mattn.mit-license.org)
|
||||||
- [mattn/go-isatty](https://github.com/mattn/go-isatty)
|
- [mattn/go-isatty](https://github.com/mattn/go-isatty)
|
||||||
|
|||||||
96
CHANGELOG.md
96
CHANGELOG.md
@@ -1,6 +1,100 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
0.46.0
|
||||||
|
------
|
||||||
|
- Added two new events
|
||||||
|
- `result` - triggered when the filtering for the current query is complete and the result list is ready
|
||||||
|
- `resize` - triggered when the terminal size is changed
|
||||||
|
- fzf now exports the following environment variables to the child processes
|
||||||
|
| Variable | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| `FZF_LINES` | Number of lines fzf takes up excluding padding and margin |
|
||||||
|
| `FZF_COLUMNS` | Number of columns fzf takes up excluding padding and margin |
|
||||||
|
| `FZF_TOTAL_COUNT` | Total number of items |
|
||||||
|
| `FZF_MATCH_COUNT` | Number of matched items |
|
||||||
|
| `FZF_SELECT_COUNT` | Number of selected items |
|
||||||
|
| `FZF_QUERY` | Current query string |
|
||||||
|
| `FZF_PROMPT` | Prompt string |
|
||||||
|
| `FZF_ACTION` | The name of the last action performed |
|
||||||
|
- This allows you to write sophisticated transformations like so
|
||||||
|
```sh
|
||||||
|
# Script to dynamically resize the preview window
|
||||||
|
transformer='
|
||||||
|
# 1 line for info, another for prompt, and 2 more lines for preview window border
|
||||||
|
lines=$(( FZF_LINES - FZF_MATCH_COUNT - 4 ))
|
||||||
|
if [[ $FZF_MATCH_COUNT -eq 0 ]]; then
|
||||||
|
echo "change-preview-window:hidden"
|
||||||
|
elif [[ $lines -gt 3 ]]; then
|
||||||
|
echo "change-preview-window:$lines"
|
||||||
|
elif [[ $FZF_PREVIEW_LINES -ne 3 ]]; then
|
||||||
|
echo "change-preview-window:3"
|
||||||
|
fi
|
||||||
|
'
|
||||||
|
seq 10000 | fzf --preview 'seq {} 10000' --preview-window up \
|
||||||
|
--bind "result:transform:$transformer" \
|
||||||
|
--bind "resize:transform:$transformer"
|
||||||
|
```
|
||||||
|
- And we're phasing out `{fzf:prompt}` and `{fzf:action}`
|
||||||
|
- Changed [mattn/go-runewidth](https://github.com/mattn/go-runewidth) dependency to [rivo/uniseg](https://github.com/rivo/uniseg) for accurate results
|
||||||
|
- Set `--ambidouble` if your terminal displays ambiguous width characters (e.g. box-drawing characters for borders) as 2 columns
|
||||||
|
- `RUNEWIDTH_EASTASIAN=1` is still respected for backward compatibility, but it's recommended that you use this new option instead
|
||||||
|
- Bug fixes
|
||||||
|
|
||||||
|
0.45.0
|
||||||
|
------
|
||||||
|
- Added `transform` action to conditionally perform a series of actions
|
||||||
|
```sh
|
||||||
|
# Disallow selecting an empty line
|
||||||
|
echo -e "1. Hello\n2. Goodbye\n\n3. Exit" |
|
||||||
|
fzf --height '~100%' --reverse --header 'Select one' \
|
||||||
|
--bind 'enter:transform:[[ -n {} ]] && echo accept || echo "change-header:Invalid selection"'
|
||||||
|
|
||||||
|
# Move cursor past the empty line
|
||||||
|
echo -e "1. Hello\n2. Goodbye\n\n3. Exit" |
|
||||||
|
fzf --height '~100%' --reverse --header 'Select one' \
|
||||||
|
--bind 'enter:transform:[[ -n {} ]] && echo accept || echo "change-header:Invalid selection"' \
|
||||||
|
--bind 'focus:transform:[[ -n {} ]] && exit; [[ {fzf:action} =~ up$ ]] && echo up || echo down'
|
||||||
|
|
||||||
|
# A single key binding to toggle between modes
|
||||||
|
fd --type file |
|
||||||
|
fzf --prompt 'Files> ' \
|
||||||
|
--header 'CTRL-T: Switch between Files/Directories' \
|
||||||
|
--bind 'ctrl-t:transform:[[ ! {fzf:prompt} =~ Files ]] &&
|
||||||
|
echo "change-prompt(Files> )+reload(fd --type file)" ||
|
||||||
|
echo "change-prompt(Directories> )+reload(fd --type directory)"'
|
||||||
|
```
|
||||||
|
- Added placeholder expressions
|
||||||
|
- `{fzf:action}` - The name of the last action performed
|
||||||
|
- `{fzf:prompt}` - Prompt string (including ANSI color codes)
|
||||||
|
- `{fzf:query}` - Synonym for `{q}`
|
||||||
|
- Added support for negative height
|
||||||
|
```sh
|
||||||
|
# Terminal height minus 1, so you can still see the command line
|
||||||
|
fzf --height=-1
|
||||||
|
```
|
||||||
|
- This handles a terminal resize better than `--height=$(($(tput lines) - 1))`
|
||||||
|
- Added `accept-or-print-query` action that acts like `accept` but prints the
|
||||||
|
current query when there's no match for the query
|
||||||
|
```sh
|
||||||
|
# You can make CTRL-R paste the current query when there's no match
|
||||||
|
export FZF_CTRL_R_OPTS='--bind enter:accept-or-print-query'
|
||||||
|
```
|
||||||
|
- Note that there are alternative ways to implement the same strategy
|
||||||
|
```sh
|
||||||
|
# 'become' is apparently more versatile but it's not available on Windows.
|
||||||
|
export FZF_CTRL_R_OPTS='--bind "enter:become:if [ -z {} ]; then echo {q}; else echo {}; fi"'
|
||||||
|
|
||||||
|
# Using the new 'transform' action
|
||||||
|
export FZF_CTRL_R_OPTS='--bind "enter:transform:[ -z {} ] && echo print-query || echo accept"'
|
||||||
|
```
|
||||||
|
- Added `show-header` and `hide-header` actions
|
||||||
|
- Bug fixes
|
||||||
|
|
||||||
|
0.44.1
|
||||||
|
------
|
||||||
|
- Fixed crash when preview window is hidden on `focus` event
|
||||||
|
|
||||||
0.44.0
|
0.44.0
|
||||||
------
|
------
|
||||||
- (Experimental) Sixel image support in preview window (not available on Windows)
|
- (Experimental) Sixel image support in preview window (not available on Windows)
|
||||||
@@ -38,7 +132,7 @@ CHANGELOG
|
|||||||
# --transfer-mode=memory is the fastest option but if you want fzf to be able
|
# --transfer-mode=memory is the fastest option but if you want fzf to be able
|
||||||
# to redraw the image on terminal resize or on 'change-preview-window',
|
# to redraw the image on terminal resize or on 'change-preview-window',
|
||||||
# you need to use --transfer-mode=stream.
|
# you need to use --transfer-mode=stream.
|
||||||
kitty icat --clear --transfer-mode=memory --stdin=no --place=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}@0x0 {} | sed \$d
|
kitty icat --clear --transfer-mode=memory --unicode-placeholder --stdin=no --place=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}@0x0 {} | sed \$d
|
||||||
else
|
else
|
||||||
bat --color=always {}
|
bat --color=always {}
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
FROM --platform=linux/amd64 archlinux
|
FROM --platform=linux/amd64 ubuntu:22.04
|
||||||
RUN pacman -Sy && pacman --noconfirm -S awk git tmux zsh fish ruby procps go make gcc
|
RUN apt-get update -y && apt install -y git make golang zsh fish ruby tmux
|
||||||
RUN gem install --no-document -v 5.14.2 minitest
|
RUN gem install --no-document -v 5.14.2 minitest
|
||||||
RUN echo '. /usr/share/bash-completion/completions/git' >> ~/.bashrc
|
RUN echo '. /usr/share/bash-completion/completions/git' >> ~/.bashrc
|
||||||
RUN echo '. ~/.bashrc' >> ~/.bash_profile
|
RUN echo '. ~/.bashrc' >> ~/.bash_profile
|
||||||
@@ -8,4 +8,5 @@ RUN echo '. ~/.bashrc' >> ~/.bash_profile
|
|||||||
RUN rm -f /etc/bash.bashrc
|
RUN rm -f /etc/bash.bashrc
|
||||||
COPY . /fzf
|
COPY . /fzf
|
||||||
RUN cd /fzf && make install && ./install --all
|
RUN cd /fzf && make install && ./install --all
|
||||||
|
ENV LANG C.UTF-8
|
||||||
CMD tmux new 'set -o pipefail; ruby /fzf/test/test_go.rb | tee out && touch ok' && cat out && [ -e ok ]
|
CMD tmux new 'set -o pipefail; ruby /fzf/test/test_go.rb | tee out && touch ok' && cat out && [ -e ok ]
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013-2023 Junegunn Choi
|
Copyright (c) 2013-2024 Junegunn Choi
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
9
Makefile
9
Makefile
@@ -89,8 +89,11 @@ bench:
|
|||||||
|
|
||||||
install: bin/fzf
|
install: bin/fzf
|
||||||
|
|
||||||
|
generate:
|
||||||
|
PATH=$(PATH):$(GOPATH)/bin $(GO) generate ./...
|
||||||
|
|
||||||
build:
|
build:
|
||||||
goreleaser build --rm-dist --snapshot --skip-post-hooks
|
goreleaser build --clean --snapshot --skip=post-hooks
|
||||||
|
|
||||||
release:
|
release:
|
||||||
# Make sure that the tests pass and the build works
|
# Make sure that the tests pass and the build works
|
||||||
@@ -123,7 +126,7 @@ endif
|
|||||||
git push origin temp --follow-tags --force
|
git push origin temp --follow-tags --force
|
||||||
|
|
||||||
# Make a GitHub release
|
# Make a GitHub release
|
||||||
goreleaser --rm-dist --release-notes tmp/release-note
|
goreleaser --clean --release-notes tmp/release-note
|
||||||
|
|
||||||
# Push to master
|
# Push to master
|
||||||
git checkout master
|
git checkout master
|
||||||
@@ -181,4 +184,4 @@ update:
|
|||||||
$(GO) get -u
|
$(GO) get -u
|
||||||
$(GO) mod tidy
|
$(GO) mod tidy
|
||||||
|
|
||||||
.PHONY: all build release test bench install clean docker docker-test update
|
.PHONY: all generate build release test bench install clean docker docker-test update
|
||||||
|
|||||||
@@ -489,4 +489,4 @@ autocmd FileType fzf set laststatus=0 noshowmode noruler
|
|||||||
|
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013-2023 Junegunn Choi
|
Copyright (c) 2013-2024 Junegunn Choi
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ if [[ $KITTY_WINDOW_ID ]]; then
|
|||||||
# 2. The last line of the output is the ANSI reset code without newline.
|
# 2. The last line of the output is the ANSI reset code without newline.
|
||||||
# This confuses fzf and makes it render scroll offset indicator.
|
# This confuses fzf and makes it render scroll offset indicator.
|
||||||
# So we remove the last line and append the reset code to its previous line.
|
# So we remove the last line and append the reset code to its previous line.
|
||||||
kitty icat --clear --transfer-mode=memory --stdin=no --place="$dim@0x0" "$file" | sed '$d' | sed $'$s/$/\e[m/'
|
kitty icat --clear --transfer-mode=memory --unicode-placeholder --stdin=no --place="$dim@0x0" "$file" | sed '$d' | sed $'$s/$/\e[m/'
|
||||||
|
|
||||||
# 2. Use chafa with Sixel output
|
# 2. Use chafa with Sixel output
|
||||||
elif command -v chafa > /dev/null; then
|
elif command -v chafa > /dev/null; then
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
fzf.txt fzf Last change: September 17 2023
|
fzf.txt fzf Last change: January 1 2024
|
||||||
FZF - TABLE OF CONTENTS *fzf* *fzf-toc*
|
FZF - TABLE OF CONTENTS *fzf* *fzf-toc*
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
@@ -512,7 +512,7 @@ LICENSE *fzf-license*
|
|||||||
|
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013-2023 Junegunn Choi
|
Copyright (c) 2013-2024 Junegunn Choi
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
vim:tw=78:sw=2:ts=2:ft=help:norl:nowrap:
|
vim:tw=78:sw=2:ts=2:ft=help:norl:nowrap:
|
||||||
|
|||||||
11
go.mod
11
go.mod
@@ -2,19 +2,20 @@ module github.com/junegunn/fzf
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gdamore/tcell/v2 v2.5.4
|
github.com/gdamore/tcell/v2 v2.5.4
|
||||||
|
github.com/junegunn/uniseg v0.0.0-20240120174029-b504da4f6ed2
|
||||||
github.com/mattn/go-isatty v0.0.17
|
github.com/mattn/go-isatty v0.0.17
|
||||||
github.com/mattn/go-runewidth v0.0.14
|
|
||||||
github.com/mattn/go-shellwords v1.0.12
|
github.com/mattn/go-shellwords v1.0.12
|
||||||
github.com/rivo/uniseg v0.4.4
|
|
||||||
github.com/saracen/walker v0.1.3
|
github.com/saracen/walker v0.1.3
|
||||||
golang.org/x/sys v0.14.0
|
golang.org/x/sys v0.16.0
|
||||||
golang.org/x/term v0.13.0
|
golang.org/x/term v0.16.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gdamore/encoding v1.0.0 // indirect
|
github.com/gdamore/encoding v1.0.0 // indirect
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
|
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||||
|
github.com/rivo/uniseg v0.4.4 // indirect
|
||||||
|
golang.org/x/sync v0.5.0 // indirect
|
||||||
golang.org/x/text v0.5.0 // indirect
|
golang.org/x/text v0.5.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
14
go.sum
14
go.sum
@@ -2,6 +2,8 @@ github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdk
|
|||||||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||||
github.com/gdamore/tcell/v2 v2.5.4 h1:TGU4tSjD3sCL788vFNeJnTdzpNKIw1H5dgLnJRQVv/k=
|
github.com/gdamore/tcell/v2 v2.5.4 h1:TGU4tSjD3sCL788vFNeJnTdzpNKIw1H5dgLnJRQVv/k=
|
||||||
github.com/gdamore/tcell/v2 v2.5.4/go.mod h1:dZgRy5v4iMobMEcWNYBtREnDZAT9DYmfqIkrgEMxLyw=
|
github.com/gdamore/tcell/v2 v2.5.4/go.mod h1:dZgRy5v4iMobMEcWNYBtREnDZAT9DYmfqIkrgEMxLyw=
|
||||||
|
github.com/junegunn/uniseg v0.0.0-20240120174029-b504da4f6ed2 h1:oEwPBh29BPu1MaTsz2dM9bDrkOgKBoYFC0u6uY2izWo=
|
||||||
|
github.com/junegunn/uniseg v0.0.0-20240120174029-b504da4f6ed2/go.mod h1:ywqF55XaSE3/uS2tkJqVFKiE0oIYAXRvU2N7DU4y3XQ=
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||||
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
|
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
|
||||||
@@ -23,20 +25,22 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
|
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
|
||||||
|
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
|
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
||||||
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
|
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
|
||||||
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
|
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
|||||||
2
install
2
install
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
version=0.44.0
|
version=0.46.0
|
||||||
auto_completion=
|
auto_completion=
|
||||||
key_bindings=
|
key_bindings=
|
||||||
update_config=2
|
update_config=2
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
$version="0.44.0"
|
$version="0.46.0"
|
||||||
|
|
||||||
$fzf_base=Split-Path -Parent $MyInvocation.MyCommand.Definition
|
$fzf_base=Split-Path -Parent $MyInvocation.MyCommand.Definition
|
||||||
|
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -5,7 +5,7 @@ import (
|
|||||||
"github.com/junegunn/fzf/src/protector"
|
"github.com/junegunn/fzf/src/protector"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version string = "0.44"
|
var version string = "0.46"
|
||||||
var revision string = "devel"
|
var revision string = "devel"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
.ig
|
.ig
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013-2023 Junegunn Choi
|
Copyright (c) 2013-2024 Junegunn Choi
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
..
|
..
|
||||||
.TH fzf-tmux 1 "Nov 2023" "fzf 0.44.0" "fzf-tmux - open fzf in tmux split pane"
|
.TH fzf-tmux 1 "Jan 2024" "fzf 0.46.0" "fzf-tmux - open fzf in tmux split pane"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
fzf-tmux - open fzf in tmux split pane
|
fzf-tmux - open fzf in tmux split pane
|
||||||
|
|||||||
127
man/man1/fzf.1
127
man/man1/fzf.1
@@ -1,7 +1,7 @@
|
|||||||
.ig
|
.ig
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013-2023 Junegunn Choi
|
Copyright (c) 2013-2024 Junegunn Choi
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
..
|
..
|
||||||
.TH fzf 1 "Nov 2023" "fzf 0.44.0" "fzf - a command-line fuzzy finder"
|
.TH fzf 1 "Jan 2024" "fzf 0.46.0" "fzf - a command-line fuzzy finder"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
fzf - a command-line fuzzy finder
|
fzf - a command-line fuzzy finder
|
||||||
@@ -192,9 +192,21 @@ Label characters for \fBjump\fR and \fBjump-accept\fR
|
|||||||
.TP
|
.TP
|
||||||
.BI "--height=" "[~]HEIGHT[%]"
|
.BI "--height=" "[~]HEIGHT[%]"
|
||||||
Display fzf window below the cursor with the given height instead of using
|
Display fzf window below the cursor with the given height instead of using
|
||||||
the full screen. When prefixed with \fB~\fR, fzf will automatically determine
|
the full screen.
|
||||||
the height in the range according to the input size. Note that adaptive height
|
|
||||||
is not compatible with top/bottom margin and padding given in percent size.
|
If a negative value is specified, the height is calculated as the terminal
|
||||||
|
height minus the given value.
|
||||||
|
|
||||||
|
fzf --height=-1
|
||||||
|
|
||||||
|
When prefixed with \fB~\fR, fzf will automatically determine the height in the
|
||||||
|
range according to the input size. Note that adaptive height is not compatible
|
||||||
|
with top/bottom margin and padding given in percent size. It is also not
|
||||||
|
compatible with a negative height value.
|
||||||
|
|
||||||
|
# Will not take up 100% of the screen
|
||||||
|
seq 5 | fzf --height=~100%
|
||||||
|
|
||||||
.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 in percent (default: 10).
|
||||||
@@ -248,9 +260,8 @@ Draw border around the finder
|
|||||||
.br
|
.br
|
||||||
|
|
||||||
If you use a terminal emulator where each box-drawing character takes
|
If you use a terminal emulator where each box-drawing character takes
|
||||||
2 columns, try setting \fBRUNEWIDTH_EASTASIAN\fR environment variable to
|
2 columns, try setting \fB--ambidouble\fR. If the border is still not properly
|
||||||
\fB0\fR or \fB1\fR. If the border is still not properly rendered, set
|
rendered, set \fB--no-unicode\fR.
|
||||||
\fB--no-unicode\fR.
|
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "--border-label" [=LABEL]
|
.BI "--border-label" [=LABEL]
|
||||||
@@ -301,6 +312,11 @@ the label. Label is printed on the top border line by default, add
|
|||||||
Use ASCII characters instead of Unicode drawing characters to draw borders,
|
Use ASCII characters instead of Unicode drawing characters to draw borders,
|
||||||
the spinner and the horizontal separator.
|
the spinner and the horizontal separator.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B "--ambidouble"
|
||||||
|
Set this option if your terminal displays ambiguous width characters (e.g.
|
||||||
|
box-drawing characters for borders) as 2 columns.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "--margin=" MARGIN
|
.BI "--margin=" MARGIN
|
||||||
Comma-separated expression for margins around the finder.
|
Comma-separated expression for margins around the finder.
|
||||||
@@ -562,10 +578,6 @@ e.g.
|
|||||||
When using a field index expression, leading and trailing whitespace is stripped
|
When using a field index expression, leading and trailing whitespace is stripped
|
||||||
from the replacement string. To preserve the whitespace, use the \fBs\fR flag.
|
from the replacement string. To preserve the whitespace, use the \fBs\fR flag.
|
||||||
|
|
||||||
Also, \fB{q}\fR is replaced to the current query string, and \fB{n}\fR is
|
|
||||||
replaced to zero-based ordinal index of the line. Use \fB{+n}\fR if you want
|
|
||||||
all index numbers when multiple lines are selected.
|
|
||||||
|
|
||||||
A placeholder expression with \fBf\fR flag is replaced to the path of
|
A placeholder expression with \fBf\fR flag is replaced to the path of
|
||||||
a temporary file that holds the evaluated list. This is useful when you
|
a temporary file that holds the evaluated list. This is useful when you
|
||||||
multi-select a large number of items and the length of the evaluated string may
|
multi-select a large number of items and the length of the evaluated string may
|
||||||
@@ -577,6 +589,14 @@ e.g.
|
|||||||
seq 100000 | fzf --multi --bind ctrl-a:select-all \\
|
seq 100000 | fzf --multi --bind ctrl-a:select-all \\
|
||||||
--preview "awk '{sum+=\\$1} END {print sum}' {+f}"\fR
|
--preview "awk '{sum+=\\$1} END {print sum}' {+f}"\fR
|
||||||
|
|
||||||
|
Also,
|
||||||
|
|
||||||
|
* \fB{q}\fR (or \fB{fzf:query}\fR) is replaced to the current query string
|
||||||
|
.br
|
||||||
|
* \fB{n}\fR is replaced to the zero-based ordinal index of the current item.
|
||||||
|
Use \fB{+n}\fR if you want all index numbers when multiple lines are selected.
|
||||||
|
.br
|
||||||
|
|
||||||
Note that you can escape a placeholder pattern by prepending a backslash.
|
Note that you can escape a placeholder pattern by prepending a backslash.
|
||||||
|
|
||||||
Preview window will be updated even when there is no match for the current
|
Preview window will be updated even when there is no match for the current
|
||||||
@@ -811,12 +831,14 @@ e.g.
|
|||||||
\fB# Start HTTP server on port 6266
|
\fB# Start HTTP server on port 6266
|
||||||
fzf --listen 6266
|
fzf --listen 6266
|
||||||
|
|
||||||
# Get program state in JSON format (experimental)
|
|
||||||
curl localhost:6266
|
|
||||||
|
|
||||||
# Send action to the server
|
# Send action to the server
|
||||||
curl -XPOST localhost:6266 -d 'reload(seq 100)+change-prompt(hundred> )'
|
curl -XPOST localhost:6266 -d 'reload(seq 100)+change-prompt(hundred> )'
|
||||||
|
|
||||||
|
# Get program state in JSON format (experimental)
|
||||||
|
# * Make sure NOT to access this endpoint from execute/transform actions
|
||||||
|
# as it will result in a timeout
|
||||||
|
curl localhost:6266
|
||||||
|
|
||||||
# Start HTTP server on port 6266 with remote connections allowed
|
# Start HTTP server on port 6266 with remote connections allowed
|
||||||
# * Listening on non-localhost address requires using an API key
|
# * Listening on non-localhost address requires using an API key
|
||||||
export FZF_API_KEY="$(head -c 32 /dev/urandom | base64)"
|
export FZF_API_KEY="$(head -c 32 /dev/urandom | base64)"
|
||||||
@@ -883,6 +905,39 @@ of field index expressions.
|
|||||||
.BR .. " All the fields"
|
.BR .. " All the fields"
|
||||||
.br
|
.br
|
||||||
|
|
||||||
|
.SH ENVIRONMENT VARIABLES EXPORTED TO CHILD PROCESSES
|
||||||
|
|
||||||
|
fzf exports the following environment variables to its child processes.
|
||||||
|
|
||||||
|
.BR FZF_LINES " Number of lines fzf takes up excluding padding and margin"
|
||||||
|
.br
|
||||||
|
.BR FZF_COLUMNS " Number of columns fzf takes up excluding padding and margin"
|
||||||
|
.br
|
||||||
|
.BR FZF_TOTAL_COUNT " Total number of items"
|
||||||
|
.br
|
||||||
|
.BR FZF_MATCH_COUNT " Number of matched items"
|
||||||
|
.br
|
||||||
|
.BR FZF_SELECT_COUNT " Number of selected items"
|
||||||
|
.br
|
||||||
|
.BR FZF_QUERY " Current query string"
|
||||||
|
.br
|
||||||
|
.BR FZF_PROMPT " Prompt string"
|
||||||
|
.br
|
||||||
|
.BR FZF_ACTION " The name of the last action performed"
|
||||||
|
.br
|
||||||
|
.BR FZF_PORT " Port number when --listen option is used"
|
||||||
|
.br
|
||||||
|
|
||||||
|
The following variables are additionally exported to the preview commands.
|
||||||
|
|
||||||
|
.BR FZF_PREVIEW_TOP " Top position of the preview window"
|
||||||
|
.br
|
||||||
|
.BR FZF_PREVIEW_LEFT " Left position of the preview window"
|
||||||
|
.br
|
||||||
|
.BR FZF_PREVIEW_LINES " Number of lines in the preview window"
|
||||||
|
.br
|
||||||
|
.BR FZF_PREVIEW_COLUMNS " Number of columns in the preview window"
|
||||||
|
|
||||||
.SH EXTENDED SEARCH MODE
|
.SH EXTENDED SEARCH MODE
|
||||||
|
|
||||||
Unless specified otherwise, fzf will start in "extended-search mode". In this
|
Unless specified otherwise, fzf will start in "extended-search mode". In this
|
||||||
@@ -1057,6 +1112,22 @@ e.g.
|
|||||||
\fB# Change the prompt to "loaded" when the input stream is complete
|
\fB# Change the prompt to "loaded" when the input stream is complete
|
||||||
(seq 10; sleep 1; seq 11 20) | fzf --prompt 'Loading> ' --bind 'load:change-prompt:Loaded> '\fR
|
(seq 10; sleep 1; seq 11 20) | fzf --prompt 'Loading> ' --bind 'load:change-prompt:Loaded> '\fR
|
||||||
.RE
|
.RE
|
||||||
|
\fIresize\fR
|
||||||
|
.RS
|
||||||
|
Triggered when the terminal size is changed.
|
||||||
|
|
||||||
|
e.g.
|
||||||
|
\fBfzf --bind 'resize:transform-header:echo Resized: ${FZF_COLUMNS}x${FZF_LINES}'\fR
|
||||||
|
.RE
|
||||||
|
\fIresult\fR
|
||||||
|
.RS
|
||||||
|
Triggered when the filtering for the current query is complete and the result list is ready.
|
||||||
|
|
||||||
|
e.g.
|
||||||
|
\fB# Put the cursor on the second item when the query string is empty
|
||||||
|
# * Note that you can't use 'change' event in this case because the second position may not be available
|
||||||
|
fzf --sync --bind 'result:transform:[[ -z {fzf:query} ]] && echo "pos(2)"'\fR
|
||||||
|
.RE
|
||||||
\fIchange\fR
|
\fIchange\fR
|
||||||
.RS
|
.RS
|
||||||
Triggered whenever the query string is changed
|
Triggered whenever the query string is changed
|
||||||
@@ -1120,6 +1191,7 @@ A key or an event can be bound to one or more of the following actions.
|
|||||||
\fBabort\fR \fIctrl-c ctrl-g ctrl-q esc\fR
|
\fBabort\fR \fIctrl-c ctrl-g ctrl-q esc\fR
|
||||||
\fBaccept\fR \fIenter double-click\fR
|
\fBaccept\fR \fIenter double-click\fR
|
||||||
\fBaccept-non-empty\fR (same as \fBaccept\fR except that it prevents fzf from exiting without selection)
|
\fBaccept-non-empty\fR (same as \fBaccept\fR except that it prevents fzf from exiting without selection)
|
||||||
|
\fBaccept-or-print-query\fR (same as \fBaccept\fR except that it prints the query when there's no match)
|
||||||
\fBbackward-char\fR \fIctrl-b left\fR
|
\fBbackward-char\fR \fIctrl-b left\fR
|
||||||
\fBbackward-delete-char\fR \fIctrl-h bspace\fR
|
\fBbackward-delete-char\fR \fIctrl-h bspace\fR
|
||||||
\fBbackward-delete-char/eof\fR (same as \fBbackward-delete-char\fR except aborts fzf if query is empty)
|
\fBbackward-delete-char/eof\fR (same as \fBbackward-delete-char\fR except aborts fzf if query is empty)
|
||||||
@@ -1164,6 +1236,7 @@ A key or an event can be bound to one or more of the following actions.
|
|||||||
\fBpage-up\fR \fIpgup\fR
|
\fBpage-up\fR \fIpgup\fR
|
||||||
\fBhalf-page-down\fR
|
\fBhalf-page-down\fR
|
||||||
\fBhalf-page-up\fR
|
\fBhalf-page-up\fR
|
||||||
|
\fBhide-header\fR
|
||||||
\fBhide-preview\fR
|
\fBhide-preview\fR
|
||||||
\fBoffset-down\fR (similar to CTRL-E of Vim)
|
\fBoffset-down\fR (similar to CTRL-E of Vim)
|
||||||
\fBoffset-up\fR (similar to CTRL-Y of Vim)
|
\fBoffset-up\fR (similar to CTRL-Y of Vim)
|
||||||
@@ -1189,6 +1262,7 @@ A key or an event can be bound to one or more of the following actions.
|
|||||||
\fBreplace-query\fR (replace query string with the current selection)
|
\fBreplace-query\fR (replace query string with the current selection)
|
||||||
\fBselect\fR
|
\fBselect\fR
|
||||||
\fBselect-all\fR (select all matches)
|
\fBselect-all\fR (select all matches)
|
||||||
|
\fBshow-header\fR
|
||||||
\fBshow-preview\fR
|
\fBshow-preview\fR
|
||||||
\fBtoggle\fR (\fIright-click\fR)
|
\fBtoggle\fR (\fIright-click\fR)
|
||||||
\fBtoggle-all\fR (toggle all matches)
|
\fBtoggle-all\fR (toggle all matches)
|
||||||
@@ -1203,6 +1277,7 @@ A key or an event can be bound to one or more of the following actions.
|
|||||||
\fBtoggle-track\fR
|
\fBtoggle-track\fR
|
||||||
\fBtoggle+up\fR \fIbtab (shift-tab)\fR
|
\fBtoggle+up\fR \fIbtab (shift-tab)\fR
|
||||||
\fBtrack\fR (track the current item; automatically disabled if focus changes)
|
\fBtrack\fR (track the current item; automatically disabled if focus changes)
|
||||||
|
\fBtransform(...)\fR (transform states using the output of an external command)
|
||||||
\fBtransform-border-label(...)\fR (transform border label using an external command)
|
\fBtransform-border-label(...)\fR (transform border label using an external command)
|
||||||
\fBtransform-header(...)\fR (transform header using an external command)
|
\fBtransform-header(...)\fR (transform header using an external command)
|
||||||
\fBtransform-preview-label(...)\fR (transform preview label using an external command)
|
\fBtransform-preview-label(...)\fR (transform preview label using an external command)
|
||||||
@@ -1315,6 +1390,28 @@ e.g.
|
|||||||
\fB# You can still filter and select entries from the initial list for 3 seconds
|
\fB# You can still filter and select entries from the initial list for 3 seconds
|
||||||
seq 100 | fzf --bind 'load:reload-sync(sleep 3; seq 1000)+unbind(load)'\fR
|
seq 100 | fzf --bind 'load:reload-sync(sleep 3; seq 1000)+unbind(load)'\fR
|
||||||
|
|
||||||
|
.SS TRANSFORM ACTIONS
|
||||||
|
|
||||||
|
Actions with \fBtransform-\fR prefix are used to transform the states of fzf
|
||||||
|
using the output of an external command. The output of these commands are
|
||||||
|
expected to be a single line of text.
|
||||||
|
|
||||||
|
e.g.
|
||||||
|
\fBfzf --bind 'focus:transform-header:file --brief {}'\fR
|
||||||
|
|
||||||
|
\fBtransform(...)\fR action runs an external command that should print a series
|
||||||
|
of actions to be performed. The output should be in the same format as the
|
||||||
|
payload of HTTP POST request to the \fB--listen\fR server.
|
||||||
|
|
||||||
|
e.g.
|
||||||
|
\fB# Disallow selecting an empty line
|
||||||
|
echo -e "1. Hello\\n2. Goodbye\\n\\n3. Exit" |
|
||||||
|
fzf --height '~100%' --reverse --header 'Select one' \\
|
||||||
|
--bind 'enter:transform:[[ -n {} ]] &&
|
||||||
|
echo accept ||
|
||||||
|
echo "change-header:Invalid selection"'
|
||||||
|
\fR
|
||||||
|
|
||||||
.SS PREVIEW BINDING
|
.SS PREVIEW BINDING
|
||||||
|
|
||||||
With \fBpreview(...)\fR action, you can specify multiple different preview
|
With \fBpreview(...)\fR action, you can specify multiple different preview
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
" Copyright (c) 2013-2023 Junegunn Choi
|
" Copyright (c) 2013-2024 Junegunn Choi
|
||||||
"
|
"
|
||||||
" MIT License
|
" MIT License
|
||||||
"
|
"
|
||||||
|
|||||||
@@ -98,13 +98,15 @@ bindkey -M viins '\ec' fzf-cd-widget
|
|||||||
fzf-history-widget() {
|
fzf-history-widget() {
|
||||||
local selected num
|
local selected num
|
||||||
setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2> /dev/null
|
setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2> /dev/null
|
||||||
selected=( $(fc -rl 1 | awk '{ cmd=$0; sub(/^[ \t]*[0-9]+\**[ \t]+/, "", cmd); if (!seen[cmd]++) print $0 }' |
|
selected="$(fc -rl 1 | awk '{ cmd=$0; sub(/^[ \t]*[0-9]+\**[ \t]+/, "", cmd); if (!seen[cmd]++) print $0 }' |
|
||||||
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} ${FZF_DEFAULT_OPTS-} -n2..,.. --scheme=history --bind=ctrl-r:toggle-sort,ctrl-z:ignore ${FZF_CTRL_R_OPTS-} --query=${(qqq)LBUFFER} +m" $(__fzfcmd)) )
|
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} ${FZF_DEFAULT_OPTS-} -n2..,.. --scheme=history --bind=ctrl-r:toggle-sort,ctrl-z:ignore ${FZF_CTRL_R_OPTS-} --query=${(qqq)LBUFFER} +m" $(__fzfcmd))"
|
||||||
local ret=$?
|
local ret=$?
|
||||||
if [ -n "$selected" ]; then
|
if [ -n "$selected" ]; then
|
||||||
num=$selected[1]
|
num=$(awk '{print $1}' <<< "$selected")
|
||||||
if [ -n "$num" ]; then
|
if [[ "$num" =~ '^[1-9][0-9]*\*?$' ]]; then
|
||||||
zle vi-fetch-history -n $num
|
zle vi-fetch-history -n ${num%\*}
|
||||||
|
else # selected is a custom query, not from history
|
||||||
|
LBUFFER="$selected"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
zle reset-prompt
|
zle reset-prompt
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013-2023 Junegunn Choi
|
Copyright (c) 2013-2024 Junegunn Choi
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
129
src/actiontype_string.go
Normal file
129
src/actiontype_string.go
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
// Code generated by "stringer -type=actionType"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package fzf
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[actIgnore-0]
|
||||||
|
_ = x[actStart-1]
|
||||||
|
_ = x[actClick-2]
|
||||||
|
_ = x[actInvalid-3]
|
||||||
|
_ = x[actChar-4]
|
||||||
|
_ = x[actMouse-5]
|
||||||
|
_ = x[actBeginningOfLine-6]
|
||||||
|
_ = x[actAbort-7]
|
||||||
|
_ = x[actAccept-8]
|
||||||
|
_ = x[actAcceptNonEmpty-9]
|
||||||
|
_ = x[actAcceptOrPrintQuery-10]
|
||||||
|
_ = x[actBackwardChar-11]
|
||||||
|
_ = x[actBackwardDeleteChar-12]
|
||||||
|
_ = x[actBackwardDeleteCharEof-13]
|
||||||
|
_ = x[actBackwardWord-14]
|
||||||
|
_ = x[actCancel-15]
|
||||||
|
_ = x[actChangeBorderLabel-16]
|
||||||
|
_ = x[actChangeHeader-17]
|
||||||
|
_ = x[actChangePreviewLabel-18]
|
||||||
|
_ = x[actChangePrompt-19]
|
||||||
|
_ = x[actChangeQuery-20]
|
||||||
|
_ = x[actClearScreen-21]
|
||||||
|
_ = x[actClearQuery-22]
|
||||||
|
_ = x[actClearSelection-23]
|
||||||
|
_ = x[actClose-24]
|
||||||
|
_ = x[actDeleteChar-25]
|
||||||
|
_ = x[actDeleteCharEof-26]
|
||||||
|
_ = x[actEndOfLine-27]
|
||||||
|
_ = x[actForwardChar-28]
|
||||||
|
_ = x[actForwardWord-29]
|
||||||
|
_ = x[actKillLine-30]
|
||||||
|
_ = x[actKillWord-31]
|
||||||
|
_ = x[actUnixLineDiscard-32]
|
||||||
|
_ = x[actUnixWordRubout-33]
|
||||||
|
_ = x[actYank-34]
|
||||||
|
_ = x[actBackwardKillWord-35]
|
||||||
|
_ = x[actSelectAll-36]
|
||||||
|
_ = x[actDeselectAll-37]
|
||||||
|
_ = x[actToggle-38]
|
||||||
|
_ = x[actToggleSearch-39]
|
||||||
|
_ = x[actToggleAll-40]
|
||||||
|
_ = x[actToggleDown-41]
|
||||||
|
_ = x[actToggleUp-42]
|
||||||
|
_ = x[actToggleIn-43]
|
||||||
|
_ = x[actToggleOut-44]
|
||||||
|
_ = x[actToggleTrack-45]
|
||||||
|
_ = x[actToggleHeader-46]
|
||||||
|
_ = x[actTrack-47]
|
||||||
|
_ = x[actDown-48]
|
||||||
|
_ = x[actUp-49]
|
||||||
|
_ = x[actPageUp-50]
|
||||||
|
_ = x[actPageDown-51]
|
||||||
|
_ = x[actPosition-52]
|
||||||
|
_ = x[actHalfPageUp-53]
|
||||||
|
_ = x[actHalfPageDown-54]
|
||||||
|
_ = x[actOffsetUp-55]
|
||||||
|
_ = x[actOffsetDown-56]
|
||||||
|
_ = x[actJump-57]
|
||||||
|
_ = x[actJumpAccept-58]
|
||||||
|
_ = x[actPrintQuery-59]
|
||||||
|
_ = x[actRefreshPreview-60]
|
||||||
|
_ = x[actReplaceQuery-61]
|
||||||
|
_ = x[actToggleSort-62]
|
||||||
|
_ = x[actShowPreview-63]
|
||||||
|
_ = x[actHidePreview-64]
|
||||||
|
_ = x[actTogglePreview-65]
|
||||||
|
_ = x[actTogglePreviewWrap-66]
|
||||||
|
_ = x[actTransform-67]
|
||||||
|
_ = x[actTransformBorderLabel-68]
|
||||||
|
_ = x[actTransformHeader-69]
|
||||||
|
_ = x[actTransformPreviewLabel-70]
|
||||||
|
_ = x[actTransformPrompt-71]
|
||||||
|
_ = x[actTransformQuery-72]
|
||||||
|
_ = x[actPreview-73]
|
||||||
|
_ = x[actChangePreview-74]
|
||||||
|
_ = x[actChangePreviewWindow-75]
|
||||||
|
_ = x[actPreviewTop-76]
|
||||||
|
_ = x[actPreviewBottom-77]
|
||||||
|
_ = x[actPreviewUp-78]
|
||||||
|
_ = x[actPreviewDown-79]
|
||||||
|
_ = x[actPreviewPageUp-80]
|
||||||
|
_ = x[actPreviewPageDown-81]
|
||||||
|
_ = x[actPreviewHalfPageUp-82]
|
||||||
|
_ = x[actPreviewHalfPageDown-83]
|
||||||
|
_ = x[actPrevHistory-84]
|
||||||
|
_ = x[actPrevSelected-85]
|
||||||
|
_ = x[actPut-86]
|
||||||
|
_ = x[actNextHistory-87]
|
||||||
|
_ = x[actNextSelected-88]
|
||||||
|
_ = x[actExecute-89]
|
||||||
|
_ = x[actExecuteSilent-90]
|
||||||
|
_ = x[actExecuteMulti-91]
|
||||||
|
_ = x[actSigStop-92]
|
||||||
|
_ = x[actFirst-93]
|
||||||
|
_ = x[actLast-94]
|
||||||
|
_ = x[actReload-95]
|
||||||
|
_ = x[actReloadSync-96]
|
||||||
|
_ = x[actDisableSearch-97]
|
||||||
|
_ = x[actEnableSearch-98]
|
||||||
|
_ = x[actSelect-99]
|
||||||
|
_ = x[actDeselect-100]
|
||||||
|
_ = x[actUnbind-101]
|
||||||
|
_ = x[actRebind-102]
|
||||||
|
_ = x[actBecome-103]
|
||||||
|
_ = x[actResponse-104]
|
||||||
|
_ = x[actShowHeader-105]
|
||||||
|
_ = x[actHideHeader-106]
|
||||||
|
}
|
||||||
|
|
||||||
|
const _actionType_name = "actIgnoreactStartactClickactInvalidactCharactMouseactBeginningOfLineactAbortactAcceptactAcceptNonEmptyactAcceptOrPrintQueryactBackwardCharactBackwardDeleteCharactBackwardDeleteCharEofactBackwardWordactCancelactChangeBorderLabelactChangeHeaderactChangePreviewLabelactChangePromptactChangeQueryactClearScreenactClearQueryactClearSelectionactCloseactDeleteCharactDeleteCharEofactEndOfLineactForwardCharactForwardWordactKillLineactKillWordactUnixLineDiscardactUnixWordRuboutactYankactBackwardKillWordactSelectAllactDeselectAllactToggleactToggleSearchactToggleAllactToggleDownactToggleUpactToggleInactToggleOutactToggleTrackactToggleHeaderactTrackactDownactUpactPageUpactPageDownactPositionactHalfPageUpactHalfPageDownactOffsetUpactOffsetDownactJumpactJumpAcceptactPrintQueryactRefreshPreviewactReplaceQueryactToggleSortactShowPreviewactHidePreviewactTogglePreviewactTogglePreviewWrapactTransformactTransformBorderLabelactTransformHeaderactTransformPreviewLabelactTransformPromptactTransformQueryactPreviewactChangePreviewactChangePreviewWindowactPreviewTopactPreviewBottomactPreviewUpactPreviewDownactPreviewPageUpactPreviewPageDownactPreviewHalfPageUpactPreviewHalfPageDownactPrevHistoryactPrevSelectedactPutactNextHistoryactNextSelectedactExecuteactExecuteSilentactExecuteMultiactSigStopactFirstactLastactReloadactReloadSyncactDisableSearchactEnableSearchactSelectactDeselectactUnbindactRebindactBecomeactResponseactShowHeaderactHideHeader"
|
||||||
|
|
||||||
|
var _actionType_index = [...]uint16{0, 9, 17, 25, 35, 42, 50, 68, 76, 85, 102, 123, 138, 159, 183, 198, 207, 227, 242, 263, 278, 292, 306, 319, 336, 344, 357, 373, 385, 399, 413, 424, 435, 453, 470, 477, 496, 508, 522, 531, 546, 558, 571, 582, 593, 605, 619, 634, 642, 649, 654, 663, 674, 685, 698, 713, 724, 737, 744, 757, 770, 787, 802, 815, 829, 843, 859, 879, 891, 914, 932, 956, 974, 991, 1001, 1017, 1039, 1052, 1068, 1080, 1094, 1110, 1128, 1148, 1170, 1184, 1199, 1205, 1219, 1234, 1244, 1260, 1275, 1285, 1293, 1300, 1309, 1322, 1338, 1353, 1362, 1373, 1382, 1391, 1400, 1411, 1424, 1437}
|
||||||
|
|
||||||
|
func (i actionType) String() string {
|
||||||
|
if i < 0 || i >= actionType(len(_actionType_index)-1) {
|
||||||
|
return "actionType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
|
}
|
||||||
|
return _actionType_name[_actionType_index[i]:_actionType_index[i+1]]
|
||||||
|
}
|
||||||
@@ -351,9 +351,11 @@ func interpretCode(ansiCode string, prevState *ansiState) ansiState {
|
|||||||
ptr := &state.fg
|
ptr := &state.fg
|
||||||
|
|
||||||
var delimiter byte = 0
|
var delimiter byte = 0
|
||||||
|
count := 0
|
||||||
for len(ansiCode) != 0 {
|
for len(ansiCode) != 0 {
|
||||||
var num int
|
var num int
|
||||||
if num, delimiter, ansiCode = parseAnsiCode(ansiCode, delimiter); num != -1 {
|
if num, delimiter, ansiCode = parseAnsiCode(ansiCode, delimiter); num != -1 {
|
||||||
|
count++
|
||||||
switch state256 {
|
switch state256 {
|
||||||
case 0:
|
case 0:
|
||||||
switch num {
|
switch num {
|
||||||
@@ -435,6 +437,13 @@ func interpretCode(ansiCode string, prevState *ansiState) ansiState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Empty sequence: reset
|
||||||
|
if count == 0 {
|
||||||
|
state.fg = -1
|
||||||
|
state.bg = -1
|
||||||
|
state.attr = 0
|
||||||
|
}
|
||||||
|
|
||||||
if state256 > 0 {
|
if state256 > 0 {
|
||||||
*ptr = -1
|
*ptr = -1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -348,6 +348,9 @@ func TestAnsiCodeStringConversion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
assert("\x1b[m", nil, "")
|
assert("\x1b[m", nil, "")
|
||||||
assert("\x1b[m", &ansiState{attr: tui.Blink, lbg: -1}, "")
|
assert("\x1b[m", &ansiState{attr: tui.Blink, lbg: -1}, "")
|
||||||
|
assert("\x1b[0m", &ansiState{fg: 4, bg: 4, lbg: -1}, "")
|
||||||
|
assert("\x1b[;m", &ansiState{fg: 4, bg: 4, lbg: -1}, "")
|
||||||
|
assert("\x1b[;;m", &ansiState{fg: 4, bg: 4, lbg: -1}, "")
|
||||||
|
|
||||||
assert("\x1b[31m", nil, "\x1b[31;49m")
|
assert("\x1b[31m", nil, "\x1b[31;49m")
|
||||||
assert("\x1b[41m", nil, "\x1b[39;41m")
|
assert("\x1b[41m", nil, "\x1b[39;41m")
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ func Run(opts *Options, version string, revision string) {
|
|||||||
padHeight := 0
|
padHeight := 0
|
||||||
heightUnknown := opts.Height.auto
|
heightUnknown := opts.Height.auto
|
||||||
if heightUnknown {
|
if heightUnknown {
|
||||||
maxFit, padHeight = terminal.MaxFitAndPad(opts)
|
maxFit, padHeight = terminal.MaxFitAndPad()
|
||||||
}
|
}
|
||||||
deferred := opts.Select1 || opts.Exit0
|
deferred := opts.Select1 || opts.Exit0
|
||||||
go terminal.Loop()
|
go terminal.Loop()
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import (
|
|||||||
"github.com/junegunn/fzf/src/algo"
|
"github.com/junegunn/fzf/src/algo"
|
||||||
"github.com/junegunn/fzf/src/tui"
|
"github.com/junegunn/fzf/src/tui"
|
||||||
"github.com/junegunn/fzf/src/util"
|
"github.com/junegunn/fzf/src/util"
|
||||||
|
"github.com/junegunn/uniseg"
|
||||||
|
|
||||||
"github.com/mattn/go-runewidth"
|
|
||||||
"github.com/mattn/go-shellwords"
|
"github.com/mattn/go-shellwords"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -57,6 +57,8 @@ const usage = `usage: fzf [options]
|
|||||||
Layout
|
Layout
|
||||||
--height=[~]HEIGHT[%] Display fzf window below the cursor with the given
|
--height=[~]HEIGHT[%] Display fzf window below the cursor with the given
|
||||||
height instead of using fullscreen.
|
height instead of using fullscreen.
|
||||||
|
A negative value is calcalated as the terminal height
|
||||||
|
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 when --height is given in percent
|
--min-height=HEIGHT Minimum height when --height is given in percent
|
||||||
@@ -157,6 +159,7 @@ type heightSpec struct {
|
|||||||
size float64
|
size float64
|
||||||
percent bool
|
percent bool
|
||||||
auto bool
|
auto bool
|
||||||
|
inverse bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type sizeSpec struct {
|
type sizeSpec struct {
|
||||||
@@ -334,6 +337,7 @@ type Options struct {
|
|||||||
BorderLabel labelOpts
|
BorderLabel labelOpts
|
||||||
PreviewLabel labelOpts
|
PreviewLabel labelOpts
|
||||||
Unicode bool
|
Unicode bool
|
||||||
|
Ambidouble bool
|
||||||
Tabstop int
|
Tabstop int
|
||||||
ListenAddr *listenAddress
|
ListenAddr *listenAddress
|
||||||
Unsafe bool
|
Unsafe bool
|
||||||
@@ -403,6 +407,7 @@ func defaultOptions() *Options {
|
|||||||
Margin: defaultMargin(),
|
Margin: defaultMargin(),
|
||||||
Padding: defaultMargin(),
|
Padding: defaultMargin(),
|
||||||
Unicode: true,
|
Unicode: true,
|
||||||
|
Ambidouble: os.Getenv("RUNEWIDTH_EASTASIAN") == "1",
|
||||||
Tabstop: 8,
|
Tabstop: 8,
|
||||||
BorderLabel: labelOpts{},
|
BorderLabel: labelOpts{},
|
||||||
PreviewLabel: labelOpts{},
|
PreviewLabel: labelOpts{},
|
||||||
@@ -647,6 +652,10 @@ func parseKeyChordsImpl(str string, message string, exit func(string)) map[tui.E
|
|||||||
add(tui.Load)
|
add(tui.Load)
|
||||||
case "focus":
|
case "focus":
|
||||||
add(tui.Focus)
|
add(tui.Focus)
|
||||||
|
case "result":
|
||||||
|
add(tui.Result)
|
||||||
|
case "resize":
|
||||||
|
add(tui.Resize)
|
||||||
case "one":
|
case "one":
|
||||||
add(tui.One)
|
add(tui.One)
|
||||||
case "zero":
|
case "zero":
|
||||||
@@ -976,7 +985,7 @@ const (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
executeRegexp = regexp.MustCompile(
|
executeRegexp = regexp.MustCompile(
|
||||||
`(?si)[:+](become|execute(?:-multi|-silent)?|reload(?:-sync)?|preview|(?:change|transform)-(?:header|query|prompt|border-label|preview-label)|change-preview-window|change-preview|(?:re|un)bind|pos|put)`)
|
`(?si)[:+](become|execute(?:-multi|-silent)?|reload(?:-sync)?|preview|(?:change|transform)-(?:header|query|prompt|border-label|preview-label)|transform|change-preview-window|change-preview|(?:re|un)bind|pos|put)`)
|
||||||
splitRegexp = regexp.MustCompile("[,:]+")
|
splitRegexp = regexp.MustCompile("[,:]+")
|
||||||
actionNameRegexp = regexp.MustCompile("(?i)^[a-z-]+")
|
actionNameRegexp = regexp.MustCompile("(?i)^[a-z-]+")
|
||||||
}
|
}
|
||||||
@@ -1070,6 +1079,8 @@ func parseActionList(masked string, original string, prevActions []*action, putA
|
|||||||
appendAction(actAccept)
|
appendAction(actAccept)
|
||||||
case "accept-non-empty":
|
case "accept-non-empty":
|
||||||
appendAction(actAcceptNonEmpty)
|
appendAction(actAcceptNonEmpty)
|
||||||
|
case "accept-or-print-query":
|
||||||
|
appendAction(actAcceptOrPrintQuery)
|
||||||
case "print-query":
|
case "print-query":
|
||||||
appendAction(actPrintQuery)
|
appendAction(actPrintQuery)
|
||||||
case "refresh-preview":
|
case "refresh-preview":
|
||||||
@@ -1081,7 +1092,7 @@ func parseActionList(masked string, original string, prevActions []*action, putA
|
|||||||
case "backward-delete-char":
|
case "backward-delete-char":
|
||||||
appendAction(actBackwardDeleteChar)
|
appendAction(actBackwardDeleteChar)
|
||||||
case "backward-delete-char/eof":
|
case "backward-delete-char/eof":
|
||||||
appendAction(actBackwardDeleteCharEOF)
|
appendAction(actBackwardDeleteCharEof)
|
||||||
case "backward-word":
|
case "backward-word":
|
||||||
appendAction(actBackwardWord)
|
appendAction(actBackwardWord)
|
||||||
case "clear-screen":
|
case "clear-screen":
|
||||||
@@ -1089,7 +1100,7 @@ func parseActionList(masked string, original string, prevActions []*action, putA
|
|||||||
case "delete-char":
|
case "delete-char":
|
||||||
appendAction(actDeleteChar)
|
appendAction(actDeleteChar)
|
||||||
case "delete-char/eof":
|
case "delete-char/eof":
|
||||||
appendAction(actDeleteCharEOF)
|
appendAction(actDeleteCharEof)
|
||||||
case "deselect":
|
case "deselect":
|
||||||
appendAction(actDeselect)
|
appendAction(actDeselect)
|
||||||
case "end-of-line":
|
case "end-of-line":
|
||||||
@@ -1136,6 +1147,10 @@ func parseActionList(masked string, original string, prevActions []*action, putA
|
|||||||
appendAction(actToggleTrack)
|
appendAction(actToggleTrack)
|
||||||
case "toggle-header":
|
case "toggle-header":
|
||||||
appendAction(actToggleHeader)
|
appendAction(actToggleHeader)
|
||||||
|
case "show-header":
|
||||||
|
appendAction(actShowHeader)
|
||||||
|
case "hide-header":
|
||||||
|
appendAction(actHideHeader)
|
||||||
case "track":
|
case "track":
|
||||||
appendAction(actTrack)
|
appendAction(actTrack)
|
||||||
case "select":
|
case "select":
|
||||||
@@ -1208,7 +1223,7 @@ func parseActionList(masked string, original string, prevActions []*action, putA
|
|||||||
appendAction(actDisableSearch)
|
appendAction(actDisableSearch)
|
||||||
case "put":
|
case "put":
|
||||||
if putAllowed {
|
if putAllowed {
|
||||||
appendAction(actRune)
|
appendAction(actChar)
|
||||||
} else {
|
} else {
|
||||||
exit("unable to put non-printable character")
|
exit("unable to put non-printable character")
|
||||||
}
|
}
|
||||||
@@ -1328,6 +1343,8 @@ func isExecuteAction(str string) actionType {
|
|||||||
return actExecuteMulti
|
return actExecuteMulti
|
||||||
case "put":
|
case "put":
|
||||||
return actPut
|
return actPut
|
||||||
|
case "transform":
|
||||||
|
return actTransform
|
||||||
case "transform-border-label":
|
case "transform-border-label":
|
||||||
return actTransformBorderLabel
|
return actTransformBorderLabel
|
||||||
case "transform-preview-label":
|
case "transform-preview-label":
|
||||||
@@ -1384,6 +1401,13 @@ func parseHeight(str string) heightSpec {
|
|||||||
heightSpec.auto = true
|
heightSpec.auto = true
|
||||||
str = str[1:]
|
str = str[1:]
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(str, "-") {
|
||||||
|
if heightSpec.auto {
|
||||||
|
errorExit("negative(-) height is not compatible with adaptive(~) height")
|
||||||
|
}
|
||||||
|
heightSpec.inverse = true
|
||||||
|
str = str[1:]
|
||||||
|
}
|
||||||
|
|
||||||
size := parseSize(str, 100, "height")
|
size := parseSize(str, 100, "height")
|
||||||
heightSpec.size = size.size
|
heightSpec.size = size.size
|
||||||
@@ -1573,8 +1597,6 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
validateJumpLabels := false
|
validateJumpLabels := false
|
||||||
validatePointer := false
|
|
||||||
validateMarker := false
|
|
||||||
for i := 0; i < len(allArgs); i++ {
|
for i := 0; i < len(allArgs); i++ {
|
||||||
arg := allArgs[i]
|
arg := allArgs[i]
|
||||||
switch arg {
|
switch arg {
|
||||||
@@ -1754,10 +1776,8 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
opts.Prompt = nextString(allArgs, &i, "prompt string required")
|
opts.Prompt = nextString(allArgs, &i, "prompt string required")
|
||||||
case "--pointer":
|
case "--pointer":
|
||||||
opts.Pointer = firstLine(nextString(allArgs, &i, "pointer sign string required"))
|
opts.Pointer = firstLine(nextString(allArgs, &i, "pointer sign string required"))
|
||||||
validatePointer = true
|
|
||||||
case "--marker":
|
case "--marker":
|
||||||
opts.Marker = firstLine(nextString(allArgs, &i, "selected sign string required"))
|
opts.Marker = firstLine(nextString(allArgs, &i, "selected sign string required"))
|
||||||
validateMarker = true
|
|
||||||
case "--sync":
|
case "--sync":
|
||||||
opts.Sync = true
|
opts.Sync = true
|
||||||
case "--no-sync":
|
case "--no-sync":
|
||||||
@@ -1825,6 +1845,10 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
opts.Unicode = false
|
opts.Unicode = false
|
||||||
case "--unicode":
|
case "--unicode":
|
||||||
opts.Unicode = true
|
opts.Unicode = true
|
||||||
|
case "--ambidouble":
|
||||||
|
opts.Ambidouble = true
|
||||||
|
case "--no-ambidouble":
|
||||||
|
opts.Ambidouble = false
|
||||||
case "--margin":
|
case "--margin":
|
||||||
opts.Margin = parseMargin(
|
opts.Margin = parseMargin(
|
||||||
"margin",
|
"margin",
|
||||||
@@ -1883,10 +1907,8 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
opts.Prompt = value
|
opts.Prompt = value
|
||||||
} else if match, value := optString(arg, "--pointer="); match {
|
} else if match, value := optString(arg, "--pointer="); match {
|
||||||
opts.Pointer = firstLine(value)
|
opts.Pointer = firstLine(value)
|
||||||
validatePointer = true
|
|
||||||
} else if match, value := optString(arg, "--marker="); match {
|
} else if match, value := optString(arg, "--marker="); match {
|
||||||
opts.Marker = firstLine(value)
|
opts.Marker = firstLine(value)
|
||||||
validateMarker = true
|
|
||||||
} else if match, value := optString(arg, "-n", "--nth="); match {
|
} else if match, value := optString(arg, "-n", "--nth="); match {
|
||||||
opts.Nth = splitNth(value)
|
opts.Nth = splitNth(value)
|
||||||
} else if match, value := optString(arg, "--with-nth="); match {
|
} else if match, value := optString(arg, "--with-nth="); match {
|
||||||
@@ -1993,31 +2015,31 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if validatePointer {
|
|
||||||
if err := validateSign(opts.Pointer, "pointer"); err != nil {
|
|
||||||
errorExit(err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if validateMarker {
|
|
||||||
if err := validateSign(opts.Marker, "marker"); err != nil {
|
|
||||||
errorExit(err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateSign(sign string, signOptName string) error {
|
func validateSign(sign string, signOptName string) error {
|
||||||
if sign == "" {
|
if sign == "" {
|
||||||
return fmt.Errorf("%v cannot be empty", signOptName)
|
return fmt.Errorf("%v cannot be empty", signOptName)
|
||||||
}
|
}
|
||||||
if runewidth.StringWidth(sign) > 2 {
|
if uniseg.StringWidth(sign) > 2 {
|
||||||
return fmt.Errorf("%v display width should be up to 2", signOptName)
|
return fmt.Errorf("%v display width should be up to 2", signOptName)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func postProcessOptions(opts *Options) {
|
func postProcessOptions(opts *Options) {
|
||||||
|
if opts.Ambidouble {
|
||||||
|
uniseg.EastAsianAmbiguousWidth = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := validateSign(opts.Pointer, "pointer"); err != nil {
|
||||||
|
errorExit(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := validateSign(opts.Marker, "marker"); err != nil {
|
||||||
|
errorExit(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
if !opts.Version && !tui.IsLightRendererSupported() && opts.Height.size > 0 {
|
if !opts.Version && !tui.IsLightRendererSupported() && opts.Height.size > 0 {
|
||||||
errorExit("--height option is currently not supported on this platform")
|
errorExit("--height option is currently not supported on this platform")
|
||||||
}
|
}
|
||||||
@@ -2028,7 +2050,7 @@ func postProcessOptions(opts *Options) {
|
|||||||
errorExit("--scrollbar should be given one or two characters")
|
errorExit("--scrollbar should be given one or two characters")
|
||||||
}
|
}
|
||||||
for _, r := range runes {
|
for _, r := range runes {
|
||||||
if runewidth.RuneWidth(r) != 1 {
|
if uniseg.StringWidth(string(r)) != 1 {
|
||||||
errorExit("scrollbar display width should be 1")
|
errorExit("scrollbar display width should be 1")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ import "golang.org/x/sys/unix"
|
|||||||
|
|
||||||
// Protect calls OS specific protections like pledge on OpenBSD
|
// Protect calls OS specific protections like pledge on OpenBSD
|
||||||
func Protect() {
|
func Protect() {
|
||||||
unix.PledgePromises("stdio rpath tty proc exec inet")
|
unix.PledgePromises("stdio rpath tty proc exec inet tmppath")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ func buildResult(item *Item, offsets []Offset, score int) Result {
|
|||||||
if criterion == byBegin {
|
if criterion == byBegin {
|
||||||
val = util.AsUint16(minEnd - whitePrefixLen)
|
val = util.AsUint16(minEnd - whitePrefixLen)
|
||||||
} else {
|
} else {
|
||||||
val = util.AsUint16(math.MaxUint16 - math.MaxUint16*(maxEnd-whitePrefixLen)/int(item.TrimLength()))
|
val = util.AsUint16(math.MaxUint16 - math.MaxUint16*(maxEnd-whitePrefixLen)/int(item.TrimLength()+1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,9 @@ func (result *Result) colorOffsets(matchOffsets []Offset, theme *tui.ColorTheme,
|
|||||||
for i := off[0]; i < off[1]; i++ {
|
for i := off[0]; i < off[1]; i++ {
|
||||||
// Negative of 1-based index of itemColors
|
// Negative of 1-based index of itemColors
|
||||||
// - The extra -1 means highlighted
|
// - The extra -1 means highlighted
|
||||||
cols[i] = cols[i]*-1 - 1
|
if cols[i] >= 0 {
|
||||||
|
cols[i] = cols[i]*-1 - 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ func TestColorOffset(t *testing.T) {
|
|||||||
// ++++++++ ++++++++++
|
// ++++++++ ++++++++++
|
||||||
// --++++++++-- --++++++++++---
|
// --++++++++-- --++++++++++---
|
||||||
|
|
||||||
offsets := []Offset{{5, 15}, {25, 35}}
|
offsets := []Offset{{5, 15}, {10, 12}, {25, 35}}
|
||||||
item := Result{
|
item := Result{
|
||||||
item: &Item{
|
item: &Item{
|
||||||
colors: &[]ansiOffset{
|
colors: &[]ansiOffset{
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ const (
|
|||||||
httpOk = "HTTP/1.1 200 OK" + crlf
|
httpOk = "HTTP/1.1 200 OK" + crlf
|
||||||
httpBadRequest = "HTTP/1.1 400 Bad Request" + crlf
|
httpBadRequest = "HTTP/1.1 400 Bad Request" + crlf
|
||||||
httpUnauthorized = "HTTP/1.1 401 Unauthorized" + crlf
|
httpUnauthorized = "HTTP/1.1 401 Unauthorized" + crlf
|
||||||
|
httpUnavailable = "HTTP/1.1 503 Service Unavailable" + crlf
|
||||||
httpReadTimeout = 10 * time.Second
|
httpReadTimeout = 10 * time.Second
|
||||||
|
jsonContentType = "Content-Type: application/json" + crlf
|
||||||
maxContentLength = 1024 * 1024
|
maxContentLength = 1024 * 1024
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -141,7 +143,7 @@ func (server *httpServer) handleHttpRequest(conn net.Conn) string {
|
|||||||
return answer(httpBadRequest, message)
|
return answer(httpBadRequest, message)
|
||||||
}
|
}
|
||||||
good := func(message string) string {
|
good := func(message string) string {
|
||||||
return answer(httpOk+"Content-Type: application/json"+crlf, message)
|
return answer(httpOk+jsonContentType, message)
|
||||||
}
|
}
|
||||||
conn.SetReadDeadline(time.Now().Add(httpReadTimeout))
|
conn.SetReadDeadline(time.Now().Add(httpReadTimeout))
|
||||||
scanner := bufio.NewScanner(conn)
|
scanner := bufio.NewScanner(conn)
|
||||||
@@ -165,8 +167,16 @@ func (server *httpServer) handleHttpRequest(conn net.Conn) string {
|
|||||||
getMatch := getRegex.FindStringSubmatch(text)
|
getMatch := getRegex.FindStringSubmatch(text)
|
||||||
if len(getMatch) > 0 {
|
if len(getMatch) > 0 {
|
||||||
server.actionChannel <- []*action{{t: actResponse, a: getMatch[1]}}
|
server.actionChannel <- []*action{{t: actResponse, a: getMatch[1]}}
|
||||||
response := <-server.responseChannel
|
select {
|
||||||
return good(response)
|
case response := <-server.responseChannel:
|
||||||
|
return good(response)
|
||||||
|
case <-time.After(2 * time.Second):
|
||||||
|
go func() {
|
||||||
|
// Drain the channel
|
||||||
|
<-server.responseChannel
|
||||||
|
}()
|
||||||
|
return answer(httpUnavailable+jsonContentType, `{"error":"timeout"}`)
|
||||||
|
}
|
||||||
} else if !strings.HasPrefix(text, "POST / HTTP") {
|
} else if !strings.HasPrefix(text, "POST / HTTP") {
|
||||||
return bad("invalid request method")
|
return bad("invalid request method")
|
||||||
}
|
}
|
||||||
@@ -218,7 +228,7 @@ func (server *httpServer) handleHttpRequest(conn net.Conn) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
server.actionChannel <- actions
|
server.actionChannel <- actions
|
||||||
return httpOk
|
return httpOk + crlf
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseGetParams(query string) getParams {
|
func parseGetParams(query string) getParams {
|
||||||
|
|||||||
267
src/terminal.go
267
src/terminal.go
@@ -17,8 +17,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mattn/go-runewidth"
|
"github.com/junegunn/uniseg"
|
||||||
"github.com/rivo/uniseg"
|
|
||||||
|
|
||||||
"github.com/junegunn/fzf/src/tui"
|
"github.com/junegunn/fzf/src/tui"
|
||||||
"github.com/junegunn/fzf/src/util"
|
"github.com/junegunn/fzf/src/util"
|
||||||
@@ -52,11 +51,12 @@ var offsetComponentRegex *regexp.Regexp
|
|||||||
var offsetTrimCharsRegex *regexp.Regexp
|
var offsetTrimCharsRegex *regexp.Regexp
|
||||||
var activeTempFiles []string
|
var activeTempFiles []string
|
||||||
var passThroughRegex *regexp.Regexp
|
var passThroughRegex *regexp.Regexp
|
||||||
|
var actionTypeRegex *regexp.Regexp
|
||||||
|
|
||||||
const clearCode string = "\x1b[2J"
|
const clearCode string = "\x1b[2J"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
placeholder = regexp.MustCompile(`\\?(?:{[+sf]*[0-9,-.]*}|{q}|{\+?f?nf?})`)
|
placeholder = regexp.MustCompile(`\\?(?:{[+sf]*[0-9,-.]*}|{q}|{fzf:(?:query|action|prompt)}|{\+?f?nf?})`)
|
||||||
whiteSuffix = regexp.MustCompile(`\s*$`)
|
whiteSuffix = regexp.MustCompile(`\s*$`)
|
||||||
offsetComponentRegex = regexp.MustCompile(`([+-][0-9]+)|(-?/[1-9][0-9]*)`)
|
offsetComponentRegex = regexp.MustCompile(`([+-][0-9]+)|(-?/[1-9][0-9]*)`)
|
||||||
offsetTrimCharsRegex = regexp.MustCompile(`[^0-9/+-]`)
|
offsetTrimCharsRegex = regexp.MustCompile(`[^0-9/+-]`)
|
||||||
@@ -182,6 +182,7 @@ type Terminal struct {
|
|||||||
separator labelPrinter
|
separator labelPrinter
|
||||||
separatorLen int
|
separatorLen int
|
||||||
spinner []string
|
spinner []string
|
||||||
|
promptString string
|
||||||
prompt func()
|
prompt func()
|
||||||
promptLen int
|
promptLen int
|
||||||
borderLabel labelPrinter
|
borderLabel labelPrinter
|
||||||
@@ -249,7 +250,10 @@ type Terminal struct {
|
|||||||
borderWidth int
|
borderWidth int
|
||||||
count int
|
count int
|
||||||
progress int
|
progress int
|
||||||
|
hasResultActions bool
|
||||||
|
hasFocusActions bool
|
||||||
hasLoadActions bool
|
hasLoadActions bool
|
||||||
|
hasResizeActions bool
|
||||||
triggerLoad bool
|
triggerLoad bool
|
||||||
reading bool
|
reading bool
|
||||||
running bool
|
running bool
|
||||||
@@ -285,6 +289,10 @@ type Terminal struct {
|
|||||||
tui tui.Renderer
|
tui tui.Renderer
|
||||||
executing *util.AtomicBool
|
executing *util.AtomicBool
|
||||||
termSize tui.TermSize
|
termSize tui.TermSize
|
||||||
|
lastAction actionType
|
||||||
|
lastFocus int32
|
||||||
|
areaLines int
|
||||||
|
areaColumns int
|
||||||
}
|
}
|
||||||
|
|
||||||
type selectedItem struct {
|
type selectedItem struct {
|
||||||
@@ -332,20 +340,24 @@ type action struct {
|
|||||||
a string
|
a string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:generate stringer -type=actionType
|
||||||
type actionType int
|
type actionType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
actIgnore actionType = iota
|
actIgnore actionType = iota
|
||||||
|
actStart
|
||||||
|
actClick
|
||||||
actInvalid
|
actInvalid
|
||||||
actRune
|
actChar
|
||||||
actMouse
|
actMouse
|
||||||
actBeginningOfLine
|
actBeginningOfLine
|
||||||
actAbort
|
actAbort
|
||||||
actAccept
|
actAccept
|
||||||
actAcceptNonEmpty
|
actAcceptNonEmpty
|
||||||
|
actAcceptOrPrintQuery
|
||||||
actBackwardChar
|
actBackwardChar
|
||||||
actBackwardDeleteChar
|
actBackwardDeleteChar
|
||||||
actBackwardDeleteCharEOF
|
actBackwardDeleteCharEof
|
||||||
actBackwardWord
|
actBackwardWord
|
||||||
actCancel
|
actCancel
|
||||||
actChangeBorderLabel
|
actChangeBorderLabel
|
||||||
@@ -358,7 +370,7 @@ const (
|
|||||||
actClearSelection
|
actClearSelection
|
||||||
actClose
|
actClose
|
||||||
actDeleteChar
|
actDeleteChar
|
||||||
actDeleteCharEOF
|
actDeleteCharEof
|
||||||
actEndOfLine
|
actEndOfLine
|
||||||
actForwardChar
|
actForwardChar
|
||||||
actForwardWord
|
actForwardWord
|
||||||
@@ -399,6 +411,7 @@ const (
|
|||||||
actHidePreview
|
actHidePreview
|
||||||
actTogglePreview
|
actTogglePreview
|
||||||
actTogglePreviewWrap
|
actTogglePreviewWrap
|
||||||
|
actTransform
|
||||||
actTransformBorderLabel
|
actTransformBorderLabel
|
||||||
actTransformHeader
|
actTransformHeader
|
||||||
actTransformPreviewLabel
|
actTransformPreviewLabel
|
||||||
@@ -436,17 +449,32 @@ const (
|
|||||||
actRebind
|
actRebind
|
||||||
actBecome
|
actBecome
|
||||||
actResponse
|
actResponse
|
||||||
|
actShowHeader
|
||||||
|
actHideHeader
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (a actionType) Name() string {
|
||||||
|
name := ""
|
||||||
|
for i, r := range a.String()[3:] {
|
||||||
|
if i > 0 && r >= 'A' && r <= 'Z' {
|
||||||
|
name += "-"
|
||||||
|
}
|
||||||
|
name += string(r)
|
||||||
|
}
|
||||||
|
return strings.ToLower(name)
|
||||||
|
}
|
||||||
|
|
||||||
func processExecution(action actionType) bool {
|
func processExecution(action actionType) bool {
|
||||||
switch action {
|
switch action {
|
||||||
case actTransformBorderLabel,
|
case actTransform,
|
||||||
|
actTransformBorderLabel,
|
||||||
actTransformHeader,
|
actTransformHeader,
|
||||||
actTransformPreviewLabel,
|
actTransformPreviewLabel,
|
||||||
actTransformPrompt,
|
actTransformPrompt,
|
||||||
actTransformQuery,
|
actTransformQuery,
|
||||||
actPreview,
|
actPreview,
|
||||||
actChangePreview,
|
actChangePreview,
|
||||||
|
actRefreshPreview,
|
||||||
actExecute,
|
actExecute,
|
||||||
actExecuteSilent,
|
actExecuteSilent,
|
||||||
actExecuteMulti,
|
actExecuteMulti,
|
||||||
@@ -462,7 +490,7 @@ type placeholderFlags struct {
|
|||||||
plus bool
|
plus bool
|
||||||
preserveSpace bool
|
preserveSpace bool
|
||||||
number bool
|
number bool
|
||||||
query bool
|
forceUpdate bool
|
||||||
file bool
|
file bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,6 +503,7 @@ type searchRequest struct {
|
|||||||
|
|
||||||
type previewRequest struct {
|
type previewRequest struct {
|
||||||
template string
|
template string
|
||||||
|
pwindow tui.Window
|
||||||
pwindowSize tui.TermSize
|
pwindowSize tui.TermSize
|
||||||
scrollOffset int
|
scrollOffset int
|
||||||
list []*Item
|
list []*Item
|
||||||
@@ -505,14 +534,13 @@ func defaultKeymap() map[tui.Event][]*action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
add(tui.Invalid, actInvalid)
|
add(tui.Invalid, actInvalid)
|
||||||
add(tui.Resize, actClearScreen)
|
|
||||||
add(tui.CtrlA, actBeginningOfLine)
|
add(tui.CtrlA, actBeginningOfLine)
|
||||||
add(tui.CtrlB, actBackwardChar)
|
add(tui.CtrlB, actBackwardChar)
|
||||||
add(tui.CtrlC, actAbort)
|
add(tui.CtrlC, actAbort)
|
||||||
add(tui.CtrlG, actAbort)
|
add(tui.CtrlG, actAbort)
|
||||||
add(tui.CtrlQ, actAbort)
|
add(tui.CtrlQ, actAbort)
|
||||||
add(tui.ESC, actAbort)
|
add(tui.ESC, actAbort)
|
||||||
add(tui.CtrlD, actDeleteCharEOF)
|
add(tui.CtrlD, actDeleteCharEof)
|
||||||
add(tui.CtrlE, actEndOfLine)
|
add(tui.CtrlE, actEndOfLine)
|
||||||
add(tui.CtrlF, actForwardChar)
|
add(tui.CtrlF, actForwardChar)
|
||||||
add(tui.CtrlH, actBackwardDeleteChar)
|
add(tui.CtrlH, actBackwardDeleteChar)
|
||||||
@@ -554,7 +582,7 @@ func defaultKeymap() map[tui.Event][]*action {
|
|||||||
add(tui.SDown, actPreviewDown)
|
add(tui.SDown, actPreviewDown)
|
||||||
|
|
||||||
add(tui.Mouse, actMouse)
|
add(tui.Mouse, actMouse)
|
||||||
add(tui.LeftClick, actIgnore)
|
add(tui.LeftClick, actClick)
|
||||||
add(tui.RightClick, actToggle)
|
add(tui.RightClick, actToggle)
|
||||||
add(tui.SLeftClick, actToggle)
|
add(tui.SLeftClick, actToggle)
|
||||||
add(tui.SRightClick, actToggle)
|
add(tui.SRightClick, actToggle)
|
||||||
@@ -573,10 +601,14 @@ func trimQuery(query string) []rune {
|
|||||||
return []rune(strings.Replace(query, "\t", " ", -1))
|
return []rune(strings.Replace(query, "\t", " ", -1))
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasPreviewAction(opts *Options) bool {
|
func mayTriggerPreview(opts *Options) bool {
|
||||||
|
if opts.ListenAddr != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
for _, actions := range opts.Keymap {
|
for _, actions := range opts.Keymap {
|
||||||
for _, action := range actions {
|
for _, action := range actions {
|
||||||
if action.t == actPreview || action.t == actChangePreview {
|
switch action.t {
|
||||||
|
case actPreview, actChangePreview, actTransform:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -592,10 +624,17 @@ func makeSpinner(unicode bool) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func evaluateHeight(opts *Options, termHeight int) int {
|
func evaluateHeight(opts *Options, termHeight int) int {
|
||||||
|
size := opts.Height.size
|
||||||
if opts.Height.percent {
|
if opts.Height.percent {
|
||||||
return util.Max(int(opts.Height.size*float64(termHeight)/100.0), opts.MinHeight)
|
if opts.Height.inverse {
|
||||||
|
size = 100 - size
|
||||||
|
}
|
||||||
|
return util.Max(int(size*float64(termHeight)/100.0), opts.MinHeight)
|
||||||
}
|
}
|
||||||
return int(opts.Height.size)
|
if opts.Height.inverse {
|
||||||
|
size = float64(termHeight) - size
|
||||||
|
}
|
||||||
|
return int(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTerminal returns new Terminal object
|
// NewTerminal returns new Terminal object
|
||||||
@@ -608,8 +647,11 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
delay = initialDelay
|
delay = initialDelay
|
||||||
}
|
}
|
||||||
var previewBox *util.EventBox
|
var previewBox *util.EventBox
|
||||||
// We need to start previewer if HTTP server is enabled even when --preview option is not specified
|
// We need to start the previewer even when --preview option is not specified
|
||||||
if len(opts.Preview.command) > 0 || hasPreviewAction(opts) || opts.ListenAddr != nil {
|
// * if HTTP server is enabled
|
||||||
|
// * if 'preview' or 'change-preview' action is bound to a key
|
||||||
|
// * if 'transform' action is bound to a key
|
||||||
|
if len(opts.Preview.command) > 0 || mayTriggerPreview(opts) {
|
||||||
previewBox = util.NewEventBox()
|
previewBox = util.NewEventBox()
|
||||||
}
|
}
|
||||||
var renderer tui.Renderer
|
var renderer tui.Renderer
|
||||||
@@ -653,6 +695,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
infoSep: opts.InfoSep,
|
infoSep: opts.InfoSep,
|
||||||
separator: nil,
|
separator: nil,
|
||||||
spinner: makeSpinner(opts.Unicode),
|
spinner: makeSpinner(opts.Unicode),
|
||||||
|
promptString: opts.Prompt,
|
||||||
queryLen: [2]int{0, 0},
|
queryLen: [2]int{0, 0},
|
||||||
layout: opts.Layout,
|
layout: opts.Layout,
|
||||||
fullscreen: fullscreen,
|
fullscreen: fullscreen,
|
||||||
@@ -701,6 +744,8 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
ellipsis: opts.Ellipsis,
|
ellipsis: opts.Ellipsis,
|
||||||
ansi: opts.Ansi,
|
ansi: opts.Ansi,
|
||||||
tabstop: opts.Tabstop,
|
tabstop: opts.Tabstop,
|
||||||
|
hasResultActions: false,
|
||||||
|
hasFocusActions: false,
|
||||||
hasLoadActions: false,
|
hasLoadActions: false,
|
||||||
triggerLoad: false,
|
triggerLoad: false,
|
||||||
reading: true,
|
reading: true,
|
||||||
@@ -728,10 +773,12 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
killChan: make(chan int),
|
killChan: make(chan int),
|
||||||
serverInputChan: make(chan []*action, 10),
|
serverInputChan: make(chan []*action, 10),
|
||||||
serverOutputChan: make(chan string),
|
serverOutputChan: make(chan string),
|
||||||
eventChan: make(chan tui.Event, 1),
|
eventChan: make(chan tui.Event, 6), // (load + result + zero|one) | (focus) | (resize) | (GetChar)
|
||||||
tui: renderer,
|
tui: renderer,
|
||||||
initFunc: func() { renderer.Init() },
|
initFunc: func() { renderer.Init() },
|
||||||
executing: util.NewAtomicBool(false)}
|
executing: util.NewAtomicBool(false),
|
||||||
|
lastAction: actStart,
|
||||||
|
lastFocus: minItem.Index()}
|
||||||
t.prompt, t.promptLen = t.parsePrompt(opts.Prompt)
|
t.prompt, t.promptLen = t.parsePrompt(opts.Prompt)
|
||||||
t.pointer, t.pointerLen = t.processTabs([]rune(opts.Pointer), 0)
|
t.pointer, t.pointerLen = t.processTabs([]rune(opts.Pointer), 0)
|
||||||
t.marker, t.markerLen = t.processTabs([]rune(opts.Marker), 0)
|
t.marker, t.markerLen = t.processTabs([]rune(opts.Marker), 0)
|
||||||
@@ -750,7 +797,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
t.separator, t.separatorLen = t.ansiLabelPrinter(bar, &tui.ColSeparator, true)
|
t.separator, t.separatorLen = t.ansiLabelPrinter(bar, &tui.ColSeparator, true)
|
||||||
}
|
}
|
||||||
if t.unicode {
|
if t.unicode {
|
||||||
t.borderWidth = runewidth.RuneWidth('│')
|
t.borderWidth = uniseg.StringWidth("│")
|
||||||
}
|
}
|
||||||
if opts.Scrollbar == nil {
|
if opts.Scrollbar == nil {
|
||||||
if t.unicode && t.borderWidth == 1 {
|
if t.unicode && t.borderWidth == 1 {
|
||||||
@@ -770,6 +817,9 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, t.hasResizeActions = t.keymap[tui.Resize.AsEvent()]
|
||||||
|
_, t.hasResultActions = t.keymap[tui.Result.AsEvent()]
|
||||||
|
_, t.hasFocusActions = t.keymap[tui.Focus.AsEvent()]
|
||||||
_, t.hasLoadActions = t.keymap[tui.Load.AsEvent()]
|
_, t.hasLoadActions = t.keymap[tui.Load.AsEvent()]
|
||||||
|
|
||||||
if t.listenAddr != nil {
|
if t.listenAddr != nil {
|
||||||
@@ -788,6 +838,14 @@ func (t *Terminal) environ() []string {
|
|||||||
if t.listenPort != nil {
|
if t.listenPort != nil {
|
||||||
env = append(env, fmt.Sprintf("FZF_PORT=%d", *t.listenPort))
|
env = append(env, fmt.Sprintf("FZF_PORT=%d", *t.listenPort))
|
||||||
}
|
}
|
||||||
|
env = append(env, "FZF_QUERY="+string(t.input))
|
||||||
|
env = append(env, "FZF_ACTION="+t.lastAction.Name())
|
||||||
|
env = append(env, "FZF_PROMPT="+string(t.promptString))
|
||||||
|
env = append(env, fmt.Sprintf("FZF_TOTAL_COUNT=%d", t.count))
|
||||||
|
env = append(env, fmt.Sprintf("FZF_MATCH_COUNT=%d", t.merger.Length()))
|
||||||
|
env = append(env, fmt.Sprintf("FZF_SELECT_COUNT=%d", len(t.selected)))
|
||||||
|
env = append(env, fmt.Sprintf("FZF_LINES=%d", t.areaLines))
|
||||||
|
env = append(env, fmt.Sprintf("FZF_COLUMNS=%d", t.areaColumns))
|
||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -817,7 +875,7 @@ func (t *Terminal) extraLines() int {
|
|||||||
return extra
|
return extra
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) MaxFitAndPad(opts *Options) (int, int) {
|
func (t *Terminal) MaxFitAndPad() (int, int) {
|
||||||
_, screenHeight, marginInt, paddingInt := t.adjustMarginAndPadding()
|
_, screenHeight, marginInt, paddingInt := t.adjustMarginAndPadding()
|
||||||
padHeight := marginInt[0] + marginInt[2] + paddingInt[0] + paddingInt[2]
|
padHeight := marginInt[0] + marginInt[2] + paddingInt[0] + paddingInt[2]
|
||||||
fit := screenHeight - padHeight - t.extraLines()
|
fit := screenHeight - padHeight - t.extraLines()
|
||||||
@@ -1042,6 +1100,9 @@ func (t *Terminal) UpdateList(merger *Merger) {
|
|||||||
t.eventChan <- one
|
t.eventChan <- one
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if t.hasResultActions {
|
||||||
|
t.eventChan <- tui.Result.AsEvent()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
t.reqBox.Set(reqInfo, nil)
|
t.reqBox.Set(reqInfo, nil)
|
||||||
@@ -1251,6 +1312,9 @@ func (t *Terminal) resizeWindows(forcePreview bool) {
|
|||||||
width -= paddingInt[1] + paddingInt[3]
|
width -= paddingInt[1] + paddingInt[3]
|
||||||
height -= paddingInt[0] + paddingInt[2]
|
height -= paddingInt[0] + paddingInt[2]
|
||||||
|
|
||||||
|
t.areaLines = height
|
||||||
|
t.areaColumns = width
|
||||||
|
|
||||||
// Set up preview window
|
// Set up preview window
|
||||||
noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode)
|
noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode)
|
||||||
if forcePreview || t.needPreviewWindow() {
|
if forcePreview || t.needPreviewWindow() {
|
||||||
@@ -2335,6 +2399,12 @@ func parsePlaceholder(match string) (bool, string, placeholderFlags) {
|
|||||||
return true, match[1:], flags
|
return true, match[1:], flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(match, "{fzf:") {
|
||||||
|
// {fzf:*} are not determined by the current item
|
||||||
|
flags.forceUpdate = true
|
||||||
|
return false, match, flags
|
||||||
|
}
|
||||||
|
|
||||||
skipChars := 1
|
skipChars := 1
|
||||||
for _, char := range match[1:] {
|
for _, char := range match[1:] {
|
||||||
switch char {
|
switch char {
|
||||||
@@ -2351,7 +2421,7 @@ func parsePlaceholder(match string) (bool, string, placeholderFlags) {
|
|||||||
flags.file = true
|
flags.file = true
|
||||||
skipChars++
|
skipChars++
|
||||||
case 'q':
|
case 'q':
|
||||||
flags.query = true
|
flags.forceUpdate = true
|
||||||
// query flag is not skipped
|
// query flag is not skipped
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
@@ -2363,14 +2433,14 @@ func parsePlaceholder(match string) (bool, string, placeholderFlags) {
|
|||||||
return false, matchWithoutFlags, flags
|
return false, matchWithoutFlags, flags
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasPreviewFlags(template string) (slot bool, plus bool, query bool) {
|
func hasPreviewFlags(template string) (slot bool, plus bool, forceUpdate bool) {
|
||||||
for _, match := range placeholder.FindAllString(template, -1) {
|
for _, match := range placeholder.FindAllString(template, -1) {
|
||||||
_, _, flags := parsePlaceholder(match)
|
_, _, flags := parsePlaceholder(match)
|
||||||
if flags.plus {
|
if flags.plus {
|
||||||
plus = true
|
plus = true
|
||||||
}
|
}
|
||||||
if flags.query {
|
if flags.forceUpdate {
|
||||||
query = true
|
forceUpdate = true
|
||||||
}
|
}
|
||||||
slot = true
|
slot = true
|
||||||
}
|
}
|
||||||
@@ -2397,9 +2467,30 @@ func cleanTemporaryFiles() {
|
|||||||
activeTempFiles = []string{}
|
activeTempFiles = []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type replacePlaceholderParams struct {
|
||||||
|
template string
|
||||||
|
stripAnsi bool
|
||||||
|
delimiter Delimiter
|
||||||
|
printsep string
|
||||||
|
forcePlus bool
|
||||||
|
query string
|
||||||
|
allItems []*Item
|
||||||
|
lastAction actionType
|
||||||
|
prompt string
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Terminal) replacePlaceholder(template string, forcePlus bool, input string, list []*Item) string {
|
func (t *Terminal) replacePlaceholder(template string, forcePlus bool, input string, list []*Item) string {
|
||||||
return replacePlaceholder(
|
return replacePlaceholder(replacePlaceholderParams{
|
||||||
template, t.ansi, t.delimiter, t.printsep, forcePlus, input, list)
|
template: template,
|
||||||
|
stripAnsi: t.ansi,
|
||||||
|
delimiter: t.delimiter,
|
||||||
|
printsep: t.printsep,
|
||||||
|
forcePlus: forcePlus,
|
||||||
|
query: input,
|
||||||
|
allItems: list,
|
||||||
|
lastAction: t.lastAction,
|
||||||
|
prompt: t.promptString,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) evaluateScrollOffset() int {
|
func (t *Terminal) evaluateScrollOffset() int {
|
||||||
@@ -2437,9 +2528,9 @@ func (t *Terminal) evaluateScrollOffset() int {
|
|||||||
return util.Max(0, base)
|
return util.Max(0, base)
|
||||||
}
|
}
|
||||||
|
|
||||||
func replacePlaceholder(template string, stripAnsi bool, delimiter Delimiter, printsep string, forcePlus bool, query string, allItems []*Item) string {
|
func replacePlaceholder(params replacePlaceholderParams) string {
|
||||||
current := allItems[:1]
|
current := params.allItems[:1]
|
||||||
selected := allItems[1:]
|
selected := params.allItems[1:]
|
||||||
if current[0] == nil {
|
if current[0] == nil {
|
||||||
current = []*Item{}
|
current = []*Item{}
|
||||||
}
|
}
|
||||||
@@ -2448,7 +2539,7 @@ func replacePlaceholder(template string, stripAnsi bool, delimiter Delimiter, pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// replace placeholders one by one
|
// replace placeholders one by one
|
||||||
return placeholder.ReplaceAllStringFunc(template, func(match string) string {
|
return placeholder.ReplaceAllStringFunc(params.template, func(match string) string {
|
||||||
escaped, match, flags := parsePlaceholder(match)
|
escaped, match, flags := parsePlaceholder(match)
|
||||||
|
|
||||||
// this function implements the effects a placeholder has on items
|
// this function implements the effects a placeholder has on items
|
||||||
@@ -2458,8 +2549,8 @@ func replacePlaceholder(template string, stripAnsi bool, delimiter Delimiter, pr
|
|||||||
switch {
|
switch {
|
||||||
case escaped:
|
case escaped:
|
||||||
return match
|
return match
|
||||||
case match == "{q}":
|
case match == "{q}" || match == "{fzf:query}":
|
||||||
return quoteEntry(query)
|
return quoteEntry(params.query)
|
||||||
case match == "{}":
|
case match == "{}":
|
||||||
replace = func(item *Item) string {
|
replace = func(item *Item) string {
|
||||||
switch {
|
switch {
|
||||||
@@ -2470,11 +2561,15 @@ func replacePlaceholder(template string, stripAnsi bool, delimiter Delimiter, pr
|
|||||||
}
|
}
|
||||||
return strconv.Itoa(n)
|
return strconv.Itoa(n)
|
||||||
case flags.file:
|
case flags.file:
|
||||||
return item.AsString(stripAnsi)
|
return item.AsString(params.stripAnsi)
|
||||||
default:
|
default:
|
||||||
return quoteEntry(item.AsString(stripAnsi))
|
return quoteEntry(item.AsString(params.stripAnsi))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case match == "{fzf:action}":
|
||||||
|
return params.lastAction.Name()
|
||||||
|
case match == "{fzf:prompt}":
|
||||||
|
return quoteEntry(params.prompt)
|
||||||
default:
|
default:
|
||||||
// token type and also failover (below)
|
// token type and also failover (below)
|
||||||
rangeExpressions := strings.Split(match[1:len(match)-1], ",")
|
rangeExpressions := strings.Split(match[1:len(match)-1], ",")
|
||||||
@@ -2489,15 +2584,15 @@ func replacePlaceholder(template string, stripAnsi bool, delimiter Delimiter, pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
replace = func(item *Item) string {
|
replace = func(item *Item) string {
|
||||||
tokens := Tokenize(item.AsString(stripAnsi), delimiter)
|
tokens := Tokenize(item.AsString(params.stripAnsi), params.delimiter)
|
||||||
trans := Transform(tokens, ranges)
|
trans := Transform(tokens, ranges)
|
||||||
str := joinTokens(trans)
|
str := joinTokens(trans)
|
||||||
|
|
||||||
// trim the last delimiter
|
// trim the last delimiter
|
||||||
if delimiter.str != nil {
|
if params.delimiter.str != nil {
|
||||||
str = strings.TrimSuffix(str, *delimiter.str)
|
str = strings.TrimSuffix(str, *params.delimiter.str)
|
||||||
} else if delimiter.regex != nil {
|
} else if params.delimiter.regex != nil {
|
||||||
delims := delimiter.regex.FindAllStringIndex(str, -1)
|
delims := params.delimiter.regex.FindAllStringIndex(str, -1)
|
||||||
// make sure the delimiter is at the very end of the string
|
// make sure the delimiter is at the very end of the string
|
||||||
if len(delims) > 0 && delims[len(delims)-1][1] == len(str) {
|
if len(delims) > 0 && delims[len(delims)-1][1] == len(str) {
|
||||||
str = str[:delims[len(delims)-1][0]]
|
str = str[:delims[len(delims)-1][0]]
|
||||||
@@ -2517,7 +2612,7 @@ func replacePlaceholder(template string, stripAnsi bool, delimiter Delimiter, pr
|
|||||||
// apply 'replace' function over proper set of items and return result
|
// apply 'replace' function over proper set of items and return result
|
||||||
|
|
||||||
items := current
|
items := current
|
||||||
if flags.plus || forcePlus {
|
if flags.plus || params.forcePlus {
|
||||||
items = selected
|
items = selected
|
||||||
}
|
}
|
||||||
replacements := make([]string, len(items))
|
replacements := make([]string, len(items))
|
||||||
@@ -2527,7 +2622,7 @@ func replacePlaceholder(template string, stripAnsi bool, delimiter Delimiter, pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if flags.file {
|
if flags.file {
|
||||||
return writeTemporaryFile(replacements, printsep)
|
return writeTemporaryFile(replacements, params.printsep)
|
||||||
}
|
}
|
||||||
return strings.Join(replacements, " ")
|
return strings.Join(replacements, " ")
|
||||||
})
|
})
|
||||||
@@ -2609,8 +2704,8 @@ func (t *Terminal) currentItem() *Item {
|
|||||||
|
|
||||||
func (t *Terminal) buildPlusList(template string, forcePlus bool) (bool, []*Item) {
|
func (t *Terminal) buildPlusList(template string, forcePlus bool) (bool, []*Item) {
|
||||||
current := t.currentItem()
|
current := t.currentItem()
|
||||||
slot, plus, query := hasPreviewFlags(template)
|
slot, plus, forceUpdate := hasPreviewFlags(template)
|
||||||
if !(!slot || query || (forcePlus || plus) && len(t.selected) > 0) {
|
if !(!slot || forceUpdate || (forcePlus || plus) && len(t.selected) > 0) {
|
||||||
return current != nil, []*Item{current, current}
|
return current != nil, []*Item{current, current}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2704,6 +2799,13 @@ func (t *Terminal) pwindowSize() tui.TermSize {
|
|||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Terminal) currentIndex() int32 {
|
||||||
|
if currentItem := t.currentItem(); currentItem != nil {
|
||||||
|
return currentItem.Index()
|
||||||
|
}
|
||||||
|
return minItem.Index()
|
||||||
|
}
|
||||||
|
|
||||||
// Loop is called to start Terminal I/O
|
// Loop is called to start Terminal I/O
|
||||||
func (t *Terminal) Loop() {
|
func (t *Terminal) Loop() {
|
||||||
// prof := profile.Start(profile.ProfilePath("/tmp/"))
|
// prof := profile.Start(profile.ProfilePath("/tmp/"))
|
||||||
@@ -2794,6 +2896,7 @@ func (t *Terminal) Loop() {
|
|||||||
for {
|
for {
|
||||||
var items []*Item
|
var items []*Item
|
||||||
var commandTemplate string
|
var commandTemplate string
|
||||||
|
var pwindow tui.Window
|
||||||
var pwindowSize tui.TermSize
|
var pwindowSize tui.TermSize
|
||||||
initialOffset := 0
|
initialOffset := 0
|
||||||
t.previewBox.Wait(func(events *util.Events) {
|
t.previewBox.Wait(func(events *util.Events) {
|
||||||
@@ -2804,6 +2907,7 @@ func (t *Terminal) Loop() {
|
|||||||
commandTemplate = request.template
|
commandTemplate = request.template
|
||||||
initialOffset = request.scrollOffset
|
initialOffset = request.scrollOffset
|
||||||
items = request.list
|
items = request.list
|
||||||
|
pwindow = request.pwindow
|
||||||
pwindowSize = request.pwindowSize
|
pwindowSize = request.pwindowSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2823,8 +2927,8 @@ func (t *Terminal) Loop() {
|
|||||||
env = append(env, "FZF_PREVIEW_"+lines)
|
env = append(env, "FZF_PREVIEW_"+lines)
|
||||||
env = append(env, columns)
|
env = append(env, columns)
|
||||||
env = append(env, "FZF_PREVIEW_"+columns)
|
env = append(env, "FZF_PREVIEW_"+columns)
|
||||||
env = append(env, fmt.Sprintf("FZF_PREVIEW_TOP=%d", t.tui.Top()+t.pwindow.Top()))
|
env = append(env, fmt.Sprintf("FZF_PREVIEW_TOP=%d", t.tui.Top()+pwindow.Top()))
|
||||||
env = append(env, fmt.Sprintf("FZF_PREVIEW_LEFT=%d", t.pwindow.Left()))
|
env = append(env, fmt.Sprintf("FZF_PREVIEW_LEFT=%d", pwindow.Left()))
|
||||||
}
|
}
|
||||||
cmd.Env = env
|
cmd.Env = env
|
||||||
|
|
||||||
@@ -2952,7 +3056,7 @@ func (t *Terminal) Loop() {
|
|||||||
if len(command) > 0 && t.canPreview() {
|
if len(command) > 0 && t.canPreview() {
|
||||||
_, list := t.buildPlusList(command, false)
|
_, list := t.buildPlusList(command, false)
|
||||||
t.cancelPreview()
|
t.cancelPreview()
|
||||||
t.previewBox.Set(reqPreviewEnqueue, previewRequest{command, t.pwindowSize(), t.evaluateScrollOffset(), list})
|
t.previewBox.Set(reqPreviewEnqueue, previewRequest{command, t.pwindow, t.pwindowSize(), t.evaluateScrollOffset(), list})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2986,18 +3090,15 @@ func (t *Terminal) Loop() {
|
|||||||
t.printInfo()
|
t.printInfo()
|
||||||
case reqList:
|
case reqList:
|
||||||
t.printList()
|
t.printList()
|
||||||
var currentIndex int32 = minItem.Index()
|
currentIndex := t.currentIndex()
|
||||||
currentItem := t.currentItem()
|
|
||||||
if currentItem != nil {
|
|
||||||
currentIndex = currentItem.Index()
|
|
||||||
}
|
|
||||||
focusChanged := focusedIndex != currentIndex
|
focusChanged := focusedIndex != currentIndex
|
||||||
if focusChanged && t.track == trackCurrent {
|
if focusChanged && t.track == trackCurrent {
|
||||||
t.track = trackDisabled
|
t.track = trackDisabled
|
||||||
t.printInfo()
|
t.printInfo()
|
||||||
}
|
}
|
||||||
if onFocus, prs := t.keymap[tui.Focus.AsEvent()]; prs && focusChanged {
|
if t.hasFocusActions && focusChanged && currentIndex != t.lastFocus {
|
||||||
t.serverInputChan <- onFocus
|
t.lastFocus = currentIndex
|
||||||
|
t.eventChan <- tui.Focus.AsEvent()
|
||||||
}
|
}
|
||||||
if focusChanged || version != t.version {
|
if focusChanged || version != t.version {
|
||||||
version = t.version
|
version = t.version
|
||||||
@@ -3029,6 +3130,9 @@ func (t *Terminal) Loop() {
|
|||||||
if wasHidden && t.hasPreviewWindow() {
|
if wasHidden && t.hasPreviewWindow() {
|
||||||
refreshPreview(t.previewOpts.command)
|
refreshPreview(t.previewOpts.command)
|
||||||
}
|
}
|
||||||
|
if req == reqResize && t.hasResizeActions {
|
||||||
|
t.eventChan <- tui.Resize.AsEvent()
|
||||||
|
}
|
||||||
case reqClose:
|
case reqClose:
|
||||||
exit(func() int {
|
exit(func() int {
|
||||||
if t.output() {
|
if t.output() {
|
||||||
@@ -3111,7 +3215,7 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case event = <-t.eventChan:
|
case event = <-t.eventChan:
|
||||||
needBarrier = !event.Is(tui.Load, tui.One, tui.Zero)
|
needBarrier = !event.Is(tui.Load, tui.Result, tui.Focus, tui.One, tui.Zero, tui.Resize)
|
||||||
case serverActions := <-t.serverInputChan:
|
case serverActions := <-t.serverInputChan:
|
||||||
event = tui.Invalid.AsEvent()
|
event = tui.Invalid.AsEvent()
|
||||||
if t.listenAddr == nil || t.listenAddr.IsLocal() || t.listenUnsafe {
|
if t.listenAddr == nil || t.listenAddr.IsLocal() || t.listenUnsafe {
|
||||||
@@ -3186,17 +3290,26 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var doAction func(*action) bool
|
var doAction func(*action) bool
|
||||||
doActions := func(actions []*action) bool {
|
var doActions func(actions []*action) bool
|
||||||
|
doActions = func(actions []*action) bool {
|
||||||
|
currentIndex := t.currentIndex()
|
||||||
for _, action := range actions {
|
for _, action := range actions {
|
||||||
if !doAction(action) {
|
if !doAction(action) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if onFocus, prs := t.keymap[tui.Focus.AsEvent()]; prs {
|
||||||
|
if newIndex := t.currentIndex(); newIndex != currentIndex {
|
||||||
|
t.lastFocus = newIndex
|
||||||
|
return doActions(onFocus)
|
||||||
|
}
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
doAction = func(a *action) bool {
|
doAction = func(a *action) bool {
|
||||||
switch a.t {
|
switch a.t {
|
||||||
case actIgnore:
|
case actIgnore, actStart, actClick:
|
||||||
case actResponse:
|
case actResponse:
|
||||||
t.serverOutputChan <- t.dumpStatus(parseGetParams(a.a))
|
t.serverOutputChan <- t.dumpStatus(parseGetParams(a.a))
|
||||||
case actBecome:
|
case actBecome:
|
||||||
@@ -3250,7 +3363,7 @@ func (t *Terminal) Loop() {
|
|||||||
if valid {
|
if valid {
|
||||||
t.cancelPreview()
|
t.cancelPreview()
|
||||||
t.previewBox.Set(reqPreviewEnqueue,
|
t.previewBox.Set(reqPreviewEnqueue,
|
||||||
previewRequest{t.previewOpts.command, t.pwindowSize(), t.evaluateScrollOffset(), list})
|
previewRequest{t.previewOpts.command, t.pwindow, t.pwindowSize(), t.evaluateScrollOffset(), list})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Discard the preview content so that it won't accidentally appear
|
// Discard the preview content so that it won't accidentally appear
|
||||||
@@ -3267,6 +3380,7 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
case actTransformPrompt:
|
case actTransformPrompt:
|
||||||
prompt := t.executeCommand(a.a, false, true, true, true)
|
prompt := t.executeCommand(a.a, false, true, true, true)
|
||||||
|
t.promptString = prompt
|
||||||
t.prompt, t.promptLen = t.parsePrompt(prompt)
|
t.prompt, t.promptLen = t.parsePrompt(prompt)
|
||||||
req(reqPrompt)
|
req(reqPrompt)
|
||||||
case actTransformQuery:
|
case actTransformQuery:
|
||||||
@@ -3343,6 +3457,10 @@ func (t *Terminal) Loop() {
|
|||||||
t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(a.a, &tui.ColPreviewLabel, false)
|
t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(a.a, &tui.ColPreviewLabel, false)
|
||||||
req(reqRedrawPreviewLabel)
|
req(reqRedrawPreviewLabel)
|
||||||
}
|
}
|
||||||
|
case actTransform:
|
||||||
|
body := t.executeCommand(a.a, false, true, true, false)
|
||||||
|
actions := parseSingleActionList(strings.Trim(body, "\r\n"), func(message string) {})
|
||||||
|
return doActions(actions)
|
||||||
case actTransformBorderLabel:
|
case actTransformBorderLabel:
|
||||||
if t.border != nil {
|
if t.border != nil {
|
||||||
label := t.executeCommand(a.a, false, true, true, true)
|
label := t.executeCommand(a.a, false, true, true, true)
|
||||||
@@ -3356,6 +3474,7 @@ func (t *Terminal) Loop() {
|
|||||||
req(reqRedrawPreviewLabel)
|
req(reqRedrawPreviewLabel)
|
||||||
}
|
}
|
||||||
case actChangePrompt:
|
case actChangePrompt:
|
||||||
|
t.promptString = a.a
|
||||||
t.prompt, t.promptLen = t.parsePrompt(a.a)
|
t.prompt, t.promptLen = t.parsePrompt(a.a)
|
||||||
req(reqPrompt)
|
req(reqPrompt)
|
||||||
case actPreview:
|
case actPreview:
|
||||||
@@ -3373,7 +3492,7 @@ func (t *Terminal) Loop() {
|
|||||||
req(reqQuit)
|
req(reqQuit)
|
||||||
case actDeleteChar:
|
case actDeleteChar:
|
||||||
t.delChar()
|
t.delChar()
|
||||||
case actDeleteCharEOF:
|
case actDeleteCharEof:
|
||||||
if !t.delChar() && t.cx == 0 {
|
if !t.delChar() && t.cx == 0 {
|
||||||
req(reqQuit)
|
req(reqQuit)
|
||||||
}
|
}
|
||||||
@@ -3387,7 +3506,7 @@ func (t *Terminal) Loop() {
|
|||||||
t.input = []rune{}
|
t.input = []rune{}
|
||||||
t.cx = 0
|
t.cx = 0
|
||||||
}
|
}
|
||||||
case actBackwardDeleteCharEOF:
|
case actBackwardDeleteCharEof:
|
||||||
if len(t.input) == 0 {
|
if len(t.input) == 0 {
|
||||||
req(reqQuit)
|
req(reqQuit)
|
||||||
} else if t.cx > 0 {
|
} else if t.cx > 0 {
|
||||||
@@ -3494,6 +3613,12 @@ func (t *Terminal) Loop() {
|
|||||||
if len(t.selected) > 0 || t.merger.Length() > 0 || !t.reading && t.count == 0 {
|
if len(t.selected) > 0 || t.merger.Length() > 0 || !t.reading && t.count == 0 {
|
||||||
req(reqClose)
|
req(reqClose)
|
||||||
}
|
}
|
||||||
|
case actAcceptOrPrintQuery:
|
||||||
|
if len(t.selected) > 0 || t.merger.Length() > 0 {
|
||||||
|
req(reqClose)
|
||||||
|
} else {
|
||||||
|
req(reqPrintQuery)
|
||||||
|
}
|
||||||
case actClearScreen:
|
case actClearScreen:
|
||||||
req(reqFullRedraw)
|
req(reqFullRedraw)
|
||||||
case actClearQuery:
|
case actClearQuery:
|
||||||
@@ -3600,7 +3725,7 @@ func (t *Terminal) Loop() {
|
|||||||
t.yanked = copySlice(t.input[t.cx:])
|
t.yanked = copySlice(t.input[t.cx:])
|
||||||
t.input = t.input[:t.cx]
|
t.input = t.input[:t.cx]
|
||||||
}
|
}
|
||||||
case actRune:
|
case actChar:
|
||||||
prefix := copySlice(t.input[:t.cx])
|
prefix := copySlice(t.input[:t.cx])
|
||||||
t.input = append(append(prefix, event.Char), t.input[t.cx:]...)
|
t.input = append(append(prefix, event.Char), t.input[t.cx:]...)
|
||||||
t.cx++
|
t.cx++
|
||||||
@@ -3628,6 +3753,12 @@ func (t *Terminal) Loop() {
|
|||||||
t.track = trackEnabled
|
t.track = trackEnabled
|
||||||
}
|
}
|
||||||
req(reqInfo)
|
req(reqInfo)
|
||||||
|
case actShowHeader:
|
||||||
|
t.headerVisible = true
|
||||||
|
req(reqList, reqInfo, reqPrompt, reqHeader)
|
||||||
|
case actHideHeader:
|
||||||
|
t.headerVisible = false
|
||||||
|
req(reqList, reqInfo, reqPrompt, reqHeader)
|
||||||
case actToggleHeader:
|
case actToggleHeader:
|
||||||
t.headerVisible = !t.headerVisible
|
t.headerVisible = !t.headerVisible
|
||||||
req(reqList, reqInfo, reqPrompt, reqHeader)
|
req(reqList, reqInfo, reqPrompt, reqHeader)
|
||||||
@@ -3797,8 +3928,8 @@ func (t *Terminal) Loop() {
|
|||||||
// We run the command even when there's no match
|
// We run the command even when there's no match
|
||||||
// 1. If the template doesn't have any slots
|
// 1. If the template doesn't have any slots
|
||||||
// 2. If the template has {q}
|
// 2. If the template has {q}
|
||||||
slot, _, query := hasPreviewFlags(a.a)
|
slot, _, forceUpdate := hasPreviewFlags(a.a)
|
||||||
valid = !slot || query
|
valid = !slot || forceUpdate
|
||||||
}
|
}
|
||||||
if valid {
|
if valid {
|
||||||
command := t.replacePlaceholder(a.a, false, string(t.input), list)
|
command := t.replacePlaceholder(a.a, false, string(t.input), list)
|
||||||
@@ -3878,6 +4009,10 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !processExecution(a.t) {
|
||||||
|
t.lastAction = a.t
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3891,7 +4026,7 @@ func (t *Terminal) Loop() {
|
|||||||
actions = t.keymap[event.Comparable()]
|
actions = t.keymap[event.Comparable()]
|
||||||
}
|
}
|
||||||
if len(actions) == 0 && event.Type == tui.Rune {
|
if len(actions) == 0 && event.Type == tui.Rune {
|
||||||
doAction(&action{t: actRune})
|
doAction(&action{t: actChar})
|
||||||
} else if !doActions(actions) {
|
} else if !doActions(actions) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -3922,8 +4057,8 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if queryChanged && t.canPreview() && len(t.previewOpts.command) > 0 {
|
if queryChanged && t.canPreview() && len(t.previewOpts.command) > 0 {
|
||||||
_, _, q := hasPreviewFlags(t.previewOpts.command)
|
_, _, forceUpdate := hasPreviewFlags(t.previewOpts.command)
|
||||||
if q {
|
if forceUpdate {
|
||||||
t.version++
|
t.version++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,20 @@ import (
|
|||||||
"github.com/junegunn/fzf/src/util"
|
"github.com/junegunn/fzf/src/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func replacePlaceholderTest(template string, stripAnsi bool, delimiter Delimiter, printsep string, forcePlus bool, query string, allItems []*Item) string {
|
||||||
|
return replacePlaceholder(replacePlaceholderParams{
|
||||||
|
template: template,
|
||||||
|
stripAnsi: stripAnsi,
|
||||||
|
delimiter: delimiter,
|
||||||
|
printsep: printsep,
|
||||||
|
forcePlus: forcePlus,
|
||||||
|
query: query,
|
||||||
|
allItems: allItems,
|
||||||
|
lastAction: actBackwardDeleteCharEof,
|
||||||
|
prompt: "prompt",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestReplacePlaceholder(t *testing.T) {
|
func TestReplacePlaceholder(t *testing.T) {
|
||||||
item1 := newItem(" foo'bar \x1b[31mbaz\x1b[m")
|
item1 := newItem(" foo'bar \x1b[31mbaz\x1b[m")
|
||||||
items1 := []*Item{item1, item1}
|
items1 := []*Item{item1, item1}
|
||||||
@@ -52,90 +66,90 @@ func TestReplacePlaceholder(t *testing.T) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// {}, preserve ansi
|
// {}, preserve ansi
|
||||||
result = replacePlaceholder("echo {}", false, Delimiter{}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {}", false, Delimiter{}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}} foo{{.I}}bar \x1b[31mbaz\x1b[m{{.O}}")
|
checkFormat("echo {{.O}} foo{{.I}}bar \x1b[31mbaz\x1b[m{{.O}}")
|
||||||
|
|
||||||
// {}, strip ansi
|
// {}, strip ansi
|
||||||
result = replacePlaceholder("echo {}", true, Delimiter{}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {}", true, Delimiter{}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}")
|
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}")
|
||||||
|
|
||||||
// {}, with multiple items
|
// {}, with multiple items
|
||||||
result = replacePlaceholder("echo {}", true, Delimiter{}, printsep, false, "query", items2)
|
result = replacePlaceholderTest("echo {}", true, Delimiter{}, printsep, false, "query", items2)
|
||||||
checkFormat("echo {{.O}}foo{{.I}}bar baz{{.O}}")
|
checkFormat("echo {{.O}}foo{{.I}}bar baz{{.O}}")
|
||||||
|
|
||||||
// {..}, strip leading whitespaces, preserve ansi
|
// {..}, strip leading whitespaces, preserve ansi
|
||||||
result = replacePlaceholder("echo {..}", false, Delimiter{}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {..}", false, Delimiter{}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}}foo{{.I}}bar \x1b[31mbaz\x1b[m{{.O}}")
|
checkFormat("echo {{.O}}foo{{.I}}bar \x1b[31mbaz\x1b[m{{.O}}")
|
||||||
|
|
||||||
// {..}, strip leading whitespaces, strip ansi
|
// {..}, strip leading whitespaces, strip ansi
|
||||||
result = replacePlaceholder("echo {..}", true, Delimiter{}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {..}", true, Delimiter{}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}}foo{{.I}}bar baz{{.O}}")
|
checkFormat("echo {{.O}}foo{{.I}}bar baz{{.O}}")
|
||||||
|
|
||||||
// {q}
|
// {q}
|
||||||
result = replacePlaceholder("echo {} {q}", true, Delimiter{}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {} {q}", true, Delimiter{}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}} {{.O}}query{{.O}}")
|
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}} {{.O}}query{{.O}}")
|
||||||
|
|
||||||
// {q}, multiple items
|
// {q}, multiple items
|
||||||
result = replacePlaceholder("echo {+}{q}{+}", true, Delimiter{}, printsep, false, "query 'string'", items2)
|
result = replacePlaceholderTest("echo {+}{q}{+}", true, Delimiter{}, printsep, false, "query 'string'", items2)
|
||||||
checkFormat("echo {{.O}}foo{{.I}}bar baz{{.O}} {{.O}}FOO{{.I}}BAR BAZ{{.O}}{{.O}}query {{.I}}string{{.I}}{{.O}}{{.O}}foo{{.I}}bar baz{{.O}} {{.O}}FOO{{.I}}BAR BAZ{{.O}}")
|
checkFormat("echo {{.O}}foo{{.I}}bar baz{{.O}} {{.O}}FOO{{.I}}BAR BAZ{{.O}}{{.O}}query {{.I}}string{{.I}}{{.O}}{{.O}}foo{{.I}}bar baz{{.O}} {{.O}}FOO{{.I}}BAR BAZ{{.O}}")
|
||||||
|
|
||||||
result = replacePlaceholder("echo {}{q}{}", true, Delimiter{}, printsep, false, "query 'string'", items2)
|
result = replacePlaceholderTest("echo {}{q}{}", true, Delimiter{}, printsep, false, "query 'string'", items2)
|
||||||
checkFormat("echo {{.O}}foo{{.I}}bar baz{{.O}}{{.O}}query {{.I}}string{{.I}}{{.O}}{{.O}}foo{{.I}}bar baz{{.O}}")
|
checkFormat("echo {{.O}}foo{{.I}}bar baz{{.O}}{{.O}}query {{.I}}string{{.I}}{{.O}}{{.O}}foo{{.I}}bar baz{{.O}}")
|
||||||
|
|
||||||
result = replacePlaceholder("echo {1}/{2}/{2,1}/{-1}/{-2}/{}/{..}/{n.t}/\\{}/\\{1}/\\{q}/{3}", true, Delimiter{}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {1}/{2}/{2,1}/{-1}/{-2}/{}/{..}/{n.t}/\\{}/\\{1}/\\{q}/{3}", true, Delimiter{}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}}foo{{.I}}bar{{.O}}/{{.O}}baz{{.O}}/{{.O}}bazfoo{{.I}}bar{{.O}}/{{.O}}baz{{.O}}/{{.O}}foo{{.I}}bar{{.O}}/{{.O}} foo{{.I}}bar baz{{.O}}/{{.O}}foo{{.I}}bar baz{{.O}}/{n.t}/{}/{1}/{q}/{{.O}}{{.O}}")
|
checkFormat("echo {{.O}}foo{{.I}}bar{{.O}}/{{.O}}baz{{.O}}/{{.O}}bazfoo{{.I}}bar{{.O}}/{{.O}}baz{{.O}}/{{.O}}foo{{.I}}bar{{.O}}/{{.O}} foo{{.I}}bar baz{{.O}}/{{.O}}foo{{.I}}bar baz{{.O}}/{n.t}/{}/{1}/{q}/{{.O}}{{.O}}")
|
||||||
|
|
||||||
result = replacePlaceholder("echo {1}/{2}/{-1}/{-2}/{..}/{n.t}/\\{}/\\{1}/\\{q}/{3}", true, Delimiter{}, printsep, false, "query", items2)
|
result = replacePlaceholderTest("echo {1}/{2}/{-1}/{-2}/{..}/{n.t}/\\{}/\\{1}/\\{q}/{3}", true, Delimiter{}, printsep, false, "query", items2)
|
||||||
checkFormat("echo {{.O}}foo{{.I}}bar{{.O}}/{{.O}}baz{{.O}}/{{.O}}baz{{.O}}/{{.O}}foo{{.I}}bar{{.O}}/{{.O}}foo{{.I}}bar baz{{.O}}/{n.t}/{}/{1}/{q}/{{.O}}{{.O}}")
|
checkFormat("echo {{.O}}foo{{.I}}bar{{.O}}/{{.O}}baz{{.O}}/{{.O}}baz{{.O}}/{{.O}}foo{{.I}}bar{{.O}}/{{.O}}foo{{.I}}bar baz{{.O}}/{n.t}/{}/{1}/{q}/{{.O}}{{.O}}")
|
||||||
|
|
||||||
result = replacePlaceholder("echo {+1}/{+2}/{+-1}/{+-2}/{+..}/{n.t}/\\{}/\\{1}/\\{q}/{+3}", true, Delimiter{}, printsep, false, "query", items2)
|
result = replacePlaceholderTest("echo {+1}/{+2}/{+-1}/{+-2}/{+..}/{n.t}/\\{}/\\{1}/\\{q}/{+3}", true, Delimiter{}, printsep, false, "query", items2)
|
||||||
checkFormat("echo {{.O}}foo{{.I}}bar{{.O}} {{.O}}FOO{{.I}}BAR{{.O}}/{{.O}}baz{{.O}} {{.O}}BAZ{{.O}}/{{.O}}baz{{.O}} {{.O}}BAZ{{.O}}/{{.O}}foo{{.I}}bar{{.O}} {{.O}}FOO{{.I}}BAR{{.O}}/{{.O}}foo{{.I}}bar baz{{.O}} {{.O}}FOO{{.I}}BAR BAZ{{.O}}/{n.t}/{}/{1}/{q}/{{.O}}{{.O}} {{.O}}{{.O}}")
|
checkFormat("echo {{.O}}foo{{.I}}bar{{.O}} {{.O}}FOO{{.I}}BAR{{.O}}/{{.O}}baz{{.O}} {{.O}}BAZ{{.O}}/{{.O}}baz{{.O}} {{.O}}BAZ{{.O}}/{{.O}}foo{{.I}}bar{{.O}} {{.O}}FOO{{.I}}BAR{{.O}}/{{.O}}foo{{.I}}bar baz{{.O}} {{.O}}FOO{{.I}}BAR BAZ{{.O}}/{n.t}/{}/{1}/{q}/{{.O}}{{.O}} {{.O}}{{.O}}")
|
||||||
|
|
||||||
// forcePlus
|
// forcePlus
|
||||||
result = replacePlaceholder("echo {1}/{2}/{-1}/{-2}/{..}/{n.t}/\\{}/\\{1}/\\{q}/{3}", true, Delimiter{}, printsep, true, "query", items2)
|
result = replacePlaceholderTest("echo {1}/{2}/{-1}/{-2}/{..}/{n.t}/\\{}/\\{1}/\\{q}/{3}", true, Delimiter{}, printsep, true, "query", items2)
|
||||||
checkFormat("echo {{.O}}foo{{.I}}bar{{.O}} {{.O}}FOO{{.I}}BAR{{.O}}/{{.O}}baz{{.O}} {{.O}}BAZ{{.O}}/{{.O}}baz{{.O}} {{.O}}BAZ{{.O}}/{{.O}}foo{{.I}}bar{{.O}} {{.O}}FOO{{.I}}BAR{{.O}}/{{.O}}foo{{.I}}bar baz{{.O}} {{.O}}FOO{{.I}}BAR BAZ{{.O}}/{n.t}/{}/{1}/{q}/{{.O}}{{.O}} {{.O}}{{.O}}")
|
checkFormat("echo {{.O}}foo{{.I}}bar{{.O}} {{.O}}FOO{{.I}}BAR{{.O}}/{{.O}}baz{{.O}} {{.O}}BAZ{{.O}}/{{.O}}baz{{.O}} {{.O}}BAZ{{.O}}/{{.O}}foo{{.I}}bar{{.O}} {{.O}}FOO{{.I}}BAR{{.O}}/{{.O}}foo{{.I}}bar baz{{.O}} {{.O}}FOO{{.I}}BAR BAZ{{.O}}/{n.t}/{}/{1}/{q}/{{.O}}{{.O}} {{.O}}{{.O}}")
|
||||||
|
|
||||||
// Whitespace preserving flag with "'" delimiter
|
// Whitespace preserving flag with "'" delimiter
|
||||||
result = replacePlaceholder("echo {s1}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {s1}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}} foo{{.O}}")
|
checkFormat("echo {{.O}} foo{{.O}}")
|
||||||
|
|
||||||
result = replacePlaceholder("echo {s2}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {s2}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}}bar baz{{.O}}")
|
checkFormat("echo {{.O}}bar baz{{.O}}")
|
||||||
|
|
||||||
result = replacePlaceholder("echo {s}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {s}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}")
|
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}")
|
||||||
|
|
||||||
result = replacePlaceholder("echo {s..}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {s..}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}")
|
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}")
|
||||||
|
|
||||||
// Whitespace preserving flag with regex delimiter
|
// Whitespace preserving flag with regex delimiter
|
||||||
regex = regexp.MustCompile(`\w+`)
|
regex = regexp.MustCompile(`\w+`)
|
||||||
|
|
||||||
result = replacePlaceholder("echo {s1}", true, Delimiter{regex: regex}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {s1}", true, Delimiter{regex: regex}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}} {{.O}}")
|
checkFormat("echo {{.O}} {{.O}}")
|
||||||
|
|
||||||
result = replacePlaceholder("echo {s2}", true, Delimiter{regex: regex}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {s2}", true, Delimiter{regex: regex}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}}{{.I}}{{.O}}")
|
checkFormat("echo {{.O}}{{.I}}{{.O}}")
|
||||||
|
|
||||||
result = replacePlaceholder("echo {s3}", true, Delimiter{regex: regex}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {s3}", true, Delimiter{regex: regex}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}} {{.O}}")
|
checkFormat("echo {{.O}} {{.O}}")
|
||||||
|
|
||||||
// No match
|
// No match
|
||||||
result = replacePlaceholder("echo {}/{+}", true, Delimiter{}, printsep, false, "query", []*Item{nil, nil})
|
result = replacePlaceholderTest("echo {}/{+}", true, Delimiter{}, printsep, false, "query", []*Item{nil, nil})
|
||||||
check("echo /")
|
check("echo /")
|
||||||
|
|
||||||
// No match, but with selections
|
// No match, but with selections
|
||||||
result = replacePlaceholder("echo {}/{+}", true, Delimiter{}, printsep, false, "query", []*Item{nil, item1})
|
result = replacePlaceholderTest("echo {}/{+}", true, Delimiter{}, printsep, false, "query", []*Item{nil, item1})
|
||||||
checkFormat("echo /{{.O}} foo{{.I}}bar baz{{.O}}")
|
checkFormat("echo /{{.O}} foo{{.I}}bar baz{{.O}}")
|
||||||
|
|
||||||
// String delimiter
|
// String delimiter
|
||||||
result = replacePlaceholder("echo {}/{1}/{2}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {}/{1}/{2}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}/{{.O}}foo{{.O}}/{{.O}}bar baz{{.O}}")
|
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}/{{.O}}foo{{.O}}/{{.O}}bar baz{{.O}}")
|
||||||
|
|
||||||
// Regex delimiter
|
// Regex delimiter
|
||||||
regex = regexp.MustCompile("[oa]+")
|
regex = regexp.MustCompile("[oa]+")
|
||||||
// foo'bar baz
|
// foo'bar baz
|
||||||
result = replacePlaceholder("echo {}/{1}/{3}/{2..3}", true, Delimiter{regex: regex}, printsep, false, "query", items1)
|
result = replacePlaceholderTest("echo {}/{1}/{3}/{2..3}", true, Delimiter{regex: regex}, printsep, false, "query", items1)
|
||||||
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}/{{.O}}f{{.O}}/{{.O}}r b{{.O}}/{{.O}}{{.I}}bar b{{.O}}")
|
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}/{{.O}}f{{.O}}/{{.O}}r b{{.O}}/{{.O}}{{.I}}bar b{{.O}}")
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -155,7 +169,6 @@ func TestReplacePlaceholder(t *testing.T) {
|
|||||||
newItem("7a 7b 7c 7d 7e 7f"),
|
newItem("7a 7b 7c 7d 7e 7f"),
|
||||||
}
|
}
|
||||||
stripAnsi := false
|
stripAnsi := false
|
||||||
printsep = "\n"
|
|
||||||
forcePlus := false
|
forcePlus := false
|
||||||
query := "sample query"
|
query := "sample query"
|
||||||
|
|
||||||
@@ -198,18 +211,23 @@ func TestReplacePlaceholder(t *testing.T) {
|
|||||||
// query flag is not removed after parsing, so it gets doubled
|
// query flag is not removed after parsing, so it gets doubled
|
||||||
// while the double q is invalid, it is useful here for testing purposes
|
// while the double q is invalid, it is useful here for testing purposes
|
||||||
templateToOutput[`{q}`] = "{{.O}}" + query + "{{.O}}"
|
templateToOutput[`{q}`] = "{{.O}}" + query + "{{.O}}"
|
||||||
|
templateToOutput[`{fzf:query}`] = "{{.O}}" + query + "{{.O}}"
|
||||||
|
templateToOutput[`{fzf:action} {fzf:prompt}`] = "backward-delete-char-eof 'prompt'"
|
||||||
|
|
||||||
// IV. escaping placeholder
|
// IV. escaping placeholder
|
||||||
templateToOutput[`\{}`] = `{}`
|
templateToOutput[`\{}`] = `{}`
|
||||||
|
templateToOutput[`\{q}`] = `{q}`
|
||||||
|
templateToOutput[`\{fzf:query}`] = `{fzf:query}`
|
||||||
|
templateToOutput[`\{fzf:action}`] = `{fzf:action}`
|
||||||
templateToOutput[`\{++}`] = `{++}`
|
templateToOutput[`\{++}`] = `{++}`
|
||||||
templateToOutput[`{++}`] = templateToOutput[`{+}`]
|
templateToOutput[`{++}`] = templateToOutput[`{+}`]
|
||||||
|
|
||||||
for giveTemplate, wantOutput := range templateToOutput {
|
for giveTemplate, wantOutput := range templateToOutput {
|
||||||
result = replacePlaceholder(giveTemplate, stripAnsi, Delimiter{}, printsep, forcePlus, query, items3)
|
result = replacePlaceholderTest(giveTemplate, stripAnsi, Delimiter{}, printsep, forcePlus, query, items3)
|
||||||
checkFormat(wantOutput)
|
checkFormat(wantOutput)
|
||||||
}
|
}
|
||||||
for giveTemplate, wantOutput := range templateToFile {
|
for giveTemplate, wantOutput := range templateToFile {
|
||||||
path := replacePlaceholder(giveTemplate, stripAnsi, Delimiter{}, printsep, forcePlus, query, items3)
|
path := replacePlaceholderTest(giveTemplate, stripAnsi, Delimiter{}, printsep, forcePlus, query, items3)
|
||||||
|
|
||||||
data, err := readFile(path)
|
data, err := readFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -563,7 +581,7 @@ func testCommands(t *testing.T, tests []testCase) {
|
|||||||
|
|
||||||
// evaluate the test cases
|
// evaluate the test cases
|
||||||
for idx, test := range tests {
|
for idx, test := range tests {
|
||||||
gotOutput := replacePlaceholder(
|
gotOutput := replacePlaceholderTest(
|
||||||
test.give.template, stripAnsi, delimiter, printsep, forcePlus,
|
test.give.template, stripAnsi, delimiter, printsep, forcePlus,
|
||||||
test.give.query,
|
test.give.query,
|
||||||
test.give.allItems)
|
test.give.allItems)
|
||||||
@@ -605,7 +623,7 @@ func (flags placeholderFlags) encodePlaceholder() string {
|
|||||||
if flags.file {
|
if flags.file {
|
||||||
encoded += "f"
|
encoded += "f"
|
||||||
}
|
}
|
||||||
if flags.query {
|
if flags.forceUpdate { // FIXME
|
||||||
encoded += "q"
|
encoded += "q"
|
||||||
}
|
}
|
||||||
return encoded
|
return encoded
|
||||||
|
|||||||
@@ -11,6 +11,20 @@ import (
|
|||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var escaper *strings.Replacer
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
tokens := strings.Split(os.Getenv("SHELL"), "/")
|
||||||
|
if tokens[len(tokens)-1] == "fish" {
|
||||||
|
// https://fishshell.com/docs/current/language.html#quotes
|
||||||
|
// > The only meaningful escape sequences in single quotes are \', which
|
||||||
|
// > escapes a single quote and \\, which escapes the backslash symbol.
|
||||||
|
escaper = strings.NewReplacer("\\", "\\\\", "'", "\\'")
|
||||||
|
} else {
|
||||||
|
escaper = strings.NewReplacer("'", "'\\''")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func notifyOnResize(resizeChan chan<- os.Signal) {
|
func notifyOnResize(resizeChan chan<- os.Signal) {
|
||||||
signal.Notify(resizeChan, syscall.SIGWINCH)
|
signal.Notify(resizeChan, syscall.SIGWINCH)
|
||||||
}
|
}
|
||||||
@@ -29,5 +43,5 @@ func notifyOnCont(resizeChan chan<- os.Signal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func quoteEntry(entry string) string {
|
func quoteEntry(entry string) string {
|
||||||
return "'" + strings.Replace(entry, "'", "'\\''", -1) + "'"
|
return "'" + escaper.Replace(entry) + "'"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/mattn/go-runewidth"
|
"github.com/junegunn/uniseg"
|
||||||
"github.com/rivo/uniseg"
|
|
||||||
|
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
@@ -804,7 +803,7 @@ func (w *LightWindow) drawBorderHorizontal(top, bottom bool) {
|
|||||||
if w.preview {
|
if w.preview {
|
||||||
color = ColPreviewBorder
|
color = ColPreviewBorder
|
||||||
}
|
}
|
||||||
hw := runewidth.RuneWidth(w.border.top)
|
hw := runeWidth(w.border.top)
|
||||||
if top {
|
if top {
|
||||||
w.Move(0, 0)
|
w.Move(0, 0)
|
||||||
w.CPrint(color, repeat(w.border.top, w.width/hw))
|
w.CPrint(color, repeat(w.border.top, w.width/hw))
|
||||||
@@ -842,13 +841,13 @@ func (w *LightWindow) drawBorderAround(onlyHorizontal bool) {
|
|||||||
if w.preview {
|
if w.preview {
|
||||||
color = ColPreviewBorder
|
color = ColPreviewBorder
|
||||||
}
|
}
|
||||||
hw := runewidth.RuneWidth(w.border.top)
|
hw := runeWidth(w.border.top)
|
||||||
tcw := runewidth.RuneWidth(w.border.topLeft) + runewidth.RuneWidth(w.border.topRight)
|
tcw := runeWidth(w.border.topLeft) + runeWidth(w.border.topRight)
|
||||||
bcw := runewidth.RuneWidth(w.border.bottomLeft) + runewidth.RuneWidth(w.border.bottomRight)
|
bcw := runeWidth(w.border.bottomLeft) + runeWidth(w.border.bottomRight)
|
||||||
rem := (w.width - tcw) % hw
|
rem := (w.width - tcw) % hw
|
||||||
w.CPrint(color, string(w.border.topLeft)+repeat(w.border.top, (w.width-tcw)/hw)+repeat(' ', rem)+string(w.border.topRight))
|
w.CPrint(color, string(w.border.topLeft)+repeat(w.border.top, (w.width-tcw)/hw)+repeat(' ', rem)+string(w.border.topRight))
|
||||||
if !onlyHorizontal {
|
if !onlyHorizontal {
|
||||||
vw := runewidth.RuneWidth(w.border.left)
|
vw := runeWidth(w.border.left)
|
||||||
for y := 1; y < w.height-1; y++ {
|
for y := 1; y < w.height-1; y++ {
|
||||||
w.Move(y, 0)
|
w.Move(y, 0)
|
||||||
w.CPrint(color, string(w.border.left))
|
w.CPrint(color, string(w.border.left))
|
||||||
@@ -1020,7 +1019,7 @@ func wrapLine(input string, prefixLength int, max int, tabstop int) []wrappedLin
|
|||||||
} else if rs[0] == '\r' {
|
} else if rs[0] == '\r' {
|
||||||
w++
|
w++
|
||||||
} else {
|
} else {
|
||||||
w = runewidth.StringWidth(str)
|
w = uniseg.StringWidth(str)
|
||||||
}
|
}
|
||||||
width += w
|
width += w
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ import (
|
|||||||
"github.com/gdamore/tcell/v2/encoding"
|
"github.com/gdamore/tcell/v2/encoding"
|
||||||
"github.com/junegunn/fzf/src/util"
|
"github.com/junegunn/fzf/src/util"
|
||||||
|
|
||||||
"github.com/mattn/go-runewidth"
|
"github.com/junegunn/uniseg"
|
||||||
"github.com/rivo/uniseg"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func HasFullscreenRenderer() bool {
|
func HasFullscreenRenderer() bool {
|
||||||
@@ -738,7 +737,7 @@ func (w *TcellWindow) drawBorder(onlyHorizontal bool) {
|
|||||||
style = w.normal.style()
|
style = w.normal.style()
|
||||||
}
|
}
|
||||||
|
|
||||||
hw := runewidth.RuneWidth(w.borderStyle.top)
|
hw := runeWidth(w.borderStyle.top)
|
||||||
switch shape {
|
switch shape {
|
||||||
case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble, BorderHorizontal, BorderTop:
|
case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble, BorderHorizontal, BorderTop:
|
||||||
max := right - 2*hw
|
max := right - 2*hw
|
||||||
@@ -773,7 +772,7 @@ func (w *TcellWindow) drawBorder(onlyHorizontal bool) {
|
|||||||
}
|
}
|
||||||
switch shape {
|
switch shape {
|
||||||
case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble, BorderVertical, BorderRight:
|
case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble, BorderVertical, BorderRight:
|
||||||
vw := runewidth.RuneWidth(w.borderStyle.right)
|
vw := runeWidth(w.borderStyle.right)
|
||||||
for y := top; y < bot; y++ {
|
for y := top; y < bot; y++ {
|
||||||
_screen.SetContent(right-vw, y, w.borderStyle.right, nil, style)
|
_screen.SetContent(right-vw, y, w.borderStyle.right, nil, style)
|
||||||
}
|
}
|
||||||
@@ -782,8 +781,8 @@ func (w *TcellWindow) drawBorder(onlyHorizontal bool) {
|
|||||||
switch shape {
|
switch shape {
|
||||||
case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble:
|
case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble:
|
||||||
_screen.SetContent(left, top, w.borderStyle.topLeft, nil, style)
|
_screen.SetContent(left, top, w.borderStyle.topLeft, nil, style)
|
||||||
_screen.SetContent(right-runewidth.RuneWidth(w.borderStyle.topRight), top, w.borderStyle.topRight, nil, style)
|
_screen.SetContent(right-runeWidth(w.borderStyle.topRight), top, w.borderStyle.topRight, nil, style)
|
||||||
_screen.SetContent(left, bot-1, w.borderStyle.bottomLeft, nil, style)
|
_screen.SetContent(left, bot-1, w.borderStyle.bottomLeft, nil, style)
|
||||||
_screen.SetContent(right-runewidth.RuneWidth(w.borderStyle.bottomRight), bot-1, w.borderStyle.bottomRight, nil, style)
|
_screen.SetContent(right-runeWidth(w.borderStyle.bottomRight), bot-1, w.borderStyle.bottomRight, nil, style)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/junegunn/uniseg"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Types of user action
|
// Types of user action
|
||||||
@@ -105,6 +107,7 @@ const (
|
|||||||
Focus
|
Focus
|
||||||
One
|
One
|
||||||
Zero
|
Zero
|
||||||
|
Result
|
||||||
|
|
||||||
AltBS
|
AltBS
|
||||||
|
|
||||||
@@ -811,3 +814,7 @@ func initPalette(theme *ColorTheme) {
|
|||||||
ColPreviewScrollbar = pair(theme.PreviewScrollbar, theme.PreviewBg)
|
ColPreviewScrollbar = pair(theme.PreviewScrollbar, theme.PreviewBg)
|
||||||
ColPreviewSpinner = pair(theme.Spinner, theme.PreviewBg)
|
ColPreviewSpinner = pair(theme.Spinner, theme.PreviewBg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runeWidth(r rune) int {
|
||||||
|
return uniseg.StringWidth(string(r))
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,14 +6,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/junegunn/uniseg"
|
||||||
"github.com/mattn/go-isatty"
|
"github.com/mattn/go-isatty"
|
||||||
"github.com/mattn/go-runewidth"
|
|
||||||
"github.com/rivo/uniseg"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// StringWidth returns string width where each CR/LF character takes 1 column
|
// StringWidth returns string width where each CR/LF character takes 1 column
|
||||||
func StringWidth(s string) int {
|
func StringWidth(s string) int {
|
||||||
return runewidth.StringWidth(s) + strings.Count(s, "\n") + strings.Count(s, "\r")
|
return uniseg.StringWidth(s) + strings.Count(s, "\n") + strings.Count(s, "\r")
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunesWidth returns runes width
|
// RunesWidth returns runes width
|
||||||
@@ -165,7 +164,7 @@ func RepeatToFill(str string, length int, limit int) string {
|
|||||||
output := strings.Repeat(str, times)
|
output := strings.Repeat(str, times)
|
||||||
if rest > 0 {
|
if rest > 0 {
|
||||||
for _, r := range str {
|
for _, r := range str {
|
||||||
rest -= runewidth.RuneWidth(r)
|
rest -= uniseg.StringWidth(string(r))
|
||||||
if rest < 0 {
|
if rest < 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,6 +164,18 @@ func TestRunesWidth(t *testing.T) {
|
|||||||
t.Errorf("Expected overflow index: %d, actual: %d", args[2], overflowIdx)
|
t.Errorf("Expected overflow index: %d, actual: %d", args[2], overflowIdx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, input := range []struct {
|
||||||
|
s string
|
||||||
|
w int
|
||||||
|
}{
|
||||||
|
{"▶", 1},
|
||||||
|
{"▶️", 2},
|
||||||
|
} {
|
||||||
|
width, _ := RunesWidth([]rune(input.s), 0, 0, 100)
|
||||||
|
if width != input.w {
|
||||||
|
t.Errorf("Expected width of %s: %d, actual: %d", input.s, input.w, width)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTruncate(t *testing.T) {
|
func TestTruncate(t *testing.T) {
|
||||||
|
|||||||
@@ -741,6 +741,12 @@ class TestGoFZF < TestBase
|
|||||||
'xxoxxxxxxx',
|
'xxoxxxxxxx',
|
||||||
'xoxxxxxxxx'
|
'xoxxxxxxxx'
|
||||||
], `#{FZF} -fo --tiebreak=end,length,begin < #{tempname}`.lines(chomp: true)
|
], `#{FZF} -fo --tiebreak=end,length,begin < #{tempname}`.lines(chomp: true)
|
||||||
|
|
||||||
|
writelines(tempname, ['/bar/baz', '/foo/bar/baz'])
|
||||||
|
assert_equal [
|
||||||
|
'/foo/bar/baz',
|
||||||
|
'/bar/baz'
|
||||||
|
], `#{FZF} -fbaz --tiebreak=end < #{tempname}`.lines(chomp: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tiebreak_length_with_nth
|
def test_tiebreak_length_with_nth
|
||||||
@@ -1776,6 +1782,35 @@ class TestGoFZF < TestBase
|
|||||||
assert_equal %w[foo], readonce.lines(chomp: true)
|
assert_equal %w[foo], readonce.lines(chomp: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_accept_or_print_query_without_match
|
||||||
|
tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query')}), :Enter
|
||||||
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
||||||
|
tmux.send_keys 99_999
|
||||||
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
assert_equal %w[99999], readonce.lines(chomp: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_accept_or_print_query_with_match
|
||||||
|
tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query')}), :Enter
|
||||||
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
||||||
|
tmux.send_keys '^99$'
|
||||||
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
assert_equal %w[99], readonce.lines(chomp: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_accept_or_print_query_with_multi_selection
|
||||||
|
tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query --multi')}), :Enter
|
||||||
|
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
||||||
|
tmux.send_keys :BTab, :BTab, :BTab
|
||||||
|
tmux.until { |lines| assert_equal 3, lines.select_count }
|
||||||
|
tmux.send_keys 99_999
|
||||||
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
assert_equal %w[1 2 3], readonce.lines(chomp: true)
|
||||||
|
end
|
||||||
|
|
||||||
def test_preview_update_on_select
|
def test_preview_update_on_select
|
||||||
tmux.send_keys %(seq 10 | fzf -m --preview 'echo {+}' --bind a:toggle-all),
|
tmux.send_keys %(seq 10 | fzf -m --preview 'echo {+}' --bind a:toggle-all),
|
||||||
:Enter
|
:Enter
|
||||||
@@ -1987,6 +2022,13 @@ class TestGoFZF < TestBase
|
|||||||
tmux.until { |lines| assert_equal '> RAB', lines[-1] }
|
tmux.until { |lines| assert_equal '> RAB', lines[-1] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_transform
|
||||||
|
tmux.send_keys %{#{FZF} --bind 'focus:transform:echo "change-prompt({fzf:action})"'}, :Enter
|
||||||
|
tmux.until { |lines| assert_equal 'start', lines[-1] }
|
||||||
|
tmux.send_keys :Up
|
||||||
|
tmux.until { |lines| assert_equal 'up', lines[-1] }
|
||||||
|
end
|
||||||
|
|
||||||
def test_clear_selection
|
def test_clear_selection
|
||||||
tmux.send_keys %(seq 100 | #{FZF} --multi --bind space:clear-selection), :Enter
|
tmux.send_keys %(seq 100 | #{FZF} --multi --bind space:clear-selection), :Enter
|
||||||
tmux.until { |lines| assert_equal 100, lines.match_count }
|
tmux.until { |lines| assert_equal 100, lines.match_count }
|
||||||
@@ -2669,12 +2711,26 @@ class TestGoFZF < TestBase
|
|||||||
tmux.until { |lines| assert_includes(lines[-1], '[[2]]') }
|
tmux.until { |lines| assert_includes(lines[-1], '[[2]]') }
|
||||||
tmux.send_keys :X
|
tmux.send_keys :X
|
||||||
tmux.until { |lines| assert_includes(lines[-1], '[[]]') }
|
tmux.until { |lines| assert_includes(lines[-1], '[[]]') }
|
||||||
|
tmux.send_keys :BSpace
|
||||||
|
tmux.until { |lines| assert_includes(lines[-1], '[[1]]') }
|
||||||
|
tmux.send_keys :X
|
||||||
|
tmux.until { |lines| assert_includes(lines[-1], '[[]]') }
|
||||||
tmux.send_keys '?'
|
tmux.send_keys '?'
|
||||||
tmux.send_keys :BSpace
|
tmux.send_keys :BSpace
|
||||||
tmux.until { |lines| assert_equal 100, lines.match_count }
|
tmux.until { |lines| assert_equal 100, lines.match_count }
|
||||||
tmux.until { |lines| refute_includes(lines[-1], '[[1]]') }
|
tmux.until { |lines| refute_includes(lines[-1], '[[1]]') }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_result_event
|
||||||
|
tmux.send_keys '(echo 0; seq 10) | fzf --bind "result:pos(2)"', :Enter
|
||||||
|
tmux.until { |lines| assert_equal 11, lines.item_count }
|
||||||
|
tmux.until { |lines| assert_includes lines, '> 1' }
|
||||||
|
tmux.send_keys '9'
|
||||||
|
tmux.until { |lines| assert_includes lines, '> 9' }
|
||||||
|
tmux.send_keys :BSpace
|
||||||
|
tmux.until { |lines| assert_includes lines, '> 1' }
|
||||||
|
end
|
||||||
|
|
||||||
def test_labels_center
|
def test_labels_center
|
||||||
tmux.send_keys 'echo x | fzf --border --border-label foobar --preview : --preview-label barfoo --bind "space:change-border-label(foobarfoo)+change-preview-label(barfoobar),enter:transform-border-label(echo foo{}foo)+transform-preview-label(echo bar{}bar)"', :Enter
|
tmux.send_keys 'echo x | fzf --border --border-label foobar --preview : --preview-label barfoo --bind "space:change-border-label(foobarfoo)+change-preview-label(barfoobar),enter:transform-border-label(echo foo{}foo)+transform-preview-label(echo bar{}bar)"', :Enter
|
||||||
tmux.until do
|
tmux.until do
|
||||||
@@ -3020,6 +3076,13 @@ class TestGoFZF < TestBase
|
|||||||
tmux.send_keys :x
|
tmux.send_keys :x
|
||||||
tmux.until { |lines| assert(lines.any? { |line| line.include?('[x-foo]') }) }
|
tmux.until { |lines| assert(lines.any? { |line| line.include?('[x-foo]') }) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_preview_window_hidden_on_focus
|
||||||
|
tmux.send_keys "seq 3 | #{FZF} --preview 'echo {}' --bind focus:hide-preview", :Enter
|
||||||
|
tmux.until { |lines| assert_includes lines, '> 1' }
|
||||||
|
tmux.send_keys :Up
|
||||||
|
tmux.until { |lines| assert_includes lines, '> 2' }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module TestShell
|
module TestShell
|
||||||
|
|||||||
Reference in New Issue
Block a user