Allow empty pointer and marker
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #3879
authored by Junegunn Choi · committed by Junegunn Choi · parent 27d1f5e · Browse files · 4 files·+58 added−21 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+58 added−21 removed
- tests:+16 added−0 removed
- other:+42 added−21 removed
Provenance
- Commit
c3cc378- Tree
fcede8a- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
27d1f5e
4 files changed+58 added−21 removed
modified:src/options.go+32 added-20 removed
448 unmodified lines449 JumpLabels string450 Prompt string451 Pointer *string452 Marker *string453- MarkerMulti [3]string453+ MarkerMulti *[3]string454 Query string455 Select1 bool456 Exit0 bool457 Filter *string96 unmodified lines554 JumpLabels: defaultJumpLabels,555 Prompt: "> ",556 Pointer: nil,557 Marker: nil,558+ MarkerMulti: nil,559 Query: "",560 Select1: false,561 Exit0: false,562 Filter: nil,1299 unmodified lines1862 }1863 return [4]sizeSpec{}, errors.New("invalid " + opt + ": " + margin)1864 }1865 1865-func parseMarkerMultiLine(str string) ([3]string, error) {1866+func parseMarkerMultiLine(str string) (*[3]string, error) {1867+ if str == "" {1868+ return &[3]string{}, nil1869+ }1870 gr := uniseg.NewGraphemes(str)1871 parts := []string{}1872 totalWidth := 01873 for gr.Next() {3 unmodified lines1877 }1878 1879 result := [3]string{}1880 if totalWidth != 3 && totalWidth != 6 {1877- return result, fmt.Errorf("invalid total marker width: %d (expected: 3 or 6)", totalWidth)1881+ return &result, fmt.Errorf("invalid total marker width: %d (expected: 0, 3 or 6)", totalWidth)1882 }1883 1884 expected := totalWidth / 31885 idx := 07 unmodified lines1893 if idx == 3 {1894 break1895 }1896 }1893- return result, nil1897+ return &result, nil1898 }1899 1900 func parseOptions(index *int, opts *Options, allArgs []string) error {1901 var err error800 unmodified lines2702 return err2703 }2704 2705 func validateSign(sign string, signOptName string) error {2702- if sign == "" {2703- return fmt.Errorf("%v cannot be empty", signOptName)2704- }2706 if uniseg.StringWidth(sign) > 2 {2707 return fmt.Errorf("%v display width should be up to 2", signOptName)2708 }2709 return nil58 unmodified lines2768 }2769 opts.Pointer = &defaultPointer2770 }2771 2772+ multiLine := opts.MultiLine && opts.ReadZero2773 markerLen := 12774 if opts.Marker == nil {2775+ if multiLine && opts.MarkerMulti != nil && opts.MarkerMulti[0] == "" {2776+ empty := ""2777+ opts.Marker = &empty2778+ markerLen = 02779+ } else {2773- // "▎" looks better, but not all terminals render it correctly2774- defaultMarker := "┃"2775- if !opts.Unicode {2776- defaultMarker = ">"2780+ // "▎" looks better, but not all terminals render it correctly2781+ defaultMarker := "┃"2782+ if !opts.Unicode {2783+ defaultMarker = ">"2784+ }2785+ opts.Marker = &defaultMarker2786 }2778- opts.Marker = &defaultMarker2787 } else {2788 markerLen = uniseg.StringWidth(*opts.Marker)2789 }2790 2791 markerMultiLen := 12784- if len(opts.MarkerMulti[0]) == 0 {2785- if opts.Unicode {2786- opts.MarkerMulti = [3]string{"╻", "┃", "╹"}2792+ if opts.MarkerMulti == nil {2793+ if !multiLine && *opts.Marker == "" {2794+ opts.MarkerMulti = &[3]string{}2795+ markerMultiLen = 02796+ } else if opts.Unicode {2797+ opts.MarkerMulti = &[3]string{"╻", "┃", "╹"}2798 } else {2788- opts.MarkerMulti = [3]string{".", "|", "'"}2799+ opts.MarkerMulti = &[3]string{".", "|", "'"}2800 }2801 } else {2802 markerMultiLen = uniseg.StringWidth(opts.MarkerMulti[0])2803 }2793- if markerMultiLen > markerLen {2794- padded := *opts.Marker + " "2804+ diff := markerMultiLen - markerLen2805+ if diff > 0 {2806+ padded := *opts.Marker + strings.Repeat(" ", diff)2807 opts.Marker = &padded2796- } else if markerMultiLen < markerLen {2808+ } else if diff < 0 {2809 for idx := range opts.MarkerMulti {2798- opts.MarkerMulti[idx] += " "2810+ opts.MarkerMulti[idx] += strings.Repeat(" ", -diff)2811 }2812 }2813 2814 // Default actions for CTRL-N / CTRL-P when --history is set133 unmodified linesmodified:src/terminal.go+1 added-1 removed
769 unmodified lines770 pointer: *opts.Pointer,771 pointerLen: uniseg.StringWidth(*opts.Pointer),772 marker: *opts.Marker,773 markerLen: uniseg.StringWidth(*opts.Marker),774- markerMultiLine: opts.MarkerMulti,774+ markerMultiLine: *opts.MarkerMulti,775 wordRubout: wordRubout,776 wordNext: wordNext,777 cx: len(input),778 cy: 0,4101 unmodified linesmodified:test/test_go.rb+16 added
3338 unmodified lines3339 │ ┃33340 BLOCK3341 tmux.until { assert_block(block, _1) }3342 end3343+3344+ def test_fzf_multi_line_no_pointer_and_marker3345+ tmux.send_keys %[(echo -en '0\\0'; echo -en '1\\n2\\0'; seq 1000) | fzf --read0 --multi --bind load:select-all --border rounded --reverse --pointer '' --marker '' --marker-multi-line ''], :Enter3346+ block = <<~BLOCK3347+ ╭───────────3348+ │ >3349+ │ 3/3 (3)3350+ │ 03351+ │ 13352+ │ 23353+ │ 13354+ │ 23355+ │ 33356+ BLOCK3357+ tmux.until { assert_block(block, _1) }3358+ end3359 end3360 3361 module TestShell3362 def setup520 unmodified linesmodified:CHANGELOG.md+9 added
8 unmodified lines9 fzf --info-command='echo -e "\x1b[33;1m$FZF_POS\x1b[m/$FZF_INFO 💛"'10 ```11 - `$FZF_INFO` is set to the original info text12 - ANSI color codes are supported13+- Pointer and marker signs can be set to empty strings14+ ```sh15+ # Minimal style16+ fzf --pointer '' --marker '' --info hidden17+18+ # When --read0 is specified, there can be multi-line entries,19+ # so you need to set --marker-multi-line to an empty string20+ find . -print0 | fzf --read0 --pointer '' --marker-multi-line '' --info hidden21+ ```22 - Better cache management and improved rendering for `--tail`23 - Improved `--sync` behavior24 - When `--sync` is provided, fzf will not render the interface until the initial filtering and the associated actions (bound to any of `start`, `load`, `result`, or `focus`) are complete.25 ```sh2163 unmodified lines