mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-29 00:06:29 +00:00
parent
a3244c4892
commit
6a75e30941
@ -8,6 +8,8 @@ CHANGELOG
|
|||||||
- Added support for composite actions in `--bind`. Multiple actions can be
|
- Added support for composite actions in `--bind`. Multiple actions can be
|
||||||
chained using `+` separator.
|
chained using `+` separator.
|
||||||
- e.g. `fzf --bind 'ctrl-y:execute(echo -n {} | pbcopy)+abort'`
|
- e.g. `fzf --bind 'ctrl-y:execute(echo -n {} | pbcopy)+abort'`
|
||||||
|
- `--preview-window` with size 0 is allowed. This is used to make fzf execute
|
||||||
|
preview command in the background without displaying the result.
|
||||||
|
|
||||||
0.16.1
|
0.16.1
|
||||||
------
|
------
|
||||||
|
@ -278,6 +278,9 @@ Determine the layout of the preview window. If the argument ends with
|
|||||||
\fBtoggle-preview\fR action is triggered. Long lines are truncated by default.
|
\fBtoggle-preview\fR action is triggered. Long lines are truncated by default.
|
||||||
Line wrap can be enabled with \fB:wrap\fR flag.
|
Line wrap can be enabled with \fB:wrap\fR flag.
|
||||||
|
|
||||||
|
If size is given as 0, preview window will not be visible, but fzf will still
|
||||||
|
execute the command in the background.
|
||||||
|
|
||||||
.RS
|
.RS
|
||||||
.B POSITION: (default: right)
|
.B POSITION: (default: right)
|
||||||
\fBup
|
\fBup
|
||||||
|
@ -823,7 +823,7 @@ func parsePreviewWindow(opts *previewOpts, input string) {
|
|||||||
opts.wrap = false
|
opts.wrap = false
|
||||||
|
|
||||||
tokens := strings.Split(input, ":")
|
tokens := strings.Split(input, ":")
|
||||||
sizeRegex := regexp.MustCompile("^[1-9][0-9]*%?$")
|
sizeRegex := regexp.MustCompile("^[0-9]+%?$")
|
||||||
for _, token := range tokens {
|
for _, token := range tokens {
|
||||||
switch token {
|
switch token {
|
||||||
case "hidden":
|
case "hidden":
|
||||||
|
@ -509,9 +509,11 @@ func (t *Terminal) resizeWindows() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previewVisible := t.isPreviewEnabled() && t.preview.size.size > 0
|
||||||
minAreaWidth := minWidth
|
minAreaWidth := minWidth
|
||||||
minAreaHeight := minHeight
|
minAreaHeight := minHeight
|
||||||
if t.isPreviewEnabled() {
|
if previewVisible {
|
||||||
switch t.preview.position {
|
switch t.preview.position {
|
||||||
case posUp, posDown:
|
case posUp, posDown:
|
||||||
minAreaHeight *= 2
|
minAreaHeight *= 2
|
||||||
@ -531,7 +533,7 @@ func (t *Terminal) resizeWindows() {
|
|||||||
|
|
||||||
width := screenWidth - marginInt[1] - marginInt[3]
|
width := screenWidth - marginInt[1] - marginInt[3]
|
||||||
height := screenHeight - marginInt[0] - marginInt[2]
|
height := screenHeight - marginInt[0] - marginInt[2]
|
||||||
if t.isPreviewEnabled() {
|
if previewVisible {
|
||||||
createPreviewWindow := func(y int, x int, w int, h int) {
|
createPreviewWindow := func(y int, x int, w int, h int) {
|
||||||
t.bwindow = t.tui.NewWindow(y, x, w, h, true)
|
t.bwindow = t.tui.NewWindow(y, x, w, h, true)
|
||||||
pwidth := w - 4
|
pwidth := w - 4
|
||||||
@ -889,7 +891,7 @@ func numLinesMax(str string, max int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) printPreview() {
|
func (t *Terminal) printPreview() {
|
||||||
if !t.isPreviewEnabled() {
|
if !t.hasPreviewWindow() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.pwindow.Erase()
|
t.pwindow.Erase()
|
||||||
@ -974,7 +976,7 @@ func (t *Terminal) printAll() {
|
|||||||
|
|
||||||
func (t *Terminal) refresh() {
|
func (t *Terminal) refresh() {
|
||||||
if !t.suppress {
|
if !t.suppress {
|
||||||
if t.isPreviewEnabled() {
|
if t.hasPreviewWindow() {
|
||||||
t.tui.RefreshWindows([]tui.Window{t.bwindow, t.pwindow, t.window})
|
t.tui.RefreshWindows([]tui.Window{t.bwindow, t.pwindow, t.window})
|
||||||
} else {
|
} else {
|
||||||
t.tui.RefreshWindows([]tui.Window{t.window})
|
t.tui.RefreshWindows([]tui.Window{t.window})
|
||||||
@ -1107,12 +1109,16 @@ func (t *Terminal) executeCommand(template string, items []*Item) {
|
|||||||
t.refresh()
|
t.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) hasPreviewWindow() bool {
|
func (t *Terminal) hasPreviewer() bool {
|
||||||
return t.previewBox != nil
|
return t.previewBox != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) isPreviewEnabled() bool {
|
func (t *Terminal) isPreviewEnabled() bool {
|
||||||
return t.previewBox != nil && t.previewer.enabled
|
return t.hasPreviewer() && t.previewer.enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Terminal) hasPreviewWindow() bool {
|
||||||
|
return t.pwindow != nil && t.isPreviewEnabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) currentItem() *Item {
|
func (t *Terminal) currentItem() *Item {
|
||||||
@ -1174,7 +1180,7 @@ func (t *Terminal) Loop() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.hasPreviewWindow() {
|
if t.hasPreviewer() {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
var request *Item
|
var request *Item
|
||||||
@ -1358,7 +1364,7 @@ func (t *Terminal) Loop() {
|
|||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
return false
|
return false
|
||||||
case actTogglePreview:
|
case actTogglePreview:
|
||||||
if t.hasPreviewWindow() {
|
if t.hasPreviewer() {
|
||||||
t.previewer.enabled = !t.previewer.enabled
|
t.previewer.enabled = !t.previewer.enabled
|
||||||
t.tui.Clear()
|
t.tui.Clear()
|
||||||
t.resizeWindows()
|
t.resizeWindows()
|
||||||
@ -1374,19 +1380,19 @@ func (t *Terminal) Loop() {
|
|||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
return false
|
return false
|
||||||
case actPreviewUp:
|
case actPreviewUp:
|
||||||
if t.isPreviewEnabled() {
|
if t.hasPreviewWindow() {
|
||||||
scrollPreview(-1)
|
scrollPreview(-1)
|
||||||
}
|
}
|
||||||
case actPreviewDown:
|
case actPreviewDown:
|
||||||
if t.isPreviewEnabled() {
|
if t.hasPreviewWindow() {
|
||||||
scrollPreview(1)
|
scrollPreview(1)
|
||||||
}
|
}
|
||||||
case actPreviewPageUp:
|
case actPreviewPageUp:
|
||||||
if t.isPreviewEnabled() {
|
if t.hasPreviewWindow() {
|
||||||
scrollPreview(-t.pwindow.Height())
|
scrollPreview(-t.pwindow.Height())
|
||||||
}
|
}
|
||||||
case actPreviewPageDown:
|
case actPreviewPageDown:
|
||||||
if t.isPreviewEnabled() {
|
if t.hasPreviewWindow() {
|
||||||
scrollPreview(t.pwindow.Height())
|
scrollPreview(t.pwindow.Height())
|
||||||
}
|
}
|
||||||
case actBeginningOfLine:
|
case actBeginningOfLine:
|
||||||
@ -1563,7 +1569,7 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
t.vmove(me.S)
|
t.vmove(me.S)
|
||||||
req(reqList)
|
req(reqList)
|
||||||
} else if t.isPreviewEnabled() && t.pwindow.Enclose(my, mx) {
|
} else if t.hasPreviewWindow() && t.pwindow.Enclose(my, mx) {
|
||||||
scrollPreview(-me.S)
|
scrollPreview(-me.S)
|
||||||
}
|
}
|
||||||
} else if t.window.Enclose(my, mx) {
|
} else if t.window.Enclose(my, mx) {
|
||||||
|
@ -1224,6 +1224,19 @@ class TestGoFZF < TestBase
|
|||||||
tmux.send_keys '?'
|
tmux.send_keys '?'
|
||||||
tmux.until { |lines| lines[-1] == '> 555' }
|
tmux.until { |lines| lines[-1] == '> 555' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_preview_size_0
|
||||||
|
File.unlink tempname rescue nil
|
||||||
|
tmux.send_keys %[seq 100 | #{FZF} --reverse --preview 'echo {} >> #{tempname}; echo ' --preview-window 0], :Enter
|
||||||
|
tmux.until { |lines| lines.item_count == 100 && lines[1] == ' 100/100' && lines[2] == '> 1' }
|
||||||
|
tmux.until { |_| %w[1] == File.readlines(tempname).map(&:chomp) }
|
||||||
|
tmux.send_keys :Down
|
||||||
|
tmux.until { |lines| lines[3] == '> 2' }
|
||||||
|
tmux.until { |_| %w[1 2] == File.readlines(tempname).map(&:chomp) }
|
||||||
|
tmux.send_keys :Down
|
||||||
|
tmux.until { |lines| lines[4] == '> 3' }
|
||||||
|
tmux.until { |_| %w[1 2 3] == File.readlines(tempname).map(&:chomp) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module TestShell
|
module TestShell
|
||||||
|
Loading…
Reference in New Issue
Block a user