mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2025-01-11 02:36:12 +00:00
Export FZF_PREVIEW_LINES and FZF_PREVIEW_COLUMNS to preview process
fzf will still override LINES and COLUMNS as before but they may not hold the correct values depending on the default shell. Close #1314
This commit is contained in:
parent
6c32148f90
commit
8dc1377efb
@ -288,8 +288,11 @@ EXPRESSION\fR for the details).
|
|||||||
e.g. \fBfzf --preview='head -$LINES {}'\fR
|
e.g. \fBfzf --preview='head -$LINES {}'\fR
|
||||||
\fBls -l | fzf --preview="echo user={3} when={-4..-2}; cat {-1}" --header-lines=1\fR
|
\fBls -l | fzf --preview="echo user={3} when={-4..-2}; cat {-1}" --header-lines=1\fR
|
||||||
|
|
||||||
fzf overrides \fB$LINES\fR and \fB$COLUMNS\fR so that they represent the exact
|
fzf exports \fB$FZF_PREVIEW_LINES\fR and \fB$FZF_PREVIEW_COLUMNS\fR so that
|
||||||
size of the preview window.
|
they represent the exact size of the preview window. (It also overrides
|
||||||
|
\fB$LINES\fR and \fB$COLUMNS\fR with the same values but they can be reset
|
||||||
|
by the default shell, so prefer to refer to the ones with \fBFZF_PREVIEW_\fR
|
||||||
|
prefix.)
|
||||||
|
|
||||||
A placeholder expression starting with \fB+\fR flag will be replaced to the
|
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
|
space-separated list of the selected lines (or the current line if no selection
|
||||||
|
@ -613,7 +613,6 @@ func (t *Terminal) resizeWindows() {
|
|||||||
pwidth += 1
|
pwidth += 1
|
||||||
}
|
}
|
||||||
t.pwindow = t.tui.NewWindow(y+1, x+2, pwidth, h-2, tui.BorderNone)
|
t.pwindow = t.tui.NewWindow(y+1, x+2, pwidth, h-2, tui.BorderNone)
|
||||||
os.Setenv("FZF_PREVIEW_HEIGHT", strconv.Itoa(h-2))
|
|
||||||
}
|
}
|
||||||
switch t.preview.position {
|
switch t.preview.position {
|
||||||
case posUp:
|
case posUp:
|
||||||
@ -1492,8 +1491,12 @@ func (t *Terminal) Loop() {
|
|||||||
cmd := util.ExecCommand(command, true)
|
cmd := util.ExecCommand(command, true)
|
||||||
if t.pwindow != nil {
|
if t.pwindow != nil {
|
||||||
env := os.Environ()
|
env := os.Environ()
|
||||||
env = append(env, fmt.Sprintf("LINES=%d", t.pwindow.Height()))
|
lines := fmt.Sprintf("LINES=%d", t.pwindow.Height())
|
||||||
env = append(env, fmt.Sprintf("COLUMNS=%d", t.pwindow.Width()))
|
columns := fmt.Sprintf("COLUMNS=%d", t.pwindow.Width())
|
||||||
|
env = append(env, lines)
|
||||||
|
env = append(env, "FZF_PREVIEW_"+lines)
|
||||||
|
env = append(env, columns)
|
||||||
|
env = append(env, "FZF_PREVIEW_"+columns)
|
||||||
cmd.Env = env
|
cmd.Env = env
|
||||||
}
|
}
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
|
@ -1371,7 +1371,7 @@ class TestGoFZF < TestBase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_preview_hidden
|
def test_preview_hidden
|
||||||
tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}-\\$LINES-\\$COLUMNS}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter
|
tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}-\\$FZF_PREVIEW_LINES-\\$FZF_PREVIEW_COLUMNS}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter
|
||||||
tmux.until { |lines| lines[-1] == '>' }
|
tmux.until { |lines| lines[-1] == '>' }
|
||||||
tmux.send_keys '?'
|
tmux.send_keys '?'
|
||||||
tmux.until { |lines| lines[-2] =~ / {1-1-1-[0-9]+}/ }
|
tmux.until { |lines| lines[-2] =~ / {1-1-1-[0-9]+}/ }
|
||||||
|
Loading…
Reference in New Issue
Block a user