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
Provenance
- Commit
618d317- Tree
59e897a- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
ae897c8
5 files changed+43 added−17 removed
modified:man/man1/fzf.1+5 added-3 removed
335 unmodified lines336 .BI "--info=" "STYLE"337 Determines the display style of finder info (match counters).338 339 .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+.br348 349 .TP350 .B "--no-info"351 A synonym for \fB--info=hidden\fB873 unmodified linesmodified:src/options.go+17 added-9 removed
68 unmodified lines69 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 scrollbar46 unmodified lines124 (e.g. '--layout=reverse --inline-info')125 126 `127 128+const defaultInfoSep = " < "129+130 // Case denotes case-sensitivity of search131 type Case int132 133 // Case-sensitivities144 unmodified lines278 HscrollOff int279 ScrollOff int280 FileWord bool281 InfoStyle infoStyle282+ InfoSep string283 Separator *string284 JumpLabels string285 Prompt string286 Pointer string1034 unmodified lines1321 }1322 return layoutDefault1323 }1324 1322-func parseInfoStyle(str string) infoStyle {1325+func 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 }1342 1343 func parsePreviewWindow(opts *previewOpts, input string) {1344 parsePreviewWindowImpl(opts, input, errorExit)259 unmodified lines1604 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 lines1795 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 = &value236 unmodified linesmodified:src/terminal.go+12 added-5 removed
145 unmodified lines146 // Terminal represents terminal input/output147 type Terminal struct {148 initDelay time.Duration149 infoStyle infoStyle150+ infoSep string151 separator labelPrinter152 separatorLen int153 spinner []string154 prompt func()424 unmodified lines579 }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 lines1394 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 linesmodified:test/test_go.rb+5 added
1585 unmodified lines1586 tmux.send_keys 'seq 10 | fzf --info=hidden', :Enter1587 tmux.until { |lines| assert_equal '> 1', lines[-2] }1588 end1589 1590+ 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+ end1594+1595 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 :Up1477 unmodified linesmodified:CHANGELOG.md+4 added
1 unmodified line2 =========3 4 0.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 ```sh1529 unmodified lines