summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-06-20 01:45:06 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2024-06-20 01:45:06 +0900
commitc3cc378d8919da13dea3094e23d9bcfc12226ad8 (patch)
treefcede8ad51b0769174503d5451c00325662f3578 /src
parent27d1f5e0a8c73bc79694157f132247c2e69c2a71 (diff)
downloadfzf-c3cc378d8919da13dea3094e23d9bcfc12226ad8.tar.gz
Allow empty pointer and marker
Close #3879
Diffstat (limited to 'src')
-rw-r--r--src/options.go52
-rw-r--r--src/terminal.go2
2 files changed, 33 insertions, 21 deletions
diff --git a/src/options.go b/src/options.go
index 31f32b3d..fdf5f8dd 100644
--- a/src/options.go
+++ b/src/options.go
@@ -450,7 +450,7 @@ type Options struct {
Prompt string
Pointer *string
Marker *string
- MarkerMulti [3]string
+ MarkerMulti *[3]string
Query string
Select1 bool
Exit0 bool
@@ -555,6 +555,7 @@ func defaultOptions() *Options {
Prompt: "> ",
Pointer: nil,
Marker: nil,
+ MarkerMulti: nil,
Query: "",
Select1: false,
Exit0: false,
@@ -1862,7 +1863,10 @@ func parseMargin(opt string, margin string) ([4]sizeSpec, error) {
return [4]sizeSpec{}, errors.New("invalid " + opt + ": " + margin)
}
-func parseMarkerMultiLine(str string) ([3]string, error) {
+func parseMarkerMultiLine(str string) (*[3]string, error) {
+ if str == "" {
+ return &[3]string{}, nil
+ }
gr := uniseg.NewGraphemes(str)
parts := []string{}
totalWidth := 0
@@ -1874,7 +1878,7 @@ func parseMarkerMultiLine(str string) ([3]string, error) {
result := [3]string{}
if totalWidth != 3 && totalWidth != 6 {
- return result, fmt.Errorf("invalid total marker width: %d (expected: 3 or 6)", totalWidth)
+ return &result, fmt.Errorf("invalid total marker width: %d (expected: 0, 3 or 6)", totalWidth)
}
expected := totalWidth / 3
@@ -1890,7 +1894,7 @@ func parseMarkerMultiLine(str string) ([3]string, error) {
break
}
}
- return result, nil
+ return &result, nil
}
func parseOptions(index *int, opts *Options, allArgs []string) error {
@@ -2699,9 +2703,6 @@ func parseOptions(index *int, opts *Options, allArgs []string) error {
}
func validateSign(sign string, signOptName string) error {
- if sign == "" {
- return fmt.Errorf("%v cannot be empty", signOptName)
- }
if uniseg.StringWidth(sign) > 2 {
return fmt.Errorf("%v display width should be up to 2", signOptName)
}
@@ -2768,34 +2769,45 @@ func postProcessOptions(opts *Options) error {
opts.Pointer = &defaultPointer
}
+ multiLine := opts.MultiLine && opts.ReadZero
markerLen := 1
if opts.Marker == nil {
- // "▎" looks better, but not all terminals render it correctly
- defaultMarker := "┃"
- if !opts.Unicode {
- defaultMarker = ">"
+ if multiLine && opts.MarkerMulti != nil && opts.MarkerMulti[0] == "" {
+ empty := ""
+ opts.Marker = &empty
+ markerLen = 0
+ } else {
+ // "▎" looks better, but not all terminals render it correctly
+ defaultMarker := "┃"
+ if !opts.Unicode {
+ defaultMarker = ">"
+ }
+ opts.Marker = &defaultMarker
}
- opts.Marker = &defaultMarker
} else {
markerLen = uniseg.StringWidth(*opts.Marker)
}
markerMultiLen := 1
- if len(opts.MarkerMulti[0]) == 0 {
- if opts.Unicode {
- opts.MarkerMulti = [3]string{"╻", "┃", "╹"}
+ if opts.MarkerMulti == nil {
+ if !multiLine && *opts.Marker == "" {
+ opts.MarkerMulti = &[3]string{}
+ markerMultiLen = 0
+ } else if opts.Unicode {
+ opts.MarkerMulti = &[3]string{"╻", "┃", "╹"}
} else {
- opts.MarkerMulti = [3]string{".", "|", "'"}
+ opts.MarkerMulti = &[3]string{".", "|", "'"}
}
} else {
markerMultiLen = uniseg.StringWidth(opts.MarkerMulti[0])
}
- if markerMultiLen > markerLen {
- padded := *opts.Marker + " "
+ diff := markerMultiLen - markerLen
+ if diff > 0 {
+ padded := *opts.Marker + strings.Repeat(" ", diff)
opts.Marker = &padded
- } else if markerMultiLen < markerLen {
+ } else if diff < 0 {
for idx := range opts.MarkerMulti {
- opts.MarkerMulti[idx] += " "
+ opts.MarkerMulti[idx] += strings.Repeat(" ", -diff)
}
}
diff --git a/src/terminal.go b/src/terminal.go
index 480fb31c..f131f1db 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -771,7 +771,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
pointerLen: uniseg.StringWidth(*opts.Pointer),
marker: *opts.Marker,
markerLen: uniseg.StringWidth(*opts.Marker),
- markerMultiLine: opts.MarkerMulti,
+ markerMultiLine: *opts.MarkerMulti,
wordRubout: wordRubout,
wordNext: wordNext,
cx: len(input),