Skip to content
Myr

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

4 files+58 added−21 removed

modified:src/options.go+32 added-20 removed
448 unmodified lines
449 JumpLabels string450 Prompt string451 Pointer *string452 Marker *string453 MarkerMulti [3]string453 MarkerMulti *[3]string454 Query string455 Select1 bool456 Exit0 bool457 Filter *string
96 unmodified lines
554 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 lines
1862 }1863 return [4]sizeSpec{}, errors.New("invalid " + opt + ": " + margin)1864}18651865func parseMarkerMultiLine(str string) ([3]string, error) {1866func 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 lines
1877 }18781879 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 }18831884 expected := totalWidth / 31885 idx := 0
7 unmodified lines
1893 if idx == 3 {1894 break1895 }1896 }1893 return result, nil1897 return &result, nil1898}18991900func parseOptions(index *int, opts *Options, allArgs []string) error {1901 var err error
800 unmodified lines
2702 return err2703}27042705func 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 nil
58 unmodified lines
2768 }2769 opts.Pointer = &defaultPointer2770 }27712772 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 }27902791 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 }28132814 // Default actions for CTRL-N / CTRL-P when --history is set
133 unmodified lines
modified:src/terminal.go+1 added-1 removed
769 unmodified lines
770 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 lines
modified:test/test_go.rb+16 added
3338 unmodified lines
3339 │ ┃33340 BLOCK3341 tmux.until { assert_block(block, _1) }3342 end33433344 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 end3359end33603361module TestShell3362 def setup
520 unmodified lines
modified:CHANGELOG.md+9 added
8 unmodified lines
9 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 hidden1718 # 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 ```sh
2163 unmodified lines