Skip to content
Myr

Add --separator to customize the info separator

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 2eec989 · Browse files · 6 files+162 added−61 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+162 added−61 removed

  • tests:+17 added−2 removed
  • other:+145 added−59 removed

6 files+162 added−61 removed

modified:man/man1/fzf.1+12 added
342 unmodified lines
343.B "--no-info"344A synonym for \fB--info=hidden\fB345346.TP347.BI "--separator=" "STR"348The given string will be repeated to form the horizontal separator on the info349line (default: '─' or '-' depending on \fB--no-unicode\fR).350351ANSI color codes are supported.352353.TP354.B "--no-separator"355Do not display horizontal separator on the info line. A synonym for356\fB--separator=''\fB357358.TP359.BI "--prompt=" "STR"360Input prompt (default: '> ')361.TP362.BI "--pointer=" "STR"
782 unmodified lines
modified:src/util/util.go+20 added
151 unmodified lines
152 state = false153 return prevState154 }155}156157// RepeatToFill repeats the given string to fill the given width158func RepeatToFill(str string, length int, limit int) string {159 times := limit / length160 rest := limit % length161 output := strings.Repeat(str, times)162 if rest > 0 {163 for _, r := range str {164 rest -= runewidth.RuneWidth(r)165 if rest < 0 {166 break167 }168 output += string(r)169 if rest == 0 {170 break171 }172 }173 }174 return output175}
modified:src/options.go+29 added-30 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[:nosep]]73 --info=STYLE Finder info style [default|inline|hidden]74 --separator=STR String to form horizontal separator on info line75 --no-separator Hide info line separator76 --prompt=STR Input prompt (default: '> ')77 --pointer=STR Pointer to the current line (default: '>')78 --marker=STR Multi-select marker (default: '>')79 --header=STR String to print as header
94 unmodified lines
174 layoutReverse175 layoutReverseList176)177176type infoLayout int177type infoStyle struct {178 layout infoLayout179 separator bool180}178type infoStyle int179180const (183 infoDefault infoLayout = iota181 infoDefault infoStyle = iota182 infoInline183 infoHidden184)185
79 unmodified lines
265 HscrollOff int266 ScrollOff int267 FileWord bool268 InfoStyle infoStyle269 Separator *string270 JumpLabels string271 Prompt string272 Pointer string273 Marker string
58 unmodified lines
332 Hscroll: true,333 HscrollOff: 10,334 ScrollOff: 0,335 FileWord: false,337 InfoStyle: infoStyle{layout: infoDefault, separator: true},336 InfoStyle: infoDefault,337 Separator: nil,338 JumpLabels: defaultJumpLabels,339 Prompt: "> ",340 Pointer: ">",341 Marker: ">",
905 unmodified lines
1247 return layoutDefault1248}12491250func parseInfoStyle(str string) infoStyle {1251 layout := infoDefault1252 separator := true12531254 for _, token := range splitRegexp.Split(strings.ToLower(str), -1) {1255 switch token {1256 case "default":1257 layout = infoDefault1258 case "inline":1259 layout = infoInline1260 case "hidden":1261 layout = infoHidden1262 case "nosep":1263 separator = false1251 switch str {1252 case "default":1253 return infoDefault1254 case "inline":1255 return infoInline1256 case "hidden":1257 return infoHidden1258 default:1259 errorExit("invalid info style (expected: default|inline|hidden)")1264 case "sep":1265 separator = true1266 default:1267 errorExit("invalid info style (expected: default|inline|hidden[:nosep])")1268 }1260 }1270 return infoStyle{layout: layout, separator: separator}1261 return infoDefault1262}12631264func parsePreviewWindow(opts *previewOpts, input string) {1265 tokenRegex := regexp.MustCompile(`[:,]*(<([1-9][0-9]*)\(([^)<]+)\)|[^,:]+)`)
257 unmodified lines
1523 case "--info":1524 opts.InfoStyle = parseInfoStyle(1525 nextString(allArgs, &i, "info style required"))1526 case "--no-info":1536 opts.InfoStyle.layout = infoHidden1527 opts.InfoStyle = infoHidden1528 case "--inline-info":1538 opts.InfoStyle.layout = infoInline1529 opts.InfoStyle = infoInline1530 case "--no-inline-info":1540 opts.InfoStyle.layout = infoDefault1531 opts.InfoStyle = infoDefault1532 case "--separator":1533 separator := nextString(allArgs, &i, "separator character required")1534 opts.Separator = &separator1535 case "--no-separator":1536 nosep := ""1537 opts.Separator = &nosep1538 case "--jump-labels":1539 opts.JumpLabels = nextString(allArgs, &i, "label characters required")1540 validateJumpLabels = true1541 case "-1", "--select-1":
155 unmodified lines
1697 } else if match, value := optString(arg, "--layout="); match {1698 opts.Layout = parseLayout(value)1699 } else if match, value := optString(arg, "--info="); match {1700 opts.InfoStyle = parseInfoStyle(value)1701 } else if match, value := optString(arg, "--separator="); match {1702 opts.Separator = &value1703 } else if match, value := optString(arg, "--toggle-sort="); match {1704 parseToggleSort(opts.Keymap, value)1705 } else if match, value := optString(arg, "--expect="); match {1706 for k, v := range parseKeyChords(value, "key names required") {
226 unmodified lines
modified:src/terminal.go+74 added-25 removed
105 unmodified lines
106}107108var emptyLine = itemLine{}109110type labelPrinter func(tui.Window, int)111112// Terminal represents terminal input/output113type Terminal struct {114 initDelay time.Duration115 infoStyle infoStyle116 separator labelPrinter117 separatorLen int118 spinner []string119 prompt func()120 promptLen int117 borderLabel func(tui.Window)121 borderLabel labelPrinter122 borderLabelLen int123 borderLabelOpts labelOpts120 previewLabel func(tui.Window)124 previewLabel labelPrinter125 previewLabelLen int126 previewLabelOpts labelOpts127 pointer string128 pointerLen int
372 unmodified lines
501 effectiveMinHeight := minHeight502 if previewBox != nil && opts.Preview.aboveOrBelow() {503 effectiveMinHeight += 1 + borderLines(opts.Preview.border)504 }501 if opts.InfoStyle.layout != infoDefault {505 if opts.InfoStyle != infoDefault {506 effectiveMinHeight--507 }508 effectiveMinHeight += borderLines(opts.BorderShape)509 return util.Min(termHeight, util.Max(evaluateHeight(opts, termHeight), effectiveMinHeight))
13 unmodified lines
523 }524 t := Terminal{525 initDelay: delay,526 infoStyle: opts.InfoStyle,527 separator: nil,528 spinner: makeSpinner(opts.Unicode),529 queryLen: [2]int{0, 0},530 layout: opts.Layout,531 fullscreen: fullscreen,
69 unmodified lines
601 t.marker, t.markerLen = t.processTabs([]rune(opts.Marker), 0)602 // Pre-calculated empty pointer and marker signs603 t.pointerEmpty = strings.Repeat(" ", t.pointerLen)604 t.markerEmpty = strings.Repeat(" ", t.markerLen)600 t.borderLabel, t.borderLabelLen = t.parseBorderLabel(opts.BorderLabel.label)601 t.previewLabel, t.previewLabelLen = t.parseBorderLabel(opts.PreviewLabel.label)605 t.borderLabel, t.borderLabelLen = t.ansiLabelPrinter(opts.BorderLabel.label, &tui.ColBorderLabel, false)606 t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(opts.PreviewLabel.label, &tui.ColBorderLabel, false)607 if opts.Separator == nil || len(*opts.Separator) > 0 {608 bar := "─"609 if opts.Separator != nil {610 bar = *opts.Separator611 } else if !t.unicode {612 bar = "-"613 }614 t.separator, t.separatorLen = t.ansiLabelPrinter(bar, &tui.ColSeparator, true)615 }616617 return &t618}619
22 unmodified lines
642 fit := screenHeight - padHeight - t.extraLines()643 return fit, padHeight644}645632func (t *Terminal) parseBorderLabel(borderLabel string) (func(tui.Window), int) {633 if len(borderLabel) == 0 {646func (t *Terminal) ansiLabelPrinter(str string, color *tui.ColorPair, fill bool) (labelPrinter, int) {647 // Nothing to do648 if len(str) == 0 {649 return nil, 0650 }651652 // Extract ANSI color codes636 text, colors, _ := extractColor(borderLabel, nil, nil)653 text, colors, _ := extractColor(str, nil, nil)654 runes := []rune(text)655656 // Simpler printer for strings without ANSI colors or tab characters657 if colors == nil && strings.IndexRune(str, '\t') < 0 {658 length := runewidth.StringWidth(str)659 if length == 0 {660 return nil, 0661 }662 printFn := func(window tui.Window, limit int) {663 if length > limit {664 trimmedRunes, _ := t.trimRight(runes, limit)665 window.CPrint(*color, string(trimmedRunes))666 } else if fill {667 window.CPrint(*color, util.RepeatToFill(str, length, limit))668 } else {669 window.CPrint(*color, str)670 }671 }672 return printFn, len(text)673 }674675 // Printer that correctly handles ANSI color codes and tab characters676 item := &Item{text: util.RunesToChars(runes), colors: colors}677 length := t.displayWidth(runes)678 if length == 0 {679 return nil, 0680 }681 result := Result{item: item}640682 var offsets []colorOffset642 borderLabelFn := func(window tui.Window) {683 printFn := func(window tui.Window, limit int) {684 if offsets == nil {685 // tui.Col* are not initialized until renderer.Init()645 offsets = result.colorOffsets(nil, t.theme, tui.ColBorderLabel, tui.ColBorderLabel, false)686 offsets = result.colorOffsets(nil, t.theme, *color, *color, false)687 }647 text, _ := t.trimRight(runes, window.Width())648 t.printColoredString(window, text, offsets, tui.ColBorderLabel)688 for limit > 0 {689 if length > limit {690 trimmedRunes, _ := t.trimRight(runes, limit)691 t.printColoredString(window, trimmedRunes, offsets, *color)692 break693 } else if fill {694 t.printColoredString(window, runes, offsets, *color)695 limit -= length696 } else {697 t.printColoredString(window, runes, offsets, *color)698 break699 }700 }701 }650 borderLabelLen := runewidth.StringWidth(text)651 return borderLabelFn, borderLabelLen702 return printFn, length703}704705func (t *Terminal) parsePrompt(prompt string) (func(), int) {706 var state *ansiState
27 unmodified lines
734 return output, promptLen735}736737func (t *Terminal) noInfoLine() bool {687 return t.infoStyle.layout != infoDefault738 return t.infoStyle != infoDefault739}740741// Input returns current query string742func (t *Terminal) Input() (bool, []rune) {
358 unmodified lines
1101 height, false, noBorder)1102 }11031104 // Print border label1054 printLabel := func(window tui.Window, render func(tui.Window), opts labelOpts, length int, borderShape tui.BorderShape) {1105 printLabel := func(window tui.Window, render labelPrinter, opts labelOpts, length int, borderShape tui.BorderShape) {1106 if window == nil || render == nil {1107 return1108 }1109
11 unmodified lines
1121 if borderShape == tui.BorderBottom || opts.bottom {1122 row = window.Height() - 11123 }1124 window.Move(row, col)1074 render(window)1125 render(window, window.Width())1126 }1127 }1128 printLabel(t.border, t.borderLabel, t.borderLabelOpts, t.borderLabelLen, t.borderShape)1129 printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.previewOpts.border)
87 unmodified lines
12171218func (t *Terminal) printInfo() {1219 pos := 01220 line := t.promptLine()1170 switch t.infoStyle.layout {1221 switch t.infoStyle {1222 case infoDefault:1223 t.move(line+1, 0, true)1224 if t.reading {1225 duration := int64(spinnerDuration)
44 unmodified lines
1270 maxWidth := t.window.Width() - pos1271 output = t.trimMessage(output, maxWidth)1272 t.window.CPrint(tui.ColInfo, output)12731223 if t.infoStyle.separator && len(output) < maxWidth-2 {1224 bar := "─"1225 if !t.unicode {1226 bar = "-"1227 }1228 t.window.CPrint(tui.ColSeparator, " "+strings.Repeat(bar, maxWidth-len(output)-2))1274 fillLength := maxWidth - len(output) - 21275 if t.separatorLen > 0 && fillLength > 0 {1276 t.window.CPrint(tui.ColSeparator, " ")1277 t.separator(t.window, fillLength)1278 }1279}12801281func (t *Terminal) printHeader() {
1859 unmodified lines
modified:test/test_go.rb+17 added-2 removed
2378 unmodified lines
2379 assert_includes(_1[-2], '─barfoo╯')2380 end2381 end23822383 def test_info_separator2383 def test_info_separator_unicode2384 tmux.send_keys 'seq 100 | fzf -q55', :Enter2385 tmux.until { assert_includes(_1[-2], ' 1/100 ─') }2386 end23872388 def test_info_separator_no_unicode2389 tmux.send_keys 'seq 100 | fzf -q55 --no-unicode', :Enter2390 tmux.until { assert_includes(_1[-2], ' 1/100 -') }2391 end23922393 def test_info_separator_repeat2394 tmux.send_keys 'seq 100 | fzf -q55 --separator _-', :Enter2395 tmux.until { assert_includes(_1[-2], ' 1/100 _-_-') }2396 end23972398 def test_info_separator_ansi_colors_and_tabs2399 tmux.send_keys "seq 100 | fzf -q55 --tabstop 4 --separator $'\\x1b[33ma\\tb'", :Enter2400 tmux.until { assert_includes(_1[-2], ' 1/100 a ba ba') }2401 end24022403 def test_info_no_separator2389 tmux.send_keys 'seq 100 | fzf -q55 --info nosep', :Enter2404 tmux.send_keys 'seq 100 | fzf -q55 --no-separator', :Enter2405 tmux.until { assert(_1[-2] == ' 1/100') }2406 end2407end2408
481 unmodified lines
modified:CHANGELOG.md+10 added-4 removed
27 unmodified lines
28 preview window29 ```sh30 fzf --preview 'cat {}' --border --preview-label=' Preview ' --preview-label-pos=231 ```32- Info panel (counter) will be followed by a horizontal separator by default32- Info panel (match counter) will be followed by a horizontal separator by33 default34 - Use `--no-separator` or `--separator=''` to hide the separator35 - You can specify an arbitrary string that is repeated to form the36 horizontal separator. e.g. `--separator=╸`37 - The color of the separator can be customized via `--color=separator:...`34 - Separator can be disabled by adding `:nosep` to `--info`35 - `--info=nosep`36 - `--info=inline:nosep`38 - ANSI color codes are also supported39 ```sh40 fzf --separator=╸ --color=separator:green41 fzf --separator=$(lolcat -f -F 1.4 <<< ▁▁▂▃▄▅▆▆▅▄▃▂▁▁) --info=inline42 ```43- Added `--border=bold` and `--border=double` along with44 `--preview-window=border-bold` and `--preview-window=border-double`45460.34.0
1341 unmodified lines