Add --preview-wrap-sign
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 0ecbf3f · Browse files · 6 files·+269 added−202 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+269 added−202 removed
- other:+269 added−202 removed
Provenance
- Commit
4a195e6- Tree
cc3f4a4- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
0ecbf3f
6 files changed+269 added−202 removed
modified:man/man1/fzf.1+5 added
918 unmodified lines919 .B * border\-bottom920 .br921 922 .TP923+.BI "\-\-preview\-wrap\-sign" =INDICATOR924+Indicator for wrapped lines in the preview window. If not set, the value of925+\fB\-\-wrap\-sign\fR is used.926+927+.TP928 .BI "\-\-preview\-label\-pos" [=N[:top|bottom]]929 Position of the border label on the border line of the preview window. Specify930 a positive integer as the column position from the left. Specify a negative931 integer to right-align the label. Label is printed on the top border line by1273 unmodified linesmodified:shell/completion.bash+1 added
217 unmodified lines218 --with-nth219 --with-shell220 --wrap221 --wrap-sign222+ --preview-wrap-sign223 --zsh224 -0 --exit-0225 -1 --select-1226 -d --delimiter512 unmodified linesmodified:src/options_test.go+44 added
462 unmodified lines463 t.Errorf("wrap-word,wrap: wrap=%v, wrapWord=%v", opts.Preview.wrap, opts.Preview.wrapWord)464 }465 }466 467+func TestPreviewWrapSign(t *testing.T) {468+ // Default: no preview wrap sign override469+ opts := optsFor()470+ if opts.PreviewWrapSign != nil {471+ t.Errorf("expected nil PreviewWrapSign, got %v", *opts.PreviewWrapSign)472+ }473+474+ // --preview-wrap-sign sets PreviewWrapSign475+ opts = optsFor("--preview-wrap-sign", ">> ")476+ if opts.PreviewWrapSign == nil || *opts.PreviewWrapSign != ">> " {477+ t.Errorf("expected '>> ', got %v", opts.PreviewWrapSign)478+ }479+480+ // --preview-wrap-sign is independent of --wrap-sign481+ opts = optsFor("--wrap-sign", "| ", "--preview-wrap-sign", ">> ")482+ if opts.WrapSign == nil || *opts.WrapSign != "| " {483+ t.Errorf("expected WrapSign '| ', got %v", opts.WrapSign)484+ }485+ if opts.PreviewWrapSign == nil || *opts.PreviewWrapSign != ">> " {486+ t.Errorf("expected PreviewWrapSign '>> ', got %v", opts.PreviewWrapSign)487+ }488+489+ // --preview-wrap-sign without --wrap-sign490+ opts = optsFor("--preview-wrap-sign", "→ ")491+ if opts.WrapSign != nil {492+ t.Errorf("expected nil WrapSign, got %v", *opts.WrapSign)493+ }494+ if opts.PreviewWrapSign == nil || *opts.PreviewWrapSign != "→ " {495+ t.Errorf("expected PreviewWrapSign '→ ', got %v", opts.PreviewWrapSign)496+ }497+498+ // Last --preview-wrap-sign wins499+ opts = optsFor("--preview-wrap-sign", "A ", "--preview-wrap-sign", "B ")500+ if opts.PreviewWrapSign == nil || *opts.PreviewWrapSign != "B " {501+ t.Errorf("expected PreviewWrapSign 'B ', got %v", opts.PreviewWrapSign)502+ }503+504+ // Empty string is allowed505+ opts = optsFor("--preview-wrap-sign", "")506+ if opts.PreviewWrapSign == nil || *opts.PreviewWrapSign != "" {507+ t.Errorf("expected empty PreviewWrapSign, got %v", opts.PreviewWrapSign)508+ }509+}510+511 func TestAdditiveExpect(t *testing.T) {512 opts := optsFor("--expect=a", "--expect", "b", "--expect=c")513 if len(opts.Expect) != 3 {514 t.Error(opts.Expect)57 unmodified linesmodified:src/options.go+8 added
165 unmodified lines166 top|bottom|left|right|line|none] (default: rounded)167 --preview-label=LABEL168 --preview-label-pos=N Same as --border-label and --border-label-pos,169 but for preview window170+ --preview-wrap-sign=STR Indicator for wrapped lines in the preview window171 172 HEADER173 --header=STR String to print as header174 --header-lines=N The first N lines of the input are treated as header433 unmodified lines608 Cycle bool609 Wrap bool610 WrapWord bool611 WrapSign *string612+ PreviewWrapSign *string613 MultiLine bool614 CursorLine bool615 KeepRight bool616 Hscroll bool2497 unmodified lines3114 hasArg, arg := optionalNextString()3115 if opts.Preview.border, err = parseBorder(arg, !hasArg); err != nil {3116 return err3117 }3118+ case "--preview-wrap-sign":3119+ str, err := nextString("preview wrap sign required")3120+ if err != nil {3121+ return err3122+ }3123+ opts.PreviewWrapSign = &str3124 case "--height":3125 str, err := nextString("height required: [~]HEIGHT[%]")3126 if err != nil {3127 return err756 unmodified linesmodified:src/terminal.go+209 added-202 removed
243 unmodified lines244 }245 246 // Terminal represents terminal input/output247 type Terminal struct {248+ initDelay time.Duration249+ infoCommand string248- initDelay time.Duration249- infoCommand string250- infoStyle infoStyle251- infoPrefix string252- wrap bool253- wrapWord bool254- wrapSign string255- wrapSignWidth int256- ghost string257- separator labelPrinter258- separatorLen int259- spinner []string260- promptString string261- prompt func()262- promptLen int263- borderLabel labelPrinter264- borderLabelLen int265- borderLabelOpts labelOpts266- previewLabel labelPrinter267- previewLabelLen int268- previewLabelOpts labelOpts269- inputLabel labelPrinter270- inputLabelLen int271- inputLabelOpts labelOpts272- headerLabel labelPrinter273- headerLabelLen int274- headerLabelOpts labelOpts275- footerLabel labelPrinter276- footerLabelLen int277- footerLabelOpts labelOpts278- gutterReverse bool279- gutterRawReverse bool280- pointer string281- pointerLen int282- pointerEmpty string283- pointerEmptyRaw string284- marker string285- markerLen int286- markerEmpty string287- markerMultiLine [3]string288- queryLen [2]int289- layout layoutType290- fullscreen bool291- keepRight bool292- hscroll bool293- hscrollOff int294- scrollOff int295- gap int296- gapLine labelPrinter297- gapLineLen int298- wordRubout string299- wordNext string300- subWordRubout string301- subWordNext string302- cx int303- cy int304- offset int305- xoffset int306- yanked []rune307- input []rune308- inputOverride *[]rune309- pasting *[]rune310- multi int311- multiLine bool312- sort bool313- toggleSort bool314- track trackOption315- delimiter Delimiter316- expect map[tui.Event]string317- keymap map[tui.Event][]*action318- keymapOrg map[tui.Event][]*action319- pressed string320- printQueue []string321- printQuery bool322- history *History323- cycle bool324- highlightLine bool325- headerVisible bool326- headerFirst bool327- headerLines int328- header []string329- header0 []string330- footer []string331- ellipsis string332- scrollbar string333- previewScrollbar string334- ansi bool335- freezeLeft int336- freezeRight int337- nthAttr tui.Attr338- nth []Range339- nthCurrent []Range340- acceptNth func([]Token, int32) string341- tabstop int342- margin [4]sizeSpec343- padding [4]sizeSpec344- unicode bool345- listenAddr *listenAddress346- listenPort *int347- listener net.Listener348- listenUnsafe bool349- borderShape tui.BorderShape350- listBorderShape tui.BorderShape351- inputBorderShape tui.BorderShape352- headerBorderShape tui.BorderShape353- headerLinesShape tui.BorderShape354- footerBorderShape tui.BorderShape355- listLabel labelPrinter356- listLabelLen int357- listLabelOpts labelOpts358- cleanExit bool359- executor *util.Executor360- paused bool361- inputless bool362- border tui.Window363- window tui.Window364- inputWindow tui.Window365- inputBorder tui.Window366- headerWindow tui.Window367- headerBorder tui.Window368- headerLinesWindow tui.Window369- headerLinesBorder tui.Window370- footerWindow tui.Window371- footerBorder tui.Window372- wborder tui.Window373- pborder tui.Window374- pwindow tui.Window375- borderWidth int376- count int377- progress int378- hasStartActions bool379- hasResultActions bool380- hasFocusActions bool381- hasLoadActions bool382- hasResizeActions bool383- triggerLoad bool384- reading bool385- running *util.AtomicBool386- failed *string387- jumping jumpMode388- jumpLabels string389- printer func(string)390- printsep string391- merger *Merger392- passMerger *Merger393- resultMerger *Merger394- matchMap map[int32]Result395- selected map[int32]selectedItem396- version int64397- revision revision398- bgVersion int64399- runningCmds *util.ConcurrentSet[*runningCmd]400- reqBox *util.EventBox401- initialPreviewOpts previewOpts402- previewOpts previewOpts403- activePreviewOpts *previewOpts404- previewer previewer405- previewed previewed406- previewBox *util.EventBox407- eventBox *util.EventBox408- mutex sync.Mutex409- uiMutex sync.Mutex410- initFunc func() error411- prevLines []itemLine412- suppress bool413- startChan chan fitpad414- killChan chan bool415- killedChan chan bool416- serverInputChan chan []*action417- callbackChan chan versionedCallback418- bgQueue map[action][]func(bool)419- bgSemaphore chan struct{}420- bgSemaphores map[action]chan struct{}421- keyChan chan tui.Event422- eventChan chan tui.Event423- slab *util.Slab424- theme *tui.ColorTheme425- tui tui.Renderer426- ttyDefault string427- ttyin *os.File428- executing *util.AtomicBool429- termSize tui.TermSize430- lastAction actionType431- lastKey string432- lastFocus int32433- areaLines int434- areaColumns int435- forcePreview bool436- clickHeaderLine int437- clickHeaderColumn int438- clickFooterLine int439- clickFooterColumn int440- proxyScript string441- numLinesCache map[int32]numLinesCacheValue442- raw bool250+ infoStyle infoStyle251+ infoPrefix string252+ wrap bool253+ wrapWord bool254+ wrapSign string255+ wrapSignWidth int256+ previewWrapSign string257+ previewWrapSignWidth int258+ ghost string259+ separator labelPrinter260+ separatorLen int261+ spinner []string262+ promptString string263+ prompt func()264+ promptLen int265+ borderLabel labelPrinter266+ borderLabelLen int267+ borderLabelOpts labelOpts268+ previewLabel labelPrinter269+ previewLabelLen int270+ previewLabelOpts labelOpts271+ inputLabel labelPrinter272+ inputLabelLen int273+ inputLabelOpts labelOpts274+ headerLabel labelPrinter275+ headerLabelLen int276+ headerLabelOpts labelOpts277+ footerLabel labelPrinter278+ footerLabelLen int279+ footerLabelOpts labelOpts280+ gutterReverse bool281+ gutterRawReverse bool282+ pointer string283+ pointerLen int284+ pointerEmpty string285+ pointerEmptyRaw string286+ marker string287+ markerLen int288+ markerEmpty string289+ markerMultiLine [3]string290+ queryLen [2]int291+ layout layoutType292+ fullscreen bool293+ keepRight bool294+ hscroll bool295+ hscrollOff int296+ scrollOff int297+ gap int298+ gapLine labelPrinter299+ gapLineLen int300+ wordRubout string301+ wordNext string302+ subWordRubout string303+ subWordNext string304+ cx int305+ cy int306+ offset int307+ xoffset int308+ yanked []rune309+ input []rune310+ inputOverride *[]rune311+ pasting *[]rune312+ multi int313+ multiLine bool314+ sort bool315+ toggleSort bool316+ track trackOption317+ delimiter Delimiter318+ expect map[tui.Event]string319+ keymap map[tui.Event][]*action320+ keymapOrg map[tui.Event][]*action321+ pressed string322+ printQueue []string323+ printQuery bool324+ history *History325+ cycle bool326+ highlightLine bool327+ headerVisible bool328+ headerFirst bool329+ headerLines int330+ header []string331+ header0 []string332+ footer []string333+ ellipsis string334+ scrollbar string335+ previewScrollbar string336+ ansi bool337+ freezeLeft int338+ freezeRight int339+ nthAttr tui.Attr340+ nth []Range341+ nthCurrent []Range342+ acceptNth func([]Token, int32) string343+ tabstop int344+ margin [4]sizeSpec345+ padding [4]sizeSpec346+ unicode bool347+ listenAddr *listenAddress348+ listenPort *int349+ listener net.Listener350+ listenUnsafe bool351+ borderShape tui.BorderShape352+ listBorderShape tui.BorderShape353+ inputBorderShape tui.BorderShape354+ headerBorderShape tui.BorderShape355+ headerLinesShape tui.BorderShape356+ footerBorderShape tui.BorderShape357+ listLabel labelPrinter358+ listLabelLen int359+ listLabelOpts labelOpts360+ cleanExit bool361+ executor *util.Executor362+ paused bool363+ inputless bool364+ border tui.Window365+ window tui.Window366+ inputWindow tui.Window367+ inputBorder tui.Window368+ headerWindow tui.Window369+ headerBorder tui.Window370+ headerLinesWindow tui.Window371+ headerLinesBorder tui.Window372+ footerWindow tui.Window373+ footerBorder tui.Window374+ wborder tui.Window375+ pborder tui.Window376+ pwindow tui.Window377+ borderWidth int378+ count int379+ progress int380+ hasStartActions bool381+ hasResultActions bool382+ hasFocusActions bool383+ hasLoadActions bool384+ hasResizeActions bool385+ triggerLoad bool386+ reading bool387+ running *util.AtomicBool388+ failed *string389+ jumping jumpMode390+ jumpLabels string391+ printer func(string)392+ printsep string393+ merger *Merger394+ passMerger *Merger395+ resultMerger *Merger396+ matchMap map[int32]Result397+ selected map[int32]selectedItem398+ version int64399+ revision revision400+ bgVersion int64401+ runningCmds *util.ConcurrentSet[*runningCmd]402+ reqBox *util.EventBox403+ initialPreviewOpts previewOpts404+ previewOpts previewOpts405+ activePreviewOpts *previewOpts406+ previewer previewer407+ previewed previewed408+ previewBox *util.EventBox409+ eventBox *util.EventBox410+ mutex sync.Mutex411+ uiMutex sync.Mutex412+ initFunc func() error413+ prevLines []itemLine414+ suppress bool415+ startChan chan fitpad416+ killChan chan bool417+ killedChan chan bool418+ serverInputChan chan []*action419+ callbackChan chan versionedCallback420+ bgQueue map[action][]func(bool)421+ bgSemaphore chan struct{}422+ bgSemaphores map[action]chan struct{}423+ keyChan chan tui.Event424+ eventChan chan tui.Event425+ slab *util.Slab426+ theme *tui.ColorTheme427+ tui tui.Renderer428+ ttyDefault string429+ ttyin *os.File430+ executing *util.AtomicBool431+ termSize tui.TermSize432+ lastAction actionType433+ lastKey string434+ lastFocus int32435+ areaLines int436+ areaColumns int437+ forcePreview bool438+ clickHeaderLine int439+ clickHeaderColumn int440+ clickFooterLine int441+ clickFooterColumn int442+ proxyScript string443+ numLinesCache map[int32]numLinesCacheValue444+ raw bool445 }446 447 type numLinesCacheValue struct {448 atMost int803 unmodified lines1252 if opts.WrapSign != nil {1253 t.wrapSign = *opts.WrapSign1254 }1255 t.wrapSign, t.wrapSignWidth = t.processTabsStr(t.wrapSign, 0)1256+ t.previewWrapSign = t.wrapSign1257+ t.previewWrapSignWidth = t.wrapSignWidth1258+ if opts.PreviewWrapSign != nil {1259+ t.previewWrapSign, t.previewWrapSignWidth = t.processTabsStr(*opts.PreviewWrapSign, 0)1260+ }1261 if opts.Scrollbar == nil {1262 if t.unicode && t.borderWidth == 1 {1263 t.scrollbar = "│"1264 } else {1053 unmodified lines2318 // Need a column to show scrollbar2319 pwidth -= 12320 }2321 t.pwindow = t.tui.NewWindow(y, x, pwidth, pheight, tui.WindowPreview, noBorder, true)2315- t.pwindow.SetWrapSign(t.wrapSign, t.wrapSignWidth)2322+ t.pwindow.SetWrapSign(t.previewWrapSign, t.previewWrapSignWidth)2323 if !hadPreviewWindow {2324 t.pwindow.Erase()2325 }2326 }1809 unmodified lines4136 4137 // For word-wrap mode, count the sub-lines produced by word wrapping.4138 // Each sub-line may still char-wrap if it contains a word longer than the width.4139 if t.activePreviewOpts.wrapWord {4133- subLines := t.wordWrapAnsiLine(line, maxWidth, t.wrapSignWidth)4140+ subLines := t.wordWrapAnsiLine(line, maxWidth, t.previewWrapSignWidth)4141 total := 04142 for i, sub := range subLines {4143 prefixWidth := 04144 cols := maxWidth4145 if i > 0 {4139- prefixWidth = t.wrapSignWidth4140- cols -= t.wrapSignWidth4146+ prefixWidth = t.previewWrapSignWidth4147+ cols -= t.previewWrapSignWidth4148 }4149 w := t.ansiLineWidth(sub, prefixWidth)4150 if cols <= 0 {4151 cols = 18 unmodified lines4160 if w <= maxWidth {4161 return 14162 }4163 remaining := w - maxWidth4157- contWidth := max(1, maxWidth-t.wrapSignWidth)4164+ contWidth := max(1, maxWidth-t.previewWrapSignWidth)4165 return 1 + (remaining+contWidth-1)/contWidth4166 }4167 4168 // ansiLineWidth computes the display width of a string, skipping ANSI escape sequences.170 unmodified lines4339 4340 // Pre-split line into sub-lines for word wrapping4341 var subLines []string4342 if t.activePreviewOpts.wrapWord {4336- subLines = t.wordWrapAnsiLine(line, maxWidth, t.wrapSignWidth)4343+ subLines = t.wordWrapAnsiLine(line, maxWidth, t.previewWrapSignWidth)4344 } else {4345 subLines = []string{line}4346 }4347 4348 var fillRet tui.FillReturn4349 wrap := t.activePreviewOpts.wrap4350 printWrapSign := func() {4344- if t.pwindow.CFill(tui.ColPreview.Fg(), tui.ColPreview.Bg(), -1, tui.Dim, t.wrapSign) == tui.FillNextLine {4351+ if t.pwindow.CFill(tui.ColPreview.Fg(), tui.ColPreview.Bg(), -1, tui.Dim, t.previewWrapSign) == tui.FillNextLine {4352 t.pwindow.Move(t.pwindow.Y()-1, t.pwindow.Width())4353 }4354 fillRet = tui.FillContinue4355 }3300 unmodified linesmodified:CHANGELOG.md+2 added
30 unmodified lines31 32 # In the preview window33 fzf --preview "printf '\e[4:3;58;2;255;0;0mRed curly underline\e[0m\n'"34 ```35+- Added `--preview-wrap-sign` to set a different wrap indicator for the preview36+ window37 - Added `alt-gutter` color option (#4602) (@hedgieinsocks)38 - Added fish completion support (#4605) (@lalvarezt)39 - zsh: Handle multi-line history selection (#4595) (@LangLangBart)40 - Bug fixes3131 unmodified lines