Skip to content
Myr

Add --gap option to put empty lines between items

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 4161403 · Browse files · 5 files+105 added−21 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+105 added−21 removed

  • tests:+34 added−0 removed
  • other:+71 added−21 removed

5 files+105 added−21 removed

modified:man/man1/fzf.1+3 added
206 unmodified lines
207.TP208.B "\-\-no\-multi\-line"209Disable multi-line display of items when using \fB\-\-read0\fR210.TP211.BI "\-\-gap" "[=N]"212Render empty lines between each item213.TP214.B "\-\-keep\-right"215Keep the right end of the line visible when it's too long. Effective only when216the query string is empty.217.TP
1492 unmodified lines
modified:src/options.go+13 added
54 unmodified lines
55 --cycle Enable cyclic scroll56 --wrap Enable line wrap57 --wrap-sign=STR Indicator for wrapped lines58 --no-multi-line Disable multi-line display of items when using --read059 --gap[=N] Render empty lines between each item60 --keep-right Keep the right end of the line visible on overflow61 --scroll-off=LINES Number of screen lines to keep above or below when62 scrolling to the top or to the bottom (default: 0)63 --no-hscroll Disable horizontal scroll
409 unmodified lines
473 History *History474 Header []string475 HeaderLines int476 HeaderFirst bool477 Gap int478 Ellipsis *string479 Scrollbar *string480 Margin [4]sizeSpec481 Padding [4]sizeSpec
98 unmodified lines
580 History: nil,581 Header: make([]string, 0),582 HeaderLines: 0,583 HeaderFirst: false,584 Gap: 0,585 Ellipsis: nil,586 Scrollbar: nil,587 Margin: defaultMargin(),588 Padding: defaultMargin(),
1756 unmodified lines
2345 case "--header-first":2346 opts.HeaderFirst = true2347 case "--no-header-first":2348 opts.HeaderFirst = false2349 case "--gap":2350 if opts.Gap, err = optionalNumeric(allArgs, &i, 1); err != nil {2351 return err2352 }2353 case "--no-gap":2354 opts.Gap = 02355 case "--ellipsis":2356 str, err := nextString(allArgs, &i, "ellipsis string required")2357 if err != nil {2358 return err
279 unmodified lines
2638 } else if match, value := optString(arg, "--header-lines="); match {2639 if opts.HeaderLines, err = atoi(value); err != nil {2640 return err2641 }2642 } else if match, value := optString(arg, "--gap="); match {2643 if opts.Gap, err = atoi(value); err != nil {2644 return err2645 }2646 } else if match, value := optString(arg, "--ellipsis="); match {2647 str := firstLine(value)2648 opts.Ellipsis = &str2649 } else if match, value := optString(arg, "--preview="); match {
360 unmodified lines
modified:src/terminal.go+40 added-21 removed
243 unmodified lines
244 keepRight bool245 hscroll bool246 hscrollOff int247 scrollOff int248 gap int249 wordRubout string250 wordNext string251 cx int252 cy int
572 unmodified lines
825 highlightLine: opts.CursorLine,826 headerVisible: true,827 headerFirst: opts.HeaderFirst,828 headerLines: opts.HeaderLines,829 gap: opts.Gap,830 header: []string{},831 header0: opts.Header,832 ansi: opts.Ansi,833 tabstop: opts.Tabstop,
303 unmodified lines
1137 }1138 return util.Max(t.window.Width()-(t.pointerLen+t.markerLen+1), 1)1139}11401141// Number of lines the item takes including the gap1142func (t *Terminal) numItemLines(item *Item, atMost int) (int, bool) {1143 var numLines int1144 if !t.wrap && !t.multiLine {1141 return 1, false1145 numLines = 1 + t.gap1146 return numLines, numLines > atMost1147 }1148 var overflow bool1149 if !t.wrap && t.multiLine {1144 return item.text.NumLines(atMost)1150 numLines, overflow = item.text.NumLines(atMost)1151 } else {1152 var lines [][]rune1153 lines, overflow = item.text.Lines(t.multiLine, atMost, t.wrapCols(), t.wrapSignWidth, t.tabstop)1154 numLines = len(lines)1155 }1146 lines, overflow := item.text.Lines(t.multiLine, atMost, t.wrapCols(), t.wrapSignWidth, t.tabstop)1147 return len(lines), overflow1156 numLines += t.gap1157 return numLines, overflow || numLines > atMost1158}11591160func (t *Terminal) itemLines(item *Item, atMost int) ([][]rune, bool) {1161 if !t.wrap && !t.multiLine {
897 unmodified lines
2059 }2060 t.wrap = wrap2061}20622063func (t *Terminal) canSpanMultiLines() bool {2064 return t.multiLine || t.wrap || t.gap > 02065}20662067func (t *Terminal) renderEmptyLine(line int, barRange [2]int) {2068 t.move(line, 0, true)2069 t.markEmptyLine(line)2070 // If the screen is not filled with the list in non-multi-line mode,2071 // scrollbar is not visible at all. But in multi-line mode, we may need2072 // to redraw the scrollbar character at the end.2073 if t.canSpanMultiLines() {2074 t.prevLines[line].hasBar = t.printBar(line, true, barRange)2075 }2076}20772078func (t *Terminal) printList() {2079 t.constrain()2080 barLength, barStart := t.getScrollbar()2081
12 unmodified lines
2094 if itemCount < count {2095 item := t.merger.Get(itemCount + t.offset)2096 line = t.printItem(item, line, maxy, itemCount, itemCount == t.cy-t.offset, barRange)2097 } else if !t.prevLines[line].empty {2073 t.move(line, 0, true)2074 t.markEmptyLine(line)2075 // If the screen is not filled with the list in non-multi-line mode,2076 // scrollbar is not visible at all. But in multi-line mode, we may need2077 // to redraw the scrollbar character at the end.2078 if t.multiLine || t.wrap {2079 t.prevLines[line].hasBar = t.printBar(line, true, barRange)2080 }2098 t.renderEmptyLine(line, barRange)2099 }2100 }2101}2102
39 unmodified lines
2142 prevLine.label == newLine.label &&2143 prevLine.queryLen == newLine.queryLen &&2144 prevLine.result == newLine.result {2145 t.prevLines[line].hasBar = printBar(line, false)2128 if !t.multiLine && !t.wrap {2129 return line2130 }2146 return line + numLines - 12147 }21482149 maxWidth := t.window.Width() - (t.pointerLen + t.markerLen + 1)
78 unmodified lines
2228 match = tui.ColMatch2229 }2230 finalLineNum = t.printHighlighted(result, base, match, false, true, line, maxLine, forceRedraw, preTask, postTask)2231 }2232 for i := 0; i < t.gap && finalLineNum < maxLine; i++ {2233 finalLineNum++2234 t.renderEmptyLine(finalLineNum, barRange)2235 }2236 return finalLineNum2237}22382239func (t *Terminal) trimRight(runes []rune, width int) ([]rune, bool) {
53 unmodified lines
2293 }2294 allOffsets := result.colorOffsets(charOffsets, t.theme, colBase, colMatch, current)22952296 maxLines := 12278 if t.multiLine || t.wrap {2297 if t.canSpanMultiLines() {2298 maxLines = maxLineNum - lineNum + 12299 }2300 lines, overflow := t.itemLines(item, maxLines)2301 numItemLines := len(lines)
1 unmodified line
2303 finalLineNum := lineNum2304 topCutoff := false2305 skipLines := 02306 wrapped := false2288 if t.multiLine || t.wrap {2307 if t.canSpanMultiLines() {2308 // Cut off the upper lines in the 'default' layout2309 if t.layout == layoutDefault && !current && maxLines == numItemLines && overflow {2310 lines, _ = t.itemLines(item, math.MaxInt)2311
2581 unmodified lines
4893 t.offset = util.Constrain(t.offset, 0, count)4894 for tries := 0; tries < maxLines; tries++ {4895 numItems := maxLines4896 // How many items can be fit on screen including the current item?4878 if (t.multiLine || t.wrap) && t.merger.Length() > 0 {4897 if t.canSpanMultiLines() && t.merger.Length() > 0 {4898 numItemsFound := 04899 linesSum := 049004901 add := func(i int) bool {
46 unmodified lines
4948 for phase := 0; phase < 2; phase++ {4949 for {4950 prevOffset := newOffset4951 numItems := t.merger.Length()4933 itemLines := 14934 if (t.multiLine || t.wrap) && t.cy < numItems {4952 itemLines := 1 + t.gap4953 if t.canSpanMultiLines() && t.cy < numItems {4954 itemLines, _ = t.numItemLines(t.merger.Get(t.cy).item, maxLines)4955 }4956 linesBefore := t.cy - newOffset4938 if t.multiLine || t.wrap {4957 if t.canSpanMultiLines() {4958 linesBefore = 04959 for i := newOffset; i < t.cy && i < numItems; i++ {4960 lines, _ := t.numItemLines(t.merger.Get(i).item, maxLines-linesBefore-itemLines)4961 linesBefore += lines
126 unmodified lines
modified:test/test_go.rb+34 added
3390 unmodified lines
3391 assert lines[1]&.start_with?('│ 1')3392 assert lines[1]&.end_with?('1000││')3393 end3394 end33953396 def test_gap3397 tmux.send_keys %[seq 100 | #{FZF} --gap --border --reverse], :Enter3398 block = <<~BLOCK3399 ╭─────────────────3400 │ >3401 │ 100/100 ──────3402 │ > 13403 │3404 │ 23405 │3406 │ 33407 │3408 │ 43409 BLOCK3410 tmux.until { assert_block(block, _1) }3411 end34123413 def test_gap_23414 tmux.send_keys %[seq 100 | #{FZF} --gap=2 --border --reverse], :Enter3415 block = <<~BLOCK3416 ╭─────────────────3417 │ >3418 │ 100/100 ──────3419 │ > 13420 │3421 │3422 │ 23423 │3424 │3425 │ 33426 BLOCK3427 tmux.until { assert_block(block, _1) }3428 end3429end34303431module TestShell3432 def setup
520 unmodified lines
modified:CHANGELOG.md+15 added
1CHANGELOG2=========340.56.05------6- Added `--gap[=N]` option to display empty lines between items.7 - This can be useful to visually separate adjacent multi-line items.8 ```sh9 # All bash functions, highlighted10 declare -f | perl -0777 -pe 's/^}\n/}\0/gm' |11 bat --plain --language bash --color always |12 fzf --read0 --ansi --reverse --multi --highlight-line --gap13 ```14 - Or just to make the list easier to read. For single-line items, you probably want to set `--color gutter:-1` as well to hide the gutter.15 ```sh16 fzf --gap --color gutter:-117 ```18190.55.020------21_Release highlights: https://junegunn.github.io/fzf/releases/0.55.0/_22
2274 unmodified lines