From 818d0be436a9a580561f793424b7780c3584c59c Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 7 Feb 2025 20:56:15 +0900 Subject: [PATCH] Fix change-header-label+change-header Fix #4227 --- src/terminal.go | 87 ++++++++++++++++++--------------------------- test/test_layout.rb | 13 +++++++ 2 files changed, 48 insertions(+), 52 deletions(-) diff --git a/src/terminal.go b/src/terminal.go index 4e2474ac..b1b5251d 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -5043,34 +5043,52 @@ func (t *Terminal) Loop() error { } else { req(reqHeader) } - case actChangeHeaderLabel: - t.headerLabelOpts.label = a.a - if t.headerBorder != nil { - t.headerLabel, t.headerLabelLen = t.ansiLabelPrinter(a.a, &tui.ColHeaderLabel, false) - req(reqRedrawHeaderLabel) + case actChangeHeaderLabel, actTransformHeaderLabel: + label := a.a + if a.t == actTransformHeaderLabel { + label = t.captureLine(a.a) } - case actChangeInputLabel: - t.inputLabelOpts.label = a.a + t.headerLabelOpts.label = label + t.headerLabel, t.headerLabelLen = t.ansiLabelPrinter(label, &tui.ColHeaderLabel, false) + req(reqRedrawHeaderLabel) + case actChangeInputLabel, actTransformInputLabel: + label := a.a + if a.t == actTransformInputLabel { + label = t.captureLine(a.a) + } + t.inputLabelOpts.label = label if t.inputBorder != nil { - t.inputLabel, t.inputLabelLen = t.ansiLabelPrinter(a.a, &tui.ColInputLabel, false) + t.inputLabel, t.inputLabelLen = t.ansiLabelPrinter(label, &tui.ColInputLabel, false) req(reqRedrawInputLabel) } - case actChangeListLabel: - t.listLabelOpts.label = a.a + case actChangeListLabel, actTransformListLabel: + label := a.a + if a.t == actTransformListLabel { + label = t.captureLine(a.a) + } + t.listLabelOpts.label = label if t.wborder != nil { - t.listLabel, t.listLabelLen = t.ansiLabelPrinter(a.a, &tui.ColListLabel, false) + t.listLabel, t.listLabelLen = t.ansiLabelPrinter(label, &tui.ColListLabel, false) req(reqRedrawListLabel) } - case actChangeBorderLabel: - t.borderLabelOpts.label = a.a + case actChangeBorderLabel, actTransformBorderLabel: + label := a.a + if a.t == actTransformBorderLabel { + label = t.captureLine(a.a) + } + t.borderLabelOpts.label = label if t.border != nil { - t.borderLabel, t.borderLabelLen = t.ansiLabelPrinter(a.a, &tui.ColBorderLabel, false) + t.borderLabel, t.borderLabelLen = t.ansiLabelPrinter(label, &tui.ColBorderLabel, false) req(reqRedrawBorderLabel) } - case actChangePreviewLabel: - t.previewLabelOpts.label = a.a + case actChangePreviewLabel, actTransformPreviewLabel: + label := a.a + if a.t == actTransformPreviewLabel { + label = t.captureLine(a.a) + } + t.previewLabelOpts.label = label if t.pborder != nil { - t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(a.a, &tui.ColPreviewLabel, false) + t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(label, &tui.ColPreviewLabel, false) req(reqRedrawPreviewLabel) } case actTransform: @@ -5078,41 +5096,6 @@ func (t *Terminal) Loop() error { if actions, err := parseSingleActionList(strings.Trim(body, "\r\n")); err == nil { return doActions(actions) } - case actTransformHeaderLabel: - label := t.captureLine(a.a) - t.headerLabelOpts.label = label - if t.headerBorder != nil { - t.headerLabel, t.headerLabelLen = t.ansiLabelPrinter(label, &tui.ColHeaderLabel, false) - req(reqRedrawHeaderLabel) - } - case actTransformInputLabel: - label := t.captureLine(a.a) - t.inputLabelOpts.label = label - if t.inputBorder != nil { - t.inputLabel, t.inputLabelLen = t.ansiLabelPrinter(label, &tui.ColInputLabel, false) - req(reqRedrawInputLabel) - } - case actTransformListLabel: - label := t.captureLine(a.a) - t.listLabelOpts.label = label - if t.wborder != nil { - t.listLabel, t.listLabelLen = t.ansiLabelPrinter(label, &tui.ColListLabel, false) - req(reqRedrawListLabel) - } - case actTransformBorderLabel: - label := t.captureLine(a.a) - t.borderLabelOpts.label = label - if t.border != nil { - t.borderLabel, t.borderLabelLen = t.ansiLabelPrinter(label, &tui.ColBorderLabel, false) - req(reqRedrawBorderLabel) - } - case actTransformPreviewLabel: - label := t.captureLine(a.a) - t.previewLabelOpts.label = label - if t.pborder != nil { - t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(label, &tui.ColPreviewLabel, false) - req(reqRedrawPreviewLabel) - } case actChangePrompt: t.promptString = a.a t.prompt, t.promptLen = t.parsePrompt(a.a) diff --git a/test/test_layout.rb b/test/test_layout.rb index 97f8da6e..401f0f35 100644 --- a/test/test_layout.rb +++ b/test/test_layout.rb @@ -978,4 +978,17 @@ class TestLayout < TestInteractive setup end end + + def test_change_header_and_label_at_once + tmux.send_keys %(seq 10 | #{FZF} --border sharp --header-border sharp --header-label-pos 3 --bind 'focus:change-header(header)+change-header-label(label)'), :Enter + block = <<~BLOCK + │ ┌─label── + │ │ header + │ └──────── + │ 10/10 ─ + │ > + └────────── + BLOCK + tmux.until { assert_block(block, it) } + end end