From 3b944addd47d7a911408a14b421c92d69a3f1eb3 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 25 Jun 2024 17:10:22 +0900 Subject: [PATCH] Allow removing header line with change-header and transform-header If the new header is an empty string. fzf --header loading --bind 'start:reload:sleep 3; ls' --bind 'load:change-header:' fzf --header loading --bind 'start:reload:sleep 3; ls' --bind 'load:transform-header:' --- src/terminal.go | 20 ++++++++++---------- test/test_go.rb | 4 +++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/terminal.go b/src/terminal.go index d94e54ec..6cc46128 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -1202,7 +1202,10 @@ func (t *Terminal) UpdateCount(cnt int, final bool, failedCommand *string) { } func (t *Terminal) changeHeader(header string) bool { - lines := strings.Split(strings.TrimSuffix(header, "\n"), "\n") + var lines []string + if len(header) > 0 { + lines = strings.Split(strings.TrimSuffix(header, "\n"), "\n") + } needFullRedraw := len(t.header0) != len(lines) t.header0 = lines return needFullRedraw @@ -4094,16 +4097,13 @@ func (t *Terminal) Loop() error { case actChangeQuery: t.input = []rune(a.a) t.cx = len(t.input) - case actTransformHeader: - header := t.executeCommand(a.a, false, true, true, false, "") - if t.changeHeader(header) { - req(reqFullRedraw) - } else { - req(reqHeader) + case actChangeHeader, actTransformHeader: + header := a.a + if a.t == actTransformHeader { + header = t.executeCommand(a.a, false, true, true, false, "") } - case actChangeHeader: - if t.changeHeader(a.a) { - req(reqFullRedraw) + if t.changeHeader(header) { + req(reqHeader, reqList, reqPrompt, reqInfo) } else { req(reqHeader) } diff --git a/test/test_go.rb b/test/test_go.rb index c6db562a..3b5eb4ee 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -3358,11 +3358,13 @@ class TestGoFZF < TestBase end def test_start_on_reload - tmux.send_keys %(echo foo | #{FZF} --header Loading --header-lines 1 --bind 'start:reload:sleep 2; echo bar' --bind 'load:change-header:Loaded'), :Enter + tmux.send_keys %(echo foo | #{FZF} --header Loading --header-lines 1 --bind 'start:reload:sleep 2; echo bar' --bind 'load:change-header:Loaded' --bind space:change-header:), :Enter tmux.until(timeout: 1) { |lines| assert_includes lines[-3], 'Loading' } tmux.until(timeout: 1) { |lines| refute_includes lines[-4], 'foo' } tmux.until { |lines| assert_includes lines[-3], 'Loaded' } tmux.until { |lines| assert_includes lines[-4], 'bar' } + tmux.send_keys :Space + tmux.until { |lines| assert_includes lines[-3], 'bar' } end end