Skip to content
Myr

Sanitize input strings that should be a single line

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 618d317 · Browse files · 2 files+10 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−4 removed

  • other:+10 added−4 removed

2 files+10 added−4 removed

modified:src/options.go+8 added-4 removed
246 unmodified lines
247func (a previewOpts) sameContentLayout(b previewOpts) bool {248 return a.wrap == b.wrap && a.headerLines == b.headerLines249}250251func firstLine(s string) string {252 return strings.SplitN(s, "\n", 2)[0]253}254255// Options stores the values of command-line options256type Options struct {257 Fuzzy bool258 FuzzyAlgo algo.Algo
1402 unmodified lines
1661 opts.PrintQuery = false1662 case "--prompt":1663 opts.Prompt = nextString(allArgs, &i, "prompt string required")1664 case "--pointer":1661 opts.Pointer = nextString(allArgs, &i, "pointer sign string required")1665 opts.Pointer = firstLine(nextString(allArgs, &i, "pointer sign string required"))1666 validatePointer = true1667 case "--marker":1664 opts.Marker = nextString(allArgs, &i, "selected sign string required")1668 opts.Marker = firstLine(nextString(allArgs, &i, "selected sign string required"))1669 validateMarker = true1670 case "--sync":1671 opts.Sync = true1672 case "--no-sync":
106 unmodified lines
1779 parseLabelPosition(&opts.PreviewLabel, value)1780 } else if match, value := optString(arg, "--prompt="); match {1781 opts.Prompt = value1782 } else if match, value := optString(arg, "--pointer="); match {1779 opts.Pointer = value1783 opts.Pointer = firstLine(value)1784 validatePointer = true1785 } else if match, value := optString(arg, "--marker="); match {1782 opts.Marker = value1786 opts.Marker = firstLine(value)1787 validateMarker = true1788 } else if match, value := optString(arg, "-n", "--nth="); match {1789 opts.Nth = splitNth(value)1790 } else if match, value := optString(arg, "--with-nth="); match {
253 unmodified lines
modified:src/terminal.go+2 added
729 unmodified lines
730 return nil, 0731 }732733 // Extract ANSI color codes734 str = firstLine(str)735 text, colors, _ := extractColor(str, nil, nil)736 runes := []rune(text)737738 // Simpler printer for strings without ANSI colors or tab characters
46 unmodified lines
785}786787func (t *Terminal) parsePrompt(prompt string) (func(), int) {788 var state *ansiState789 prompt = firstLine(prompt)790 trimmed, colors, _ := extractColor(prompt, state, nil)791 item := &Item{text: util.ToChars([]byte(trimmed)), colors: colors}792793 // "Prompt> "
2775 unmodified lines