Skip to content
Myr

Support custom separator of inline info

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

Close #2030 Close #3084

authored by Junegunn Choi · committed by Junegunn Choi · parent ae897c8 · Browse files · 5 files+43 added−17 removed
This commit

State

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

Diff stats

5 files+43 added−17 removed

  • tests:+5 added−0 removed
  • other:+38 added−17 removed

5 files+43 added−17 removed

modified:man/man1/fzf.1+5 added-3 removed
335 unmodified lines
336.BI "--info=" "STYLE"337Determines the display style of finder info (match counters).338339.br340.BR default " Display on the next line to the prompt"340.BR default " Display on the next line to the prompt"341.br342.BR inline " Display on the same line"342.BR inline " Display on the same line with the default separator ' < '"343.br344.BR hidden " Do not display finder info"344.BR inline:SEPARATOR " Display on the same line with a non-default separator"345.br346.BR hidden " Do not display finder info"347.br348349.TP350.B "--no-info"351A synonym for \fB--info=hidden\fB
873 unmodified lines
modified:src/options.go+17 added-9 removed
68 unmodified lines
69 NEGATIVE_INTEGER: columns from right][:bottom]70 (default: 0 or center)71 --margin=MARGIN Screen margin (TRBL | TB,RL | T,RL,B | T,R,B,L)72 --padding=PADDING Padding inside border (TRBL | TB,RL | T,RL,B | T,R,B,L)73 --info=STYLE Finder info style [default|inline|hidden]73 --info=STYLE Finder info style [default|hidden|inline|inline:SEPARATOR]74 --separator=STR String to form horizontal separator on info line75 --no-separator Hide info line separator76 --scrollbar[=CHAR] Scrollbar character77 --no-scrollbar Hide scrollbar
46 unmodified lines
124 (e.g. '--layout=reverse --inline-info')125126`127128const defaultInfoSep = " < "129130// Case denotes case-sensitivity of search131type Case int132133// Case-sensitivities
144 unmodified lines
278 HscrollOff int279 ScrollOff int280 FileWord bool281 InfoStyle infoStyle282 InfoSep string283 Separator *string284 JumpLabels string285 Prompt string286 Pointer string
1034 unmodified lines
1321 }1322 return layoutDefault1323}13241322func parseInfoStyle(str string) infoStyle {1325func parseInfoStyle(str string) (infoStyle, string) {1326 switch str {1327 case "default":1325 return infoDefault1328 return infoDefault, ""1329 case "inline":1327 return infoInline1330 return infoInline, defaultInfoSep1331 case "hidden":1329 return infoHidden1332 return infoHidden, ""1333 default:1334 prefix := "inline:"1335 if strings.HasPrefix(str, prefix) {1336 return infoInline, strings.ReplaceAll(str[len(prefix):], "\n", " ")1337 }1331 errorExit("invalid info style (expected: default|inline|hidden)")1338 errorExit("invalid info style (expected: default|hidden|inline|inline:SEPARATOR)")1339 }1333 return infoDefault1340 return infoDefault, ""1341}13421343func parsePreviewWindow(opts *previewOpts, input string) {1344 parsePreviewWindowImpl(opts, input, errorExit)
259 unmodified lines
1604 opts.FileWord = true1605 case "--no-filepath-word":1606 opts.FileWord = false1607 case "--info":1601 opts.InfoStyle = parseInfoStyle(1608 opts.InfoStyle, opts.InfoSep = parseInfoStyle(1609 nextString(allArgs, &i, "info style required"))1610 case "--no-info":1611 opts.InfoStyle = infoHidden1612 case "--inline-info":1613 opts.InfoStyle = infoInline1614 opts.InfoSep = defaultInfoSep1615 case "--no-inline-info":1616 opts.InfoStyle = infoDefault1617 case "--separator":1618 separator := nextString(allArgs, &i, "separator character required")
176 unmodified lines
1795 opts.MinHeight = atoi(value)1796 } else if match, value := optString(arg, "--layout="); match {1797 opts.Layout = parseLayout(value)1798 } else if match, value := optString(arg, "--info="); match {1791 opts.InfoStyle = parseInfoStyle(value)1799 opts.InfoStyle, opts.InfoSep = parseInfoStyle(value)1800 } else if match, value := optString(arg, "--separator="); match {1801 opts.Separator = &value1802 } else if match, value := optString(arg, "--scrollbar="); match {1803 opts.Scrollbar = &value
236 unmodified lines
modified:src/terminal.go+12 added-5 removed
145 unmodified lines
146// Terminal represents terminal input/output147type Terminal struct {148 initDelay time.Duration149 infoStyle infoStyle150 infoSep string151 separator labelPrinter152 separatorLen int153 spinner []string154 prompt func()
424 unmodified lines
579 }580 t := Terminal{581 initDelay: delay,582 infoStyle: opts.InfoStyle,583 infoSep: opts.InfoSep,584 separator: nil,585 spinner: makeSpinner(opts.Unicode),586 queryLen: [2]int{0, 0},587 layout: opts.Layout,
806 unmodified lines
1394 t.move(line+1, 2, false)1395 pos = 21396 case infoInline:1397 pos = t.promptLen + t.queryLen[0] + t.queryLen[1] + 11396 if pos+len(" < ") > t.window.Width() {1397 return1398 str := t.infoSep1399 maxWidth := t.window.Width() - pos1400 width := runewidth.StringWidth(str)1401 if width > maxWidth {1402 trimmed, _ := t.trimRight([]rune(str), maxWidth)1403 str = string(trimmed)1404 width = maxWidth1405 }1406 t.move(line, pos, t.separatorLen == 0)1407 if t.reading {1401 t.window.CPrint(tui.ColSpinner, " < ")1408 t.window.CPrint(tui.ColSpinner, str)1409 } else {1403 t.window.CPrint(tui.ColPrompt, " < ")1410 t.window.CPrint(tui.ColPrompt, str)1411 }1405 pos += len(" < ")1412 pos += width1413 case infoHidden:1414 return1415 }1416
2150 unmodified lines
modified:test/test_go.rb+5 added
1585 unmodified lines
1586 tmux.send_keys 'seq 10 | fzf --info=hidden', :Enter1587 tmux.until { |lines| assert_equal '> 1', lines[-2] }1588 end15891590 def test_info_inline_separator1591 tmux.send_keys 'seq 10 | fzf --info=inline:___ --no-separator', :Enter1592 tmux.until { |lines| assert_equal '> ___10/10', lines[-1] }1593 end15941595 def test_change_first_last1596 tmux.send_keys %(seq 1000 | #{FZF} --bind change:first,alt-Z:last), :Enter1597 tmux.until { |lines| assert_equal 1000, lines.match_count }1598 tmux.send_keys :Up
1477 unmodified lines
modified:CHANGELOG.md+4 added
1 unmodified line
2=========340.37.05------6- Added a way to customize the separator of inline info7 ```sh8 fzf --info 'inline: ╱ ' --prompt '╱ ' --color prompt:bright-yellow9 ```10- New event11 - `focus` - Triggered when the focus changes due to a vertical cursor12 movement or a search result update13 ```sh
1529 unmodified lines