mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-15 12:13:52 -07:00
Compare commits
38 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7320b7df62 | ||
|
11fb4233f7 | ||
|
84bb350b14 | ||
|
38e3694d1c | ||
|
1084935241 | ||
|
f5f0b9ecaa | ||
|
230fc49ae2 | ||
|
250d507bdf | ||
|
a818653174 | ||
|
5c3b044740 | ||
|
c5aa8729a1 | ||
|
3f78d76da1 | ||
|
70c19ccf16 | ||
|
68db9cb499 | ||
|
d0466fa777 | ||
|
21ab64e962 | ||
|
a0145cebf2 | ||
|
69176fc5f4 | ||
|
278dce9ba6 | ||
|
1cfa3ee4c7 | ||
|
9a95cd5794 | ||
|
a62fe3df6f | ||
|
7701244a08 | ||
|
96e31e4b78 | ||
|
ec208af474 | ||
|
242641264d | ||
|
d3a9a0615b | ||
|
3277e8c89c | ||
|
d02b9442a5 | ||
|
bac385b59c | ||
|
b1a0ab8086 | ||
|
a33749eb71 | ||
|
f5e4ee90e4 | ||
|
690d5e6dbd | ||
|
a76c055b63 | ||
|
70c461c60b | ||
|
d51b71ee80 | ||
|
3666448ca6 |
2
BUILD.md
2
BUILD.md
@@ -6,7 +6,7 @@ Build instructions
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Go 1.17 or above
|
||||
- Go 1.18 or above
|
||||
|
||||
### Using Makefile
|
||||
|
||||
|
28
CHANGELOG.md
28
CHANGELOG.md
@@ -1,9 +1,37 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
0.44.0
|
||||
------
|
||||
- (Experimental) Sixel image support in preview window (not available on Windows)
|
||||
- [bin/fzf-preview.sh](bin/fzf-preview.sh) is added to demonstrate how to
|
||||
display an image using Kitty image protocol or Sixel. You can use it
|
||||
like so:
|
||||
```sh
|
||||
fzf --preview='fzf-preview.sh {}'
|
||||
```
|
||||
- (Experimental) iTerm2 inline image protocol support in preview window (not available on Windows)
|
||||
```sh
|
||||
# Using https://iterm2.com/utilities/imgcat
|
||||
fzf --preview 'imgcat -W $FZF_PREVIEW_COLUMNS -H $FZF_PREVIEW_LINES {}'
|
||||
```
|
||||
- HTTP server can be configured to accept remote connections
|
||||
```sh
|
||||
# FZF_API_KEY is required for a non-localhost listen address
|
||||
export FZF_API_KEY="$(head -c 32 /dev/urandom | base64)"
|
||||
fzf --listen 0.0.0.0:6266
|
||||
```
|
||||
- To allow remote process execution, use `--listen-unsafe` instead
|
||||
(`execute*`, `reload*`, `become`, `preview`, `change-preview`, `transform-*`)
|
||||
```sh
|
||||
fzf --listen-unsafe 0.0.0.0:6266
|
||||
```
|
||||
- Bug fixes
|
||||
|
||||
0.43.0
|
||||
------
|
||||
- (Experimental) Added support for Kitty image protocol in the preview window
|
||||
(not available on Windows)
|
||||
```sh
|
||||
fzf --preview='
|
||||
if file --mime-type {} | grep -qF image/; then
|
||||
|
4
Makefile
4
Makefile
@@ -93,6 +93,10 @@ build:
|
||||
goreleaser build --rm-dist --snapshot --skip-post-hooks
|
||||
|
||||
release:
|
||||
# Make sure that the tests pass and the build works
|
||||
TAGS=tcell make test
|
||||
make test build clean
|
||||
|
||||
ifndef GITHUB_TOKEN
|
||||
$(error GITHUB_TOKEN is not defined)
|
||||
endif
|
||||
|
74
bin/fzf-preview.sh
Executable file
74
bin/fzf-preview.sh
Executable file
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# The purpose of this script is to demonstrate how to preview a file or an
|
||||
# image in the preview window of fzf.
|
||||
#
|
||||
# Dependencies:
|
||||
# - https://github.com/sharkdp/bat
|
||||
# - https://github.com/hpjansson/chafa
|
||||
# - https://iterm2.com/utilities/imgcat
|
||||
|
||||
if [[ $# -ne 1 ]]; then
|
||||
>&2 echo "usage: $0 FILENAME"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
file=${1/#\~\//$HOME/}
|
||||
type=$(file --dereference --mime -- "$file")
|
||||
|
||||
if [[ ! $type =~ image/ ]]; then
|
||||
if [[ $type =~ =binary ]]; then
|
||||
file "$1"
|
||||
exit
|
||||
fi
|
||||
|
||||
# Sometimes bat is installed as batcat.
|
||||
if command -v batcat > /dev/null; then
|
||||
batname="batcat"
|
||||
elif command -v bat > /dev/null; then
|
||||
batname="bat"
|
||||
else
|
||||
cat "$1"
|
||||
exit
|
||||
fi
|
||||
|
||||
${batname} --style="${BAT_STYLE:-numbers}" --color=always --pager=never -- "$file"
|
||||
exit
|
||||
fi
|
||||
|
||||
dim=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}
|
||||
if [[ $dim = x ]]; then
|
||||
dim=$(stty size < /dev/tty | awk '{print $2 "x" $1}')
|
||||
elif ! [[ $KITTY_WINDOW_ID ]] && (( FZF_PREVIEW_TOP + FZF_PREVIEW_LINES == $(stty size < /dev/tty | awk '{print $1}') )); then
|
||||
# Avoid scrolling issue when the Sixel image touches the bottom of the screen
|
||||
# * https://github.com/junegunn/fzf/issues/2544
|
||||
dim=${FZF_PREVIEW_COLUMNS}x$((FZF_PREVIEW_LINES - 1))
|
||||
fi
|
||||
|
||||
# 1. Use kitty icat on kitty terminal
|
||||
if [[ $KITTY_WINDOW_ID ]]; then
|
||||
# 1. 'memory' is the fastest option but if you want the image to be scrollable,
|
||||
# you have to use 'stream'.
|
||||
#
|
||||
# 2. The last line of the output is the ANSI reset code without newline.
|
||||
# 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.
|
||||
kitty icat --clear --transfer-mode=memory --stdin=no --place="$dim@0x0" "$file" | sed '$d' | sed $'$s/$/\e[m/'
|
||||
|
||||
# 2. Use chafa with Sixel output
|
||||
elif command -v chafa > /dev/null; then
|
||||
chafa -f sixel -s "$dim" "$file"
|
||||
# Add a new line character so that fzf can display multiple images in the preview window
|
||||
echo
|
||||
|
||||
# 3. If chafa is not found but imgcat is available, use it on iTerm2
|
||||
elif command -v imgcat > /dev/null; then
|
||||
# NOTE: We should use https://iterm2.com/utilities/it2check to check if the
|
||||
# user is running iTerm2. But for the sake of simplicity, we just assume
|
||||
# that's the case here.
|
||||
imgcat -W "${dim%%x*}" -H "${dim##*x}" "$file"
|
||||
|
||||
# 4. Cannot find any suitable method to preview the image
|
||||
else
|
||||
file "$file"
|
||||
fi
|
2
go.mod
2
go.mod
@@ -7,7 +7,7 @@ require (
|
||||
github.com/mattn/go-shellwords v1.0.12
|
||||
github.com/rivo/uniseg v0.4.4
|
||||
github.com/saracen/walker v0.1.3
|
||||
golang.org/x/sys v0.13.0
|
||||
golang.org/x/sys v0.14.0
|
||||
golang.org/x/term v0.13.0
|
||||
)
|
||||
|
||||
|
5
go.sum
5
go.sum
@@ -23,7 +23,6 @@ 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-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-20220601150217-0de741cfad7f/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-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -32,8 +31,8 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
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-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
|
||||
golang.org/x/sys v0.14.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-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
|
||||
|
2
install
2
install
@@ -2,7 +2,7 @@
|
||||
|
||||
set -u
|
||||
|
||||
version=0.43.0
|
||||
version=0.44.0
|
||||
auto_completion=
|
||||
key_bindings=
|
||||
update_config=2
|
||||
|
@@ -1,4 +1,4 @@
|
||||
$version="0.43.0"
|
||||
$version="0.44.0"
|
||||
|
||||
$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"
|
||||
)
|
||||
|
||||
var version string = "0.43"
|
||||
var version string = "0.44"
|
||||
var revision string = "devel"
|
||||
|
||||
func main() {
|
||||
|
@@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
..
|
||||
.TH fzf-tmux 1 "Oct 2023" "fzf 0.43.0" "fzf-tmux - open fzf in tmux split pane"
|
||||
.TH fzf-tmux 1 "Nov 2023" "fzf 0.44.0" "fzf-tmux - open fzf in tmux split pane"
|
||||
|
||||
.SH NAME
|
||||
fzf-tmux - open fzf in tmux split pane
|
||||
|
@@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
..
|
||||
.TH fzf 1 "Oct 2023" "fzf 0.43.0" "fzf - a command-line fuzzy finder"
|
||||
.TH fzf 1 "Nov 2023" "fzf 0.44.0" "fzf - a command-line fuzzy finder"
|
||||
|
||||
.SH NAME
|
||||
fzf - a command-line fuzzy finder
|
||||
@@ -548,6 +548,9 @@ they represent the exact size of the preview window. (It also overrides
|
||||
by the default shell, so prefer to refer to the ones with \fBFZF_PREVIEW_\fR
|
||||
prefix.)
|
||||
|
||||
fzf also exports \fB$FZF_PREVIEW_TOP\fR and \fB$FZF_PREVIEW_LEFT\fR so that
|
||||
the preview command can determine the position of the preview window.
|
||||
|
||||
A placeholder expression starting with \fB+\fR flag will be replaced to the
|
||||
space-separated list of the selected lines (or the current line if no selection
|
||||
was made) individually quoted.
|
||||
@@ -592,17 +595,13 @@ e.g.
|
||||
sleep 0.01
|
||||
done'\fR
|
||||
|
||||
Since 0.43.0, fzf has experimental support for Kitty graphics protocol,
|
||||
so if you use Kitty, you can make fzf display an image in the preview window.
|
||||
fzf has experimental support for Kitty graphics protocol and Sixel graphics.
|
||||
The following example uses https://github.com/junegunn/fzf/blob/master/bin/fzf-preview.sh
|
||||
script to render an image using either of the protocols inside the preview window.
|
||||
|
||||
e.g.
|
||||
\fBfzf --preview='
|
||||
if file --mime-type {} | grep -qF "image/"; then
|
||||
kitty icat --clear --transfer-mode=memory --stdin=no --place=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}@0x0 {} | sed \\$d
|
||||
else
|
||||
bat --color=always {}
|
||||
fi
|
||||
'\fR
|
||||
\fBfzf --preview='fzf-preview.sh {}'
|
||||
|
||||
.RE
|
||||
|
||||
.TP
|
||||
@@ -794,14 +793,19 @@ ncurses finder only after the input stream is complete.
|
||||
e.g. \fBfzf --multi | fzf --sync\fR
|
||||
.RE
|
||||
.TP
|
||||
.B "--listen[=HTTP_PORT]"
|
||||
Start HTTP server on the given port. It allows external processes to send
|
||||
actions to perform via POST method. If the port number is omitted or given as
|
||||
0, fzf will choose the port automatically and export it as \fBFZF_PORT\fR
|
||||
environment variable to the child processes started via \fBexecute\fR and
|
||||
\fBexecute-silent\fR actions. If \fBFZF_API_KEY\fR environment variable is
|
||||
set, the server would require sending an API key with the same value in the
|
||||
\fBx-api-key\fR HTTP header.
|
||||
.B "--listen[=[ADDR:]PORT]" "--listen-unsafe[=[ADDR:]PORT]"
|
||||
Start HTTP server and listen on the given address. It allows external processes
|
||||
to send actions to perform via POST method.
|
||||
|
||||
- If the port number is omitted or given as 0, fzf will automatically choose
|
||||
a port and export it as \fBFZF_PORT\fR environment variable to the child processes
|
||||
|
||||
- If \fBFZF_API_KEY\fR environment variable is set, the server would require
|
||||
sending an API key with the same value in the \fBx-api-key\fR HTTP header
|
||||
|
||||
- \fBFZF_API_KEY\fR is required for a non-localhost listen address
|
||||
|
||||
- To allow remote process execution, use \fB--listen-unsafe\fR
|
||||
|
||||
e.g.
|
||||
\fB# Start HTTP server on port 6266
|
||||
@@ -813,8 +817,12 @@ e.g.
|
||||
# Send action to the server
|
||||
curl -XPOST localhost:6266 -d 'reload(seq 100)+change-prompt(hundred> )'
|
||||
|
||||
# Start HTTP server on port 6266 and send an authenticated action
|
||||
# Start HTTP server on port 6266 with remote connections allowed
|
||||
# * Listening on non-localhost address requires using an API key
|
||||
export FZF_API_KEY="$(head -c 32 /dev/urandom | base64)"
|
||||
fzf --listen 0.0.0.0:6266
|
||||
|
||||
# Send an authenticated action
|
||||
curl -XPOST localhost:6266 -H "x-api-key: $FZF_API_KEY" -d 'change-query(yo)'
|
||||
|
||||
# Choose port automatically and export it as $FZF_PORT to the child process
|
||||
|
@@ -423,8 +423,8 @@ if ! declare -F __fzf_list_hosts > /dev/null; then
|
||||
__fzf_list_hosts() {
|
||||
command cat <(command tail -n +1 ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null | command grep -i '^\s*host\(name\)\? ' | command awk '{for (i = 2; i <= NF; i++) print $1 " " $i}' | command grep -v '[*?%]') \
|
||||
<(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts 2> /dev/null | command tr ',' '\n' | command tr -d '[' | command awk '{ print $1 " " $1 }') \
|
||||
<(command grep -v '^\s*\(#\|$\)' /etc/hosts 2> /dev/null | command grep -Fv '0.0.0.0') |
|
||||
command awk '{if (length($2) > 0) {print $2}}' | command sort -u
|
||||
<(command grep -v '^\s*\(#\|$\)' /etc/hosts 2> /dev/null | command grep -Fv '0.0.0.0' | command sed 's/#.*//') |
|
||||
command awk '{for (i = 2; i <= NF; i++) print $i}' | command sort -u
|
||||
}
|
||||
fi
|
||||
|
||||
@@ -481,7 +481,7 @@ a_cmds="
|
||||
svn tar unzip zip"
|
||||
|
||||
# Preserve existing completion
|
||||
__fzf_orig_completion < <(complete -p $d_cmds $a_cmds 2> /dev/null)
|
||||
__fzf_orig_completion < <(complete -p $d_cmds $a_cmds ssh 2> /dev/null)
|
||||
|
||||
if type _completion_loader > /dev/null 2>&1; then
|
||||
_fzf_completion_loader=1
|
||||
|
@@ -226,8 +226,8 @@ if ! declare -f __fzf_list_hosts > /dev/null; then
|
||||
setopt localoptions nonomatch
|
||||
command cat <(command tail -n +1 ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null | command grep -i '^\s*host\(name\)\? ' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}' | command grep -v '[*?%]') \
|
||||
<(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts 2> /dev/null | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \
|
||||
<(command grep -v '^\s*\(#\|$\)' /etc/hosts 2> /dev/null | command grep -Fv '0.0.0.0') |
|
||||
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
||||
<(command grep -v '^\s*\(#\|$\)' /etc/hosts 2> /dev/null | command grep -Fv '0.0.0.0' | command sed 's/#.*//') |
|
||||
awk '{for (i = 2; i <= NF; i++) print $i}' | sort -u
|
||||
}
|
||||
fi
|
||||
|
||||
|
@@ -118,7 +118,8 @@ const usage = `usage: fzf [options]
|
||||
--read0 Read input delimited by ASCII NUL characters
|
||||
--print0 Print output delimited by ASCII NUL characters
|
||||
--sync Synchronous search for multi-staged filtering
|
||||
--listen[=HTTP_PORT] Start HTTP server to receive actions (POST /)
|
||||
--listen[=[ADDR:]PORT] Start HTTP server to receive actions (POST /)
|
||||
(To allow remote process execution, use --listen-unsafe)
|
||||
--version Display version information and exit
|
||||
|
||||
Environment variables
|
||||
@@ -334,7 +335,8 @@ type Options struct {
|
||||
PreviewLabel labelOpts
|
||||
Unicode bool
|
||||
Tabstop int
|
||||
ListenPort *int
|
||||
ListenAddr *listenAddress
|
||||
Unsafe bool
|
||||
ClearOnExit bool
|
||||
Version bool
|
||||
}
|
||||
@@ -404,6 +406,7 @@ func defaultOptions() *Options {
|
||||
Tabstop: 8,
|
||||
BorderLabel: labelOpts{},
|
||||
PreviewLabel: labelOpts{},
|
||||
Unsafe: false,
|
||||
ClearOnExit: true,
|
||||
Version: false}
|
||||
}
|
||||
@@ -1832,11 +1835,21 @@ func parseOptions(opts *Options, allArgs []string) {
|
||||
nextString(allArgs, &i, "padding required (TRBL / TB,RL / T,RL,B / T,R,B,L)"))
|
||||
case "--tabstop":
|
||||
opts.Tabstop = nextInt(allArgs, &i, "tab stop required")
|
||||
case "--listen":
|
||||
port := optionalNumeric(allArgs, &i, 0)
|
||||
opts.ListenPort = &port
|
||||
case "--no-listen":
|
||||
opts.ListenPort = nil
|
||||
case "--listen", "--listen-unsafe":
|
||||
given, str := optionalNextString(allArgs, &i)
|
||||
addr := defaultListenAddr
|
||||
if given {
|
||||
var err error
|
||||
err, addr = parseListenAddress(str)
|
||||
if err != nil {
|
||||
errorExit(err.Error())
|
||||
}
|
||||
}
|
||||
opts.ListenAddr = &addr
|
||||
opts.Unsafe = arg == "--listen-unsafe"
|
||||
case "--no-listen", "--no-listen-unsafe":
|
||||
opts.ListenAddr = nil
|
||||
opts.Unsafe = false
|
||||
case "--clear":
|
||||
opts.ClearOnExit = true
|
||||
case "--no-clear":
|
||||
@@ -1927,8 +1940,19 @@ func parseOptions(opts *Options, allArgs []string) {
|
||||
} else if match, value := optString(arg, "--tabstop="); match {
|
||||
opts.Tabstop = atoi(value)
|
||||
} else if match, value := optString(arg, "--listen="); match {
|
||||
port := atoi(value)
|
||||
opts.ListenPort = &port
|
||||
err, addr := parseListenAddress(value)
|
||||
if err != nil {
|
||||
errorExit(err.Error())
|
||||
}
|
||||
opts.ListenAddr = &addr
|
||||
opts.Unsafe = false
|
||||
} else if match, value := optString(arg, "--listen-unsafe="); match {
|
||||
err, addr := parseListenAddress(value)
|
||||
if err != nil {
|
||||
errorExit(err.Error())
|
||||
}
|
||||
opts.ListenAddr = &addr
|
||||
opts.Unsafe = true
|
||||
} else if match, value := optString(arg, "--hscroll-off="); match {
|
||||
opts.HscrollOff = atoi(value)
|
||||
} else if match, value := optString(arg, "--scroll-off="); match {
|
||||
@@ -1958,10 +1982,6 @@ func parseOptions(opts *Options, allArgs []string) {
|
||||
errorExit("tab stop must be a positive integer")
|
||||
}
|
||||
|
||||
if opts.ListenPort != nil && (*opts.ListenPort < 0 || *opts.ListenPort > 65535) {
|
||||
errorExit("invalid listen port")
|
||||
}
|
||||
|
||||
if len(opts.JumpLabels) == 0 {
|
||||
errorExit("empty jump labels")
|
||||
}
|
||||
|
@@ -6,5 +6,5 @@ import "golang.org/x/sys/unix"
|
||||
|
||||
// Protect calls OS specific protections like pledge on OpenBSD
|
||||
func Protect() {
|
||||
unix.PledgePromises("stdio rpath tty proc exec")
|
||||
unix.PledgePromises("stdio rpath tty proc exec inet")
|
||||
}
|
||||
|
@@ -40,30 +40,63 @@ type httpServer struct {
|
||||
responseChannel chan string
|
||||
}
|
||||
|
||||
func startHttpServer(port int, actionChannel chan []*action, responseChannel chan string) (error, int) {
|
||||
if port < 0 {
|
||||
return nil, port
|
||||
}
|
||||
type listenAddress struct {
|
||||
host string
|
||||
port int
|
||||
}
|
||||
|
||||
listener, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", port))
|
||||
func (addr listenAddress) IsLocal() bool {
|
||||
return addr.host == "localhost" || addr.host == "127.0.0.1"
|
||||
}
|
||||
|
||||
var defaultListenAddr = listenAddress{"localhost", 0}
|
||||
|
||||
func parseListenAddress(address string) (error, listenAddress) {
|
||||
parts := strings.SplitN(address, ":", 3)
|
||||
if len(parts) == 1 {
|
||||
parts = []string{"localhost", parts[0]}
|
||||
}
|
||||
if len(parts) != 2 {
|
||||
return fmt.Errorf("invalid listen address: %s", address), defaultListenAddr
|
||||
}
|
||||
portStr := parts[len(parts)-1]
|
||||
port, err := strconv.Atoi(portStr)
|
||||
if err != nil || port < 0 || port > 65535 {
|
||||
return fmt.Errorf("invalid listen port: %s", portStr), defaultListenAddr
|
||||
}
|
||||
if len(parts[0]) == 0 {
|
||||
parts[0] = "localhost"
|
||||
}
|
||||
return nil, listenAddress{parts[0], port}
|
||||
}
|
||||
|
||||
func startHttpServer(address listenAddress, actionChannel chan []*action, responseChannel chan string) (error, int) {
|
||||
host := address.host
|
||||
port := address.port
|
||||
apiKey := os.Getenv("FZF_API_KEY")
|
||||
if !address.IsLocal() && len(apiKey) == 0 {
|
||||
return fmt.Errorf("FZF_API_KEY is required to allow remote access"), port
|
||||
}
|
||||
addrStr := fmt.Sprintf("%s:%d", host, port)
|
||||
listener, err := net.Listen("tcp", addrStr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("port not available: %d", port), port
|
||||
return fmt.Errorf("failed to listen on %s", addrStr), port
|
||||
}
|
||||
if port == 0 {
|
||||
addr := listener.Addr().String()
|
||||
parts := strings.SplitN(addr, ":", 2)
|
||||
parts := strings.Split(addr, ":")
|
||||
if len(parts) < 2 {
|
||||
return fmt.Errorf("cannot extract port: %s", addr), port
|
||||
}
|
||||
var err error
|
||||
port, err = strconv.Atoi(parts[1])
|
||||
port, err = strconv.Atoi(parts[len(parts)-1])
|
||||
if err != nil {
|
||||
return err, port
|
||||
}
|
||||
}
|
||||
|
||||
server := httpServer{
|
||||
apiKey: []byte(os.Getenv("FZF_API_KEY")),
|
||||
apiKey: []byte(apiKey),
|
||||
actionChannel: actionChannel,
|
||||
responseChannel: responseChannel,
|
||||
}
|
||||
|
217
src/terminal.go
217
src/terminal.go
@@ -65,7 +65,9 @@ func init() {
|
||||
// Parts of the preview output that should be passed through to the terminal
|
||||
// * https://github.com/tmux/tmux/wiki/FAQ#what-is-the-passthrough-escape-sequence-and-how-do-i-use-it
|
||||
// * https://sw.kovidgoyal.net/kitty/graphics-protocol
|
||||
passThroughRegex = regexp.MustCompile(`\x1bPtmux;\x1b\x1b.*?[^\x1b]\x1b\\|\x1b_G.*?\x1b\\`)
|
||||
// * https://en.wikipedia.org/wiki/Sixel
|
||||
// * https://iterm2.com/documentation-images.html
|
||||
passThroughRegex = regexp.MustCompile(`\x1bPtmux;\x1b\x1b.*?[^\x1b]\x1b\\|\x1b(_G|P[0-9;]*q).*?\x1b\\\r?|\x1b]1337;.*?\a`)
|
||||
}
|
||||
|
||||
type jumpMode int
|
||||
@@ -120,10 +122,13 @@ type previewer struct {
|
||||
}
|
||||
|
||||
type previewed struct {
|
||||
version int64
|
||||
numLines int
|
||||
offset int
|
||||
filled bool
|
||||
version int64
|
||||
numLines int
|
||||
offset int
|
||||
filled bool
|
||||
image bool
|
||||
wipe bool
|
||||
wireframe bool
|
||||
}
|
||||
|
||||
type eachLine struct {
|
||||
@@ -231,7 +236,9 @@ type Terminal struct {
|
||||
margin [4]sizeSpec
|
||||
padding [4]sizeSpec
|
||||
unicode bool
|
||||
listenAddr *listenAddress
|
||||
listenPort *int
|
||||
listenUnsafe bool
|
||||
borderShape tui.BorderShape
|
||||
cleanExit bool
|
||||
paused bool
|
||||
@@ -277,6 +284,7 @@ type Terminal struct {
|
||||
theme *tui.ColorTheme
|
||||
tui tui.Renderer
|
||||
executing *util.AtomicBool
|
||||
termSize tui.TermSize
|
||||
}
|
||||
|
||||
type selectedItem struct {
|
||||
@@ -307,6 +315,7 @@ const (
|
||||
reqRefresh
|
||||
reqReinit
|
||||
reqFullRedraw
|
||||
reqResize
|
||||
reqRedrawBorderLabel
|
||||
reqRedrawPreviewLabel
|
||||
reqClose
|
||||
@@ -429,6 +438,26 @@ const (
|
||||
actResponse
|
||||
)
|
||||
|
||||
func processExecution(action actionType) bool {
|
||||
switch action {
|
||||
case actTransformBorderLabel,
|
||||
actTransformHeader,
|
||||
actTransformPreviewLabel,
|
||||
actTransformPrompt,
|
||||
actTransformQuery,
|
||||
actPreview,
|
||||
actChangePreview,
|
||||
actExecute,
|
||||
actExecuteSilent,
|
||||
actExecuteMulti,
|
||||
actReload,
|
||||
actReloadSync,
|
||||
actBecome:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type placeholderFlags struct {
|
||||
plus bool
|
||||
preserveSpace bool
|
||||
@@ -446,7 +475,7 @@ type searchRequest struct {
|
||||
|
||||
type previewRequest struct {
|
||||
template string
|
||||
pwindow tui.Window
|
||||
pwindowSize tui.TermSize
|
||||
scrollOffset int
|
||||
list []*Item
|
||||
}
|
||||
@@ -580,7 +609,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
||||
}
|
||||
var previewBox *util.EventBox
|
||||
// We need to start previewer if HTTP server is enabled even when --preview option is not specified
|
||||
if len(opts.Preview.command) > 0 || hasPreviewAction(opts) || opts.ListenPort != nil {
|
||||
if len(opts.Preview.command) > 0 || hasPreviewAction(opts) || opts.ListenAddr != nil {
|
||||
previewBox = util.NewEventBox()
|
||||
}
|
||||
var renderer tui.Renderer
|
||||
@@ -653,7 +682,8 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
||||
margin: opts.Margin,
|
||||
padding: opts.Padding,
|
||||
unicode: opts.Unicode,
|
||||
listenPort: opts.ListenPort,
|
||||
listenAddr: opts.ListenAddr,
|
||||
listenUnsafe: opts.Unsafe,
|
||||
borderShape: opts.BorderShape,
|
||||
borderWidth: 1,
|
||||
borderLabel: nil,
|
||||
@@ -686,7 +716,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
||||
initialPreviewOpts: opts.Preview,
|
||||
previewOpts: opts.Preview,
|
||||
previewer: previewer{0, []string{}, 0, false, true, disabledState, "", []bool{}},
|
||||
previewed: previewed{0, 0, 0, false},
|
||||
previewed: previewed{0, 0, 0, false, false, false, false},
|
||||
previewBox: previewBox,
|
||||
eventBox: eventBox,
|
||||
mutex: sync.Mutex{},
|
||||
@@ -742,8 +772,8 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
||||
|
||||
_, t.hasLoadActions = t.keymap[tui.Load.AsEvent()]
|
||||
|
||||
if t.listenPort != nil {
|
||||
err, port := startHttpServer(*t.listenPort, t.serverInputChan, t.serverOutputChan)
|
||||
if t.listenAddr != nil {
|
||||
err, port := startHttpServer(*t.listenAddr, t.serverInputChan, t.serverOutputChan)
|
||||
if err != nil {
|
||||
errorExit(err.Error())
|
||||
}
|
||||
@@ -1301,10 +1331,6 @@ func (t *Terminal) resizeWindows(forcePreview bool) {
|
||||
if previewOpts.hidden {
|
||||
return
|
||||
}
|
||||
// Put scrollbar closer to the right border for consistent look
|
||||
if t.borderShape.HasRight() {
|
||||
width++
|
||||
}
|
||||
if previewOpts.position == posUp {
|
||||
t.window = t.tui.NewWindow(
|
||||
marginInt[0]+pheight, marginInt[3], width, height-pheight, false, noBorder)
|
||||
@@ -1933,11 +1959,21 @@ func (t *Terminal) renderPreviewSpinner() {
|
||||
}
|
||||
|
||||
func (t *Terminal) renderPreviewArea(unchanged bool) {
|
||||
if unchanged {
|
||||
if t.previewed.wipe && t.previewed.version != t.previewer.version {
|
||||
t.previewed.wipe = false
|
||||
t.pwindow.Erase()
|
||||
} else if unchanged {
|
||||
t.pwindow.MoveAndClear(0, 0) // Clear scroll offset display
|
||||
} else {
|
||||
t.previewed.filled = false
|
||||
t.pwindow.Erase()
|
||||
// We don't erase the window here to avoid flickering during scroll.
|
||||
// However, tcell renderer uses double-buffering technique and there's no
|
||||
// flickering. So we just erase the window and make the rest of the code
|
||||
// simpler.
|
||||
if !t.pwindow.EraseMaybe() {
|
||||
t.pwindow.DrawBorder()
|
||||
t.pwindow.Move(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
height := t.pwindow.Height()
|
||||
@@ -1967,10 +2003,32 @@ func (t *Terminal) renderPreviewArea(unchanged bool) {
|
||||
t.renderPreviewScrollbar(headerLines, barLength, barStart)
|
||||
}
|
||||
|
||||
func (t *Terminal) makeImageBorder(width int, top bool) string {
|
||||
tl := "┌"
|
||||
tr := "┐"
|
||||
v := "╎"
|
||||
h := "╌"
|
||||
if !t.unicode {
|
||||
tl = "+"
|
||||
tr = "+"
|
||||
h = "-"
|
||||
v = "|"
|
||||
}
|
||||
repeat := util.Max(0, width-2)
|
||||
if top {
|
||||
return tl + strings.Repeat(h, repeat) + tr
|
||||
}
|
||||
return v + strings.Repeat(" ", repeat) + v
|
||||
}
|
||||
|
||||
func (t *Terminal) renderPreviewText(height int, lines []string, lineNo int, unchanged bool) {
|
||||
maxWidth := t.pwindow.Width()
|
||||
var ansi *ansiState
|
||||
spinnerRedraw := t.pwindow.Y() == 0
|
||||
wiped := false
|
||||
image := false
|
||||
wireframe := false
|
||||
Loop:
|
||||
for _, line := range lines {
|
||||
var lbg tui.Color = -1
|
||||
if ansi != nil {
|
||||
@@ -1988,16 +2046,76 @@ func (t *Terminal) renderPreviewText(height int, lines []string, lineNo int, unc
|
||||
t.previewer.scrollable = true
|
||||
break
|
||||
} else if lineNo >= 0 {
|
||||
x := t.pwindow.X()
|
||||
y := t.pwindow.Y()
|
||||
if spinnerRedraw && lineNo > 0 {
|
||||
spinnerRedraw = false
|
||||
y := t.pwindow.Y()
|
||||
x := t.pwindow.X()
|
||||
t.renderPreviewSpinner()
|
||||
t.pwindow.Move(y, x)
|
||||
}
|
||||
for _, passThrough := range passThroughs {
|
||||
for idx, passThrough := range passThroughs {
|
||||
// Handling Sixel/iTerm image
|
||||
requiredLines := 0
|
||||
isSixel := strings.HasPrefix(passThrough, "\x1bP")
|
||||
isItermImage := strings.HasPrefix(passThrough, "\x1b]1337;")
|
||||
isImage := isSixel || isItermImage
|
||||
if isImage {
|
||||
t.previewed.wipe = true
|
||||
// NOTE: We don't have a good way to get the height of an iTerm image,
|
||||
// so we assume that it requires the full height of the preview
|
||||
// window.
|
||||
requiredLines = height
|
||||
|
||||
if isSixel && t.termSize.PxHeight > 0 {
|
||||
rows := strings.Count(passThrough, "-")
|
||||
requiredLines = int(math.Ceil(float64(rows*6*t.termSize.Lines) / float64(t.termSize.PxHeight)))
|
||||
}
|
||||
}
|
||||
|
||||
// Render wireframe when the image cannot be displayed entirely
|
||||
if requiredLines > 0 && y+requiredLines > height {
|
||||
top := true
|
||||
for ; y < height; y++ {
|
||||
t.pwindow.MoveAndClear(y, 0)
|
||||
t.pwindow.CFill(tui.ColPreview.Fg(), tui.ColPreview.Bg(), tui.AttrRegular, t.makeImageBorder(maxWidth, top))
|
||||
top = false
|
||||
}
|
||||
wireframe = true
|
||||
t.previewed.filled = true
|
||||
t.previewer.scrollable = true
|
||||
break Loop
|
||||
}
|
||||
|
||||
// Clear previous wireframe or any other text
|
||||
if (t.previewed.wireframe || isImage && !t.previewed.image) && !wiped {
|
||||
wiped = true
|
||||
for i := y + 1; i < height; i++ {
|
||||
t.pwindow.MoveAndClear(i, 0)
|
||||
}
|
||||
}
|
||||
image = image || isImage
|
||||
if idx == 0 {
|
||||
t.pwindow.MoveAndClear(y, x)
|
||||
} else {
|
||||
t.pwindow.Move(y, x)
|
||||
}
|
||||
t.tui.PassThrough(passThrough)
|
||||
|
||||
if requiredLines > 0 {
|
||||
if y+requiredLines == height {
|
||||
t.pwindow.Move(height-1, maxWidth-1)
|
||||
t.previewed.filled = true
|
||||
break Loop
|
||||
} else {
|
||||
t.pwindow.MoveAndClear(y+requiredLines, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(passThroughs) > 0 && len(line) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
var fillRet tui.FillReturn
|
||||
prefixWidth := 0
|
||||
_, _, ansi = extractColor(line, ansi, func(str string, ansi *ansiState) bool {
|
||||
@@ -2038,6 +2156,8 @@ func (t *Terminal) renderPreviewText(height int, lines []string, lineNo int, unc
|
||||
}
|
||||
lineNo++
|
||||
}
|
||||
t.previewed.image = image
|
||||
t.previewed.wireframe = wireframe
|
||||
}
|
||||
|
||||
func (t *Terminal) renderPreviewScrollbar(yoff int, barLength int, barStart int) {
|
||||
@@ -2085,7 +2205,7 @@ func (t *Terminal) printPreview() {
|
||||
unchanged := (t.previewed.filled || numLines == t.previewed.numLines) &&
|
||||
t.previewer.version == t.previewed.version &&
|
||||
t.previewer.offset == t.previewed.offset
|
||||
t.previewer.scrollable = t.previewer.offset > 0 || numLines > height
|
||||
t.previewer.scrollable = t.previewer.offset > t.previewOpts.headerLines || numLines > height
|
||||
t.renderPreviewArea(unchanged)
|
||||
t.renderPreviewSpinner()
|
||||
t.previewed.numLines = numLines
|
||||
@@ -2571,6 +2691,19 @@ func (t *Terminal) cancelPreview() {
|
||||
t.killPreview(exitCancel)
|
||||
}
|
||||
|
||||
func (t *Terminal) pwindowSize() tui.TermSize {
|
||||
if t.pwindow == nil {
|
||||
return tui.TermSize{}
|
||||
}
|
||||
size := tui.TermSize{Lines: t.pwindow.Height(), Columns: t.pwindow.Width()}
|
||||
|
||||
if t.termSize.PxWidth > 0 {
|
||||
size.PxWidth = size.Columns * t.termSize.PxWidth / t.termSize.Columns
|
||||
size.PxHeight = size.Lines * t.termSize.PxHeight / t.termSize.Lines
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
// Loop is called to start Terminal I/O
|
||||
func (t *Terminal) Loop() {
|
||||
// prof := profile.Start(profile.ProfilePath("/tmp/"))
|
||||
@@ -2622,12 +2755,13 @@ func (t *Terminal) Loop() {
|
||||
go func() {
|
||||
for {
|
||||
<-resizeChan
|
||||
t.reqBox.Set(reqFullRedraw, nil)
|
||||
t.reqBox.Set(reqResize, nil)
|
||||
}
|
||||
}()
|
||||
|
||||
t.mutex.Lock()
|
||||
t.initFunc()
|
||||
t.termSize = t.tui.Size()
|
||||
t.resizeWindows(false)
|
||||
t.printPrompt()
|
||||
t.printInfo()
|
||||
@@ -2660,7 +2794,7 @@ func (t *Terminal) Loop() {
|
||||
for {
|
||||
var items []*Item
|
||||
var commandTemplate string
|
||||
var pwindow tui.Window
|
||||
var pwindowSize tui.TermSize
|
||||
initialOffset := 0
|
||||
t.previewBox.Wait(func(events *util.Events) {
|
||||
for req, value := range *events {
|
||||
@@ -2670,7 +2804,7 @@ func (t *Terminal) Loop() {
|
||||
commandTemplate = request.template
|
||||
initialOffset = request.scrollOffset
|
||||
items = request.list
|
||||
pwindow = request.pwindow
|
||||
pwindowSize = request.pwindowSize
|
||||
}
|
||||
}
|
||||
events.Clear()
|
||||
@@ -2682,14 +2816,15 @@ func (t *Terminal) Loop() {
|
||||
command := t.replacePlaceholder(commandTemplate, false, string(query), items)
|
||||
cmd := util.ExecCommand(command, true)
|
||||
env := t.environ()
|
||||
if pwindow != nil {
|
||||
height := pwindow.Height()
|
||||
lines := fmt.Sprintf("LINES=%d", height)
|
||||
columns := fmt.Sprintf("COLUMNS=%d", pwindow.Width())
|
||||
if pwindowSize.Lines > 0 {
|
||||
lines := fmt.Sprintf("LINES=%d", pwindowSize.Lines)
|
||||
columns := fmt.Sprintf("COLUMNS=%d", pwindowSize.Columns)
|
||||
env = append(env, lines)
|
||||
env = append(env, "FZF_PREVIEW_"+lines)
|
||||
env = append(env, 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_LEFT=%d", t.pwindow.Left()))
|
||||
}
|
||||
cmd.Env = env
|
||||
|
||||
@@ -2817,7 +2952,7 @@ func (t *Terminal) Loop() {
|
||||
if len(command) > 0 && t.canPreview() {
|
||||
_, list := t.buildPlusList(command, false)
|
||||
t.cancelPreview()
|
||||
t.previewBox.Set(reqPreviewEnqueue, previewRequest{command, t.pwindow, t.evaluateScrollOffset(), list})
|
||||
t.previewBox.Set(reqPreviewEnqueue, previewRequest{command, t.pwindowSize(), t.evaluateScrollOffset(), list})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2885,7 +3020,10 @@ func (t *Terminal) Loop() {
|
||||
case reqReinit:
|
||||
t.tui.Resume(t.fullscreen, t.sigstop)
|
||||
t.redraw()
|
||||
case reqFullRedraw:
|
||||
case reqResize, reqFullRedraw:
|
||||
if req == reqResize {
|
||||
t.termSize = t.tui.Size()
|
||||
}
|
||||
wasHidden := t.pwindow == nil
|
||||
t.redraw()
|
||||
if wasHidden && t.hasPreviewWindow() {
|
||||
@@ -2974,8 +3112,18 @@ func (t *Terminal) Loop() {
|
||||
select {
|
||||
case event = <-t.eventChan:
|
||||
needBarrier = !event.Is(tui.Load, tui.One, tui.Zero)
|
||||
case actions = <-t.serverInputChan:
|
||||
case serverActions := <-t.serverInputChan:
|
||||
event = tui.Invalid.AsEvent()
|
||||
if t.listenAddr == nil || t.listenAddr.IsLocal() || t.listenUnsafe {
|
||||
actions = serverActions
|
||||
} else {
|
||||
for _, action := range serverActions {
|
||||
if !processExecution(action.t) {
|
||||
actions = append(actions, action)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
needBarrier = false
|
||||
}
|
||||
}
|
||||
@@ -3102,8 +3250,12 @@ func (t *Terminal) Loop() {
|
||||
if valid {
|
||||
t.cancelPreview()
|
||||
t.previewBox.Set(reqPreviewEnqueue,
|
||||
previewRequest{t.previewOpts.command, t.pwindow, t.evaluateScrollOffset(), list})
|
||||
previewRequest{t.previewOpts.command, t.pwindowSize(), t.evaluateScrollOffset(), list})
|
||||
}
|
||||
} else {
|
||||
// Discard the preview content so that it won't accidentally appear
|
||||
// when preview window is re-enabled and previewDelay is triggered
|
||||
t.previewer.lines = nil
|
||||
}
|
||||
}
|
||||
case actTogglePreviewWrap:
|
||||
@@ -3158,6 +3310,7 @@ func (t *Terminal) Loop() {
|
||||
}
|
||||
case actBeginningOfLine:
|
||||
t.cx = 0
|
||||
t.xoffset = 0
|
||||
case actBackwardChar:
|
||||
if t.cx > 0 {
|
||||
t.cx--
|
||||
|
@@ -7,6 +7,8 @@ import (
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func notifyOnResize(resizeChan chan<- os.Signal) {
|
||||
@@ -14,7 +16,12 @@ func notifyOnResize(resizeChan chan<- os.Signal) {
|
||||
}
|
||||
|
||||
func notifyStop(p *os.Process) {
|
||||
p.Signal(syscall.SIGSTOP)
|
||||
pid := p.Pid
|
||||
pgid, err := unix.Getpgid(pid)
|
||||
if err == nil {
|
||||
pid = pgid * -1
|
||||
}
|
||||
unix.Kill(pid, syscall.SIGSTOP)
|
||||
}
|
||||
|
||||
func notifyOnCont(resizeChan chan<- os.Signal) {
|
||||
|
@@ -38,8 +38,10 @@ func (r *FullscreenRenderer) Clear() {}
|
||||
func (r *FullscreenRenderer) NeedScrollbarRedraw() bool { return false }
|
||||
func (r *FullscreenRenderer) Refresh() {}
|
||||
func (r *FullscreenRenderer) Close() {}
|
||||
func (r *FullscreenRenderer) Size() TermSize { return TermSize{} }
|
||||
|
||||
func (r *FullscreenRenderer) GetChar() Event { return Event{} }
|
||||
func (r *FullscreenRenderer) Top() int { return 0 }
|
||||
func (r *FullscreenRenderer) MaxX() int { return 0 }
|
||||
func (r *FullscreenRenderer) MaxY() int { return 0 }
|
||||
|
||||
|
@@ -32,8 +32,7 @@ var offsetRegexp *regexp.Regexp = regexp.MustCompile("(.*)\x1b\\[([0-9]+);([0-9]
|
||||
var offsetRegexpBegin *regexp.Regexp = regexp.MustCompile("^\x1b\\[[0-9]+;[0-9]+R")
|
||||
|
||||
func (r *LightRenderer) PassThrough(str string) {
|
||||
r.queued.WriteString(str)
|
||||
r.flush()
|
||||
r.queued.WriteString("\x1b7" + str + "\x1b8")
|
||||
}
|
||||
|
||||
func (r *LightRenderer) stderr(str string) {
|
||||
@@ -403,7 +402,7 @@ func (r *LightRenderer) escSequence(sz *int) Event {
|
||||
return Event{F3, 0, nil}
|
||||
case 'S':
|
||||
return Event{F4, 0, nil}
|
||||
case '1', '2', '3', '4', '5', '6':
|
||||
case '1', '2', '3', '4', '5', '6', '7', '8':
|
||||
if len(r.buffer) < 4 {
|
||||
return Event{Invalid, 0, nil}
|
||||
}
|
||||
@@ -454,6 +453,10 @@ func (r *LightRenderer) escSequence(sz *int) Event {
|
||||
return Event{PgUp, 0, nil}
|
||||
case '6':
|
||||
return Event{PgDn, 0, nil}
|
||||
case '7':
|
||||
return Event{Home, 0, nil}
|
||||
case '8':
|
||||
return Event{End, 0, nil}
|
||||
case '1':
|
||||
switch r.buffer[3] {
|
||||
case '~':
|
||||
@@ -721,6 +724,10 @@ func (r *LightRenderer) Close() {
|
||||
r.restoreTerminal()
|
||||
}
|
||||
|
||||
func (r *LightRenderer) Top() int {
|
||||
return r.yoffset
|
||||
}
|
||||
|
||||
func (r *LightRenderer) MaxX() int {
|
||||
return r.width
|
||||
}
|
||||
@@ -756,6 +763,10 @@ func (r *LightRenderer) NewWindow(top int, left int, width int, height int, prev
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *LightWindow) DrawBorder() {
|
||||
w.drawBorder(false)
|
||||
}
|
||||
|
||||
func (w *LightWindow) DrawHBorder() {
|
||||
w.drawBorder(true)
|
||||
}
|
||||
@@ -1088,14 +1099,21 @@ func (w *LightWindow) CFill(fg Color, bg Color, attr Attr, text string) FillRetu
|
||||
}
|
||||
|
||||
func (w *LightWindow) FinishFill() {
|
||||
w.MoveAndClear(w.posy, w.posx)
|
||||
if w.posy < w.height {
|
||||
w.MoveAndClear(w.posy, w.posx)
|
||||
}
|
||||
for y := w.posy + 1; y < w.height; y++ {
|
||||
w.MoveAndClear(y, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *LightWindow) Erase() {
|
||||
w.drawBorder(false)
|
||||
// We don't erase the window here to avoid flickering during scroll
|
||||
w.DrawBorder()
|
||||
w.Move(0, 0)
|
||||
w.FinishFill()
|
||||
w.Move(0, 0)
|
||||
}
|
||||
|
||||
func (w *LightWindow) EraseMaybe() bool {
|
||||
return false
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/junegunn/fzf/src/util"
|
||||
"golang.org/x/sys/unix"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
@@ -108,3 +109,11 @@ func (r *LightRenderer) getch(nonblock bool) (int, bool) {
|
||||
}
|
||||
return int(b[0]), true
|
||||
}
|
||||
|
||||
func (r *LightRenderer) Size() TermSize {
|
||||
ws, err := unix.IoctlGetWinsize(int(r.ttyin.Fd()), unix.TIOCGWINSZ)
|
||||
if err != nil {
|
||||
return TermSize{}
|
||||
}
|
||||
return TermSize{int(ws.Row), int(ws.Col), int(ws.Xpixel), int(ws.Ypixel)}
|
||||
}
|
||||
|
@@ -110,16 +110,24 @@ func (r *LightRenderer) restoreTerminal() error {
|
||||
return windows.SetConsoleMode(windows.Handle(r.outHandle), r.origStateOutput)
|
||||
}
|
||||
|
||||
func (r *LightRenderer) updateTerminalSize() {
|
||||
func (r *LightRenderer) Size() TermSize {
|
||||
var w, h int
|
||||
var bufferInfo windows.ConsoleScreenBufferInfo
|
||||
if err := windows.GetConsoleScreenBufferInfo(windows.Handle(r.outHandle), &bufferInfo); err != nil {
|
||||
r.width = getEnv("COLUMNS", defaultWidth)
|
||||
r.height = r.maxHeightFunc(getEnv("LINES", defaultHeight))
|
||||
w = getEnv("COLUMNS", defaultWidth)
|
||||
h = r.maxHeightFunc(getEnv("LINES", defaultHeight))
|
||||
|
||||
} else {
|
||||
r.width = int(bufferInfo.Window.Right - bufferInfo.Window.Left)
|
||||
r.height = r.maxHeightFunc(int(bufferInfo.Window.Bottom - bufferInfo.Window.Top))
|
||||
w = int(bufferInfo.Window.Right - bufferInfo.Window.Left)
|
||||
h = r.maxHeightFunc(int(bufferInfo.Window.Bottom - bufferInfo.Window.Top))
|
||||
}
|
||||
return TermSize{h, w, 0, 0}
|
||||
}
|
||||
|
||||
func (r *LightRenderer) updateTerminalSize() {
|
||||
size := r.Size()
|
||||
r.width = size.Columns
|
||||
r.height = size.Lines
|
||||
}
|
||||
|
||||
func (r *LightRenderer) findOffset() (row int, col int) {
|
||||
|
@@ -100,7 +100,7 @@ const (
|
||||
|
||||
func (r *FullscreenRenderer) PassThrough(str string) {
|
||||
// No-op
|
||||
// https://github.com/gdamore/tcell/issues/363#issuecomment-680665073
|
||||
// https://github.com/gdamore/tcell/pull/650#issuecomment-1806442846
|
||||
}
|
||||
|
||||
func (r *FullscreenRenderer) Resize(maxHeightFunc func(int) int) {}
|
||||
@@ -172,6 +172,10 @@ func (r *FullscreenRenderer) Init() {
|
||||
initTheme(r.theme, r.defaultTheme(), r.forceBlack)
|
||||
}
|
||||
|
||||
func (r *FullscreenRenderer) Top() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (r *FullscreenRenderer) MaxX() int {
|
||||
ncols, _ := _screen.Size()
|
||||
return int(ncols)
|
||||
@@ -203,6 +207,12 @@ func (r *FullscreenRenderer) Refresh() {
|
||||
// noop
|
||||
}
|
||||
|
||||
// TODO: Pixel width and height not implemented
|
||||
func (r *FullscreenRenderer) Size() TermSize {
|
||||
cols, lines := _screen.Size()
|
||||
return TermSize{lines, cols, 0, 0}
|
||||
}
|
||||
|
||||
func (r *FullscreenRenderer) GetChar() Event {
|
||||
ev := _screen.PollEvent()
|
||||
switch ev := ev.(type) {
|
||||
@@ -541,9 +551,15 @@ func fill(x, y, w, h int, n ColorPair, r rune) {
|
||||
}
|
||||
|
||||
func (w *TcellWindow) Erase() {
|
||||
w.drawBorder(false)
|
||||
fill(w.left-1, w.top, w.width+1, w.height-1, w.normal, ' ')
|
||||
}
|
||||
|
||||
func (w *TcellWindow) EraseMaybe() bool {
|
||||
w.Erase()
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *TcellWindow) Enclose(y int, x int) bool {
|
||||
return x >= w.left && x < (w.left+w.width) &&
|
||||
y >= w.top && y < (w.top+w.height)
|
||||
@@ -692,6 +708,10 @@ func (w *TcellWindow) CFill(fg Color, bg Color, a Attr, str string) FillReturn {
|
||||
return w.fillString(str, NewColorPair(fg, bg, a))
|
||||
}
|
||||
|
||||
func (w *TcellWindow) DrawBorder() {
|
||||
w.drawBorder(false)
|
||||
}
|
||||
|
||||
func (w *TcellWindow) DrawHBorder() {
|
||||
w.drawBorder(true)
|
||||
}
|
||||
|
@@ -473,6 +473,13 @@ func MakeTransparentBorder() BorderStyle {
|
||||
bottomRight: ' '}
|
||||
}
|
||||
|
||||
type TermSize struct {
|
||||
Lines int
|
||||
Columns int
|
||||
PxWidth int
|
||||
PxHeight int
|
||||
}
|
||||
|
||||
type Renderer interface {
|
||||
Init()
|
||||
Resize(maxHeightFunc func(int) int)
|
||||
@@ -487,9 +494,12 @@ type Renderer interface {
|
||||
|
||||
GetChar() Event
|
||||
|
||||
Top() int
|
||||
MaxX() int
|
||||
MaxY() int
|
||||
|
||||
Size() TermSize
|
||||
|
||||
NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window
|
||||
}
|
||||
|
||||
@@ -499,6 +509,7 @@ type Window interface {
|
||||
Width() int
|
||||
Height() int
|
||||
|
||||
DrawBorder()
|
||||
DrawHBorder()
|
||||
Refresh()
|
||||
FinishFill()
|
||||
@@ -515,6 +526,7 @@ type Window interface {
|
||||
Fill(text string) FillReturn
|
||||
CFill(fg Color, bg Color, attr Attr, text string) FillReturn
|
||||
Erase()
|
||||
EraseMaybe() bool
|
||||
}
|
||||
|
||||
type FullscreenRenderer struct {
|
||||
|
@@ -4,6 +4,7 @@ ba = "ba"
|
||||
fo = "fo"
|
||||
enew = "enew"
|
||||
tabe = "tabe"
|
||||
Iterm = "Iterm"
|
||||
|
||||
[files]
|
||||
extend-exclude = ["README.md"]
|
||||
|
Reference in New Issue
Block a user