Add --border-label and --border-label-pos
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #3022
authored by Junegunn Choi · committed by Junegunn Choi · parent 0de1aac · Browse files · 5 files·+233 added−86 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+233 added−86 removed
- other:+233 added−86 removed
Provenance
- Commit
e61585f- Tree
4c8df98- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
0de1aac
5 files changed+233 added−86 removed
modified:man/man1/fzf.1+40 added
225 unmodified lines226 .BR none227 .br228 229 .TP230+.BI "--border-label" [=LABEL]231+Label to print on the horizontal border line. Should be used with one of the232+following \fB--border\fR options.233+234+.br235+.B * rounded236+.br237+.B * sharp238+.br239+.B * horizontal240+.br241+.BR "* top" " (up)"242+.br243+.BR "* bottom" " (down)"244+.br245+246+.br247+e.g.248+ \fB# ANSI color codes are supported249+ # (with https://github.com/busyloop/lolcat)250+ label=$(curl -s http://metaphorpsum.com/sentences/1 | lolcat -f)251+252+ # Border label at the center253+ fzf --height=10 --border-label="╢ $label ╟" --border --color=label:italic:black254+255+ # Left-aligned (positive integer)256+ fzf --height=10 --border-label="╢ $label ╟" --border=top --border-label-pos=3 --color=label:italic:black257+258+ # Right-aligned (negative integer)259+ fzf --height=10 --border-label="╢ $label ╟" --border=bottom --border-label-pos=-3 --color=label:italic:black\fR260+261+.TP262+.BI "--border-label-pos" [=COL]263+Horizontal position of the border label on the border line. Specify a positive264+integer as the column position from the left. Specify a negative integer to265+right-align the label. The default value 0 (or \fBcenter\fR) will put266+the label at the center of the border line.267+268+.TP269 .B "--no-unicode"270 Use ASCII characters instead of Unicode box drawing characters to draw border271 272 .TP121 unmodified lines394 \fBquery \fRQuery string395 \fBdisabled \fRQuery string when search is disabled396 \fBinfo \fRInfo line (match counters)397 \fBborder \fRBorder around the window (\fB--border\fR and \fB--preview\fR)398+ \fBlabel \fRBorder label (\fB--border-label\fR)399 \fBprompt \fRPrompt400 \fBpointer \fRPointer to the current line401 \fBmarker \fRMulti-select marker402 \fBspinner \fRStreaming input indicator689 unmodified linesmodified:src/tui/tui.go+19 added-5 removed
266 unmodified lines267 Cursor ColorAttr268 Selected ColorAttr269 Header ColorAttr270 Border ColorAttr271+ BorderLabel ColorAttr272 }273 274 type Event struct {275 Type EventType165 unmodified lines441 ColHeader ColorPair442 ColBorder ColorPair443 ColPreview ColorPair444 ColPreviewBorder ColorPair445+ ColBorderLabel ColorPair446 )447 448 func EmptyTheme() *ColorTheme {449 return &ColorTheme{14 unmodified lines464 Info: ColorAttr{colUndefined, AttrUndefined},465 Cursor: ColorAttr{colUndefined, AttrUndefined},466 Selected: ColorAttr{colUndefined, AttrUndefined},467 Header: ColorAttr{colUndefined, AttrUndefined},466- Border: ColorAttr{colUndefined, AttrUndefined}}468+ Border: ColorAttr{colUndefined, AttrUndefined},469+ BorderLabel: ColorAttr{colUndefined, AttrUndefined},470+ }471 }472 473 func NoColorTheme() *ColorTheme {474 return &ColorTheme{14 unmodified lines489 Info: ColorAttr{colDefault, AttrRegular},490 Cursor: ColorAttr{colDefault, AttrRegular},491 Selected: ColorAttr{colDefault, AttrRegular},492 Header: ColorAttr{colDefault, AttrRegular},489- Border: ColorAttr{colDefault, AttrRegular}}493+ Border: ColorAttr{colDefault, AttrRegular},494+ BorderLabel: ColorAttr{colDefault, AttrRegular},495+ }496 }497 498 func errorExit(message string) {499 fmt.Fprintln(os.Stderr, message)19 unmodified lines519 Info: ColorAttr{colWhite, AttrUndefined},520 Cursor: ColorAttr{colRed, AttrUndefined},521 Selected: ColorAttr{colMagenta, AttrUndefined},522 Header: ColorAttr{colCyan, AttrUndefined},517- Border: ColorAttr{colBlack, AttrUndefined}}523+ Border: ColorAttr{colBlack, AttrUndefined},524+ BorderLabel: ColorAttr{colWhite, AttrUndefined},525+ }526 Dark256 = &ColorTheme{527 Colored: true,528 Input: ColorAttr{colDefault, AttrUndefined},529 Disabled: ColorAttr{colUndefined, AttrUndefined},11 unmodified lines541 Info: ColorAttr{144, AttrUndefined},542 Cursor: ColorAttr{161, AttrUndefined},543 Selected: ColorAttr{168, AttrUndefined},544 Header: ColorAttr{109, AttrUndefined},537- Border: ColorAttr{59, AttrUndefined}}545+ Border: ColorAttr{59, AttrUndefined},546+ BorderLabel: ColorAttr{145, AttrUndefined},547+ }548 Light256 = &ColorTheme{549 Colored: true,550 Input: ColorAttr{colDefault, AttrUndefined},551 Disabled: ColorAttr{colUndefined, AttrUndefined},11 unmodified lines563 Info: ColorAttr{101, AttrUndefined},564 Cursor: ColorAttr{161, AttrUndefined},565 Selected: ColorAttr{168, AttrUndefined},566 Header: ColorAttr{31, AttrUndefined},557- Border: ColorAttr{145, AttrUndefined}}567+ Border: ColorAttr{145, AttrUndefined},568+ BorderLabel: ColorAttr{59, AttrUndefined},569+ }570 }571 572 func initTheme(theme *ColorTheme, baseTheme *ColorTheme, forceBlack bool) {573 if forceBlack {27 unmodified lines601 theme.Cursor = o(baseTheme.Cursor, theme.Cursor)602 theme.Selected = o(baseTheme.Selected, theme.Selected)603 theme.Header = o(baseTheme.Header, theme.Header)604 theme.Border = o(baseTheme.Border, theme.Border)605+ theme.BorderLabel = o(baseTheme.BorderLabel, theme.BorderLabel)606 607 initPalette(theme)608 }609 24 unmodified lines634 ColSpinner = pair(theme.Spinner, theme.Bg)635 ColInfo = pair(theme.Info, theme.Bg)636 ColHeader = pair(theme.Header, theme.Bg)637 ColBorder = pair(theme.Border, theme.Bg)638+ ColBorderLabel = pair(theme.BorderLabel, theme.Bg)639 ColPreview = pair(theme.PreviewFg, theme.PreviewBg)640 ColPreviewBorder = pair(theme.Border, theme.PreviewBg)641 }modified:src/options.go+103 added-77 removed
16 unmodified lines17 18 const usage = `usage: fzf [options]19 20 Search21- -x, --extended Extended-search mode22- (enabled by default; +x or --no-extended to disable)23- -e, --exact Enable Exact-match24- -i Case-insensitive match (default: smart-case match)25- +i Case-sensitive match26- --scheme=SCHEME Scoring scheme [default|path|history]27- --literal Do not normalize latin script letters before matching28- -n, --nth=N[,..] Comma-separated list of field index expressions29- for limiting search scope. Each can be a non-zero30- integer or a range expression ([BEGIN]..[END]).31- --with-nth=N[,..] Transform the presentation of each line using32- field index expressions33- -d, --delimiter=STR Field delimiter regex (default: AWK-style)34- +s, --no-sort Do not sort the result35- --tac Reverse the order of the input36- --disabled Do not perform search37- --tiebreak=CRI[,..] Comma-separated list of sort criteria to apply38- when the scores are tied [length|chunk|begin|end|index]39- (default: length)21+ -x, --extended Extended-search mode22+ (enabled by default; +x or --no-extended to disable)23+ -e, --exact Enable Exact-match24+ -i Case-insensitive match (default: smart-case match)25+ +i Case-sensitive match26+ --scheme=SCHEME Scoring scheme [default|path|history]27+ --literal Do not normalize latin script letters before matching28+ -n, --nth=N[,..] Comma-separated list of field index expressions29+ for limiting search scope. Each can be a non-zero30+ integer or a range expression ([BEGIN]..[END]).31+ --with-nth=N[,..] Transform the presentation of each line using32+ field index expressions33+ -d, --delimiter=STR Field delimiter regex (default: AWK-style)34+ +s, --no-sort Do not sort the result35+ --tac Reverse the order of the input36+ --disabled Do not perform search37+ --tiebreak=CRI[,..] Comma-separated list of sort criteria to apply38+ when the scores are tied [length|chunk|begin|end|index]39+ (default: length)40 41 Interface42- -m, --multi[=MAX] Enable multi-select with tab/shift-tab43- --no-mouse Disable mouse44- --bind=KEYBINDS Custom key bindings. Refer to the man page.45- --cycle Enable cyclic scroll46- --keep-right Keep the right end of the line visible on overflow47- --scroll-off=LINES Number of screen lines to keep above or below when48- scrolling to the top or to the bottom (default: 0)49- --no-hscroll Disable horizontal scroll50- --hscroll-off=COLS Number of screen columns to keep to the right of the51- highlighted substring (default: 10)52- --filepath-word Make word-wise movements respect path separators53- --jump-labels=CHARS Label characters for jump and jump-accept42+ -m, --multi[=MAX] Enable multi-select with tab/shift-tab43+ --no-mouse Disable mouse44+ --bind=KEYBINDS Custom key bindings. Refer to the man page.45+ --cycle Enable cyclic scroll46+ --keep-right Keep the right end of the line visible on overflow47+ --scroll-off=LINES Number of screen lines to keep above or below when48+ scrolling to the top or to the bottom (default: 0)49+ --no-hscroll Disable horizontal scroll50+ --hscroll-off=COLS Number of screen columns to keep to the right of the51+ highlighted substring (default: 10)52+ --filepath-word Make word-wise movements respect path separators53+ --jump-labels=CHARS Label characters for jump and jump-accept54 55 Layout56- --height=[~]HEIGHT[%] Display fzf window below the cursor with the given57- height instead of using fullscreen.58- If prefixed with '~', fzf will determine the height59- according to the input size.60- --min-height=HEIGHT Minimum height when --height is given in percent61- (default: 10)62- --layout=LAYOUT Choose layout: [default|reverse|reverse-list]63- --border[=STYLE] Draw border around the finder64- [rounded|sharp|horizontal|vertical|65- top|bottom|left|right|none] (default: rounded)66- --margin=MARGIN Screen margin (TRBL | TB,RL | T,RL,B | T,R,B,L)67- --padding=PADDING Padding inside border (TRBL | TB,RL | T,RL,B | T,R,B,L)68- --info=STYLE Finder info style [default|inline|hidden]69- --prompt=STR Input prompt (default: '> ')70- --pointer=STR Pointer to the current line (default: '>')71- --marker=STR Multi-select marker (default: '>')72- --header=STR String to print as header73- --header-lines=N The first N lines of the input are treated as header74- --header-first Print header before the prompt line75- --ellipsis=STR Ellipsis to show when line is truncated (default: '..')56+ --height=[~]HEIGHT[%] Display fzf window below the cursor with the given57+ height instead of using fullscreen.58+ If prefixed with '~', fzf will determine the height59+ according to the input size.60+ --min-height=HEIGHT Minimum height when --height is given in percent61+ (default: 10)62+ --layout=LAYOUT Choose layout: [default|reverse|reverse-list]63+ --border[=STYLE] Draw border around the finder64+ [rounded|sharp|horizontal|vertical|65+ top|bottom|left|right|none] (default: rounded)66+ --border-label=LABEL Label to print on the border67+ --border-label-pos=COL Position of the border label68+ [POSITIVE_INTEGER: columns from left|69+ NEGATIVE_INTEGER: columns from right] (default: 0)70+ --margin=MARGIN Screen margin (TRBL | TB,RL | T,RL,B | T,R,B,L)71+ --padding=PADDING Padding inside border (TRBL | TB,RL | T,RL,B | T,R,B,L)72+ --info=STYLE Finder info style [default|inline|hidden]73+ --prompt=STR Input prompt (default: '> ')74+ --pointer=STR Pointer to the current line (default: '>')75+ --marker=STR Multi-select marker (default: '>')76+ --header=STR String to print as header77+ --header-lines=N The first N lines of the input are treated as header78+ --header-first Print header before the prompt line79+ --ellipsis=STR Ellipsis to show when line is truncated (default: '..')80 81 Display78- --ansi Enable processing of ANSI color codes79- --tabstop=SPACES Number of spaces for a tab character (default: 8)80- --color=COLSPEC Base scheme (dark|light|16|bw) and/or custom colors81- --no-bold Do not use bold text82+ --ansi Enable processing of ANSI color codes83+ --tabstop=SPACES Number of spaces for a tab character (default: 8)84+ --color=COLSPEC Base scheme (dark|light|16|bw) and/or custom colors85+ --no-bold Do not use bold text86 87 History84- --history=FILE History file85- --history-size=N Maximum number of history entries (default: 1000)88+ --history=FILE History file89+ --history-size=N Maximum number of history entries (default: 1000)90 91 Preview88- --preview=COMMAND Command to preview highlighted line ({})89- --preview-window=OPT Preview window layout (default: right:50%)90- [up|down|left|right][,SIZE[%]]91- [,[no]wrap][,[no]cycle][,[no]follow][,[no]hidden]92- [,border-BORDER_OPT]93- [,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES]94- [,default][,<SIZE_THRESHOLD(ALTERNATIVE_LAYOUT)]92+ --preview=COMMAND Command to preview highlighted line ({})93+ --preview-window=OPT Preview window layout (default: right:50%)94+ [up|down|left|right][,SIZE[%]]95+ [,[no]wrap][,[no]cycle][,[no]follow][,[no]hidden]96+ [,border-BORDER_OPT]97+ [,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES]98+ [,default][,<SIZE_THRESHOLD(ALTERNATIVE_LAYOUT)]99 100 Scripting97- -q, --query=STR Start the finder with the given query98- -1, --select-1 Automatically select the only match99- -0, --exit-0 Exit immediately when there's no match100- -f, --filter=STR Filter mode. Do not start interactive finder.101- --print-query Print query as the first line102- --expect=KEYS Comma-separated list of keys to complete fzf103- --read0 Read input delimited by ASCII NUL characters104- --print0 Print output delimited by ASCII NUL characters105- --sync Synchronous search for multi-staged filtering106- --version Display version information and exit101+ -q, --query=STR Start the finder with the given query102+ -1, --select-1 Automatically select the only match103+ -0, --exit-0 Exit immediately when there's no match104+ -f, --filter=STR Filter mode. Do not start interactive finder.105+ --print-query Print query as the first line106+ --expect=KEYS Comma-separated list of keys to complete fzf107+ --read0 Read input delimited by ASCII NUL characters108+ --print0 Print output delimited by ASCII NUL characters109+ --sync Synchronous search for multi-staged filtering110+ --version Display version information and exit111 112 Environment variables109- FZF_DEFAULT_COMMAND Default command to use when input is tty110- FZF_DEFAULT_OPTS Default options111- (e.g. '--layout=reverse --inline-info')113+ FZF_DEFAULT_COMMAND Default command to use when input is tty114+ FZF_DEFAULT_OPTS Default options115+ (e.g. '--layout=reverse --inline-info')116 117 `118 119 // Case denotes case-sensitivity of search71 unmodified lines191 threshold int192 alternative *previewOpts193 }194 195+func parseLabelPosition(arg string) int {196+ if strings.ToLower(arg) == "center" {197+ return 0198+ }199+ return atoi(arg)200+}201+202 func (a previewOpts) aboveOrBelow() bool {203 return a.size.size > 0 && (a.position == posUp || a.position == posDown)204 }205 62 unmodified lines268 Ellipsis string269 Margin [4]sizeSpec270 Padding [4]sizeSpec271 BorderShape tui.BorderShape272+ Label string273+ LabelPos int274 Unicode bool275 Tabstop int276 ClearOnExit bool277 Version bool58 unmodified lines336 Margin: defaultMargin(),337 Padding: defaultMargin(),338 Unicode: true,339 Tabstop: 8,340+ Label: "",341+ LabelPos: 0,342 ClearOnExit: true,343 Version: false}344 }345 466 unmodified lines812 case "hl+":813 mergeAttr(&theme.CurrentMatch)814 case "border":815 mergeAttr(&theme.Border)816+ case "label":817+ mergeAttr(&theme.BorderLabel)818 case "prompt":819 mergeAttr(&theme.Prompt)820 case "spinner":821 mergeAttr(&theme.Spinner)750 unmodified lines1572 opts.BorderShape = tui.BorderNone1573 case "--border":1574 hasArg, arg := optionalNextString(allArgs, &i)1575 opts.BorderShape = parseBorder(arg, !hasArg)1576+ case "--border-label":1577+ opts.Label = nextString(allArgs, &i, "label required")1578+ case "--border-label-pos":1579+ pos := nextString(allArgs, &i, "label position required (positive or negative integer or 'center')")1580+ opts.LabelPos = parseLabelPosition(pos)1581 case "--no-unicode":1582 opts.Unicode = false1583 case "--unicode":1584 opts.Unicode = true27 unmodified lines1612 } else if match, value := optString(arg, "-d", "--delimiter="); match {1613 opts.Delimiter = delimiterRegexp(value)1614 } else if match, value := optString(arg, "--border="); match {1615 opts.BorderShape = parseBorder(value, false)1616+ } else if match, value := optString(arg, "--border-label="); match {1617+ opts.Label = value1618+ } else if match, value := optString(arg, "--border-label-pos="); match {1619+ opts.LabelPos = parseLabelPosition(value)1620 } else if match, value := optString(arg, "--prompt="); match {1621 opts.Prompt = value1622 } else if match, value := optString(arg, "--pointer="); match {1623 opts.Pointer = value250 unmodified linesmodified:src/terminal.go+56 added-4 removed
112 unmodified lines113 infoStyle infoStyle114 spinner []string115 prompt func()116 promptLen int117+ borderLabel func()118+ borderLabelLen int119+ borderLabelPos int120 pointer string121 pointerLen int122 pointerEmpty string123 marker string422 unmodified lines546 margin: opts.Margin,547 padding: opts.Padding,548 unicode: opts.Unicode,549 borderShape: opts.BorderShape,550+ borderLabel: nil,551+ borderLabelPos: opts.LabelPos,552 cleanExit: opts.ClearOnExit,553 paused: opts.Phony,554 strong: strongAttr,555 cycle: opts.Cycle,35 unmodified lines591 t.marker, t.markerLen = t.processTabs([]rune(opts.Marker), 0)592 // Pre-calculated empty pointer and marker signs593 t.pointerEmpty = strings.Repeat(" ", t.pointerLen)594 t.markerEmpty = strings.Repeat(" ", t.markerLen)595+ if len(opts.Label) > 0 {596+ t.borderLabel, t.borderLabelLen = t.parseBorderLabel(opts.Label)597+ }598 599 return &t600 }601 22 unmodified lines624 fit := screenHeight - padHeight - t.extraLines()625 return fit, padHeight626 }627 628+func (t *Terminal) parseBorderLabel(borderLabel string) (func(), int) {629+ text, colors, _ := extractColor(borderLabel, nil, nil)630+ runes := []rune(text)631+ item := &Item{text: util.RunesToChars(runes), colors: colors}632+ result := Result{item: item}633+634+ var offsets []colorOffset635+ borderLabelFn := func() {636+ if offsets == nil {637+ // tui.Col* are not initialized until renderer.Init()638+ offsets = result.colorOffsets(nil, t.theme, tui.ColBorderLabel, tui.ColBorderLabel, false)639+ }640+ text, _ := t.trimRight(runes, t.border.Width())641+ t.printColoredString(t.border, text, offsets, tui.ColBorderLabel)642+ }643+ borderLabelLen := runewidth.StringWidth(text)644+ return borderLabelFn, borderLabelLen645+}646+647 func (t *Terminal) parsePrompt(prompt string) (func(), int) {648 var state *ansiState649 trimmed, colors, _ := extractColor(prompt, state, nil)650 item := &Item{text: util.ToChars([]byte(trimmed)), colors: colors}286 unmodified lines937 marginInt[0]-1, marginInt[3]-2, width+4, height+2,938 false, tui.MakeBorderStyle(t.borderShape, t.unicode))939 }940 941+ // Print border label942+ if t.border != nil && t.borderLabel != nil {943+ switch t.borderShape {944+ case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp:945+ var col int946+ if t.borderLabelPos == 0 {947+ col = util.Max(0, (t.border.Width()-t.borderLabelLen)/2)948+ } else if t.borderLabelPos < 0 {949+ col = util.Max(0, t.border.Width()+t.borderLabelPos+1-t.borderLabelLen)950+ } else {951+ col = util.Min(t.borderLabelPos-1, t.border.Width()-t.borderLabelLen)952+ }953+ row := 0954+ if t.borderShape == tui.BorderBottom {955+ row = t.border.Height() - 1956+ }957+ t.border.Move(row, col)958+ t.borderLabel()959+ }960+ }961+962 // Add padding to margin963 for idx, val := range paddingInt {964 marginInt[idx] += val965 }475 unmodified lines1441 }1442 displayWidth = t.displayWidthWithLimit(text, 0, displayWidth)1443 }1444 1445+ t.printColoredString(t.window, text, offsets, colBase)1446+ return displayWidth1447+}1448+1449+func (t *Terminal) printColoredString(window tui.Window, text []rune, offsets []colorOffset, colBase tui.ColorPair) {1450 var index int321451 var substr string1452 var prefixWidth int1453 maxOffset := int32(len(text))1 unmodified line1455 b := util.Constrain32(offset.offset[0], index, maxOffset)1456 e := util.Constrain32(offset.offset[1], index, maxOffset)1457 1458 substr, prefixWidth = t.processTabs(text[index:b], prefixWidth)1406- t.window.CPrint(colBase, substr)1459+ window.CPrint(colBase, substr)1460 1461 if b < e {1462 substr, prefixWidth = t.processTabs(text[b:e], prefixWidth)1410- t.window.CPrint(offset.color, substr)1463+ window.CPrint(offset.color, substr)1464 }1465 1466 index = e1467 if index >= maxOffset {1 unmodified line1469 }1470 }1471 if index < maxOffset {1472 substr, _ = t.processTabs(text[index:], prefixWidth)1420- t.window.CPrint(colBase, substr)1473+ window.CPrint(colBase, substr)1474 }1422- return displayWidth1475 }1476 1477 func (t *Terminal) renderPreviewSpinner() {1478 numLines := len(t.previewer.lines)1590 unmodified linesmodified:CHANGELOG.md+15 added
7 unmodified lines8 available unless you use `--sync`.9 ```sh10 seq 100 | fzf --multi --sync --bind 'start:last+select-all+preview(echo welcome)'11 ```12+- Added `--border-label` and `--border-label-pos` for putting label on the border13+ ```sh14+ # ANSI color codes are supported15+ # (with https://github.com/busyloop/lolcat)16+ label=$(curl -s http://metaphorpsum.com/sentences/1 | lolcat -f)17 18+ # Border label at the center19+ fzf --height=10 --border-label="╢ $label ╟" --border --color=label:italic:black20+21+ # Left-aligned (positive integer)22+ fzf --height=10 --border-label="╢ $label ╟" --border=top --border-label-pos=3 --color=label:italic:black23+24+ # Right-aligned (negative integer)25+ fzf --height=10 --border-label="╢ $label ╟" --border=bottom --border-label-pos=-3 --color=label:italic:black26+ ```27+28 0.34.029 ------30 - Added support for adaptive `--height`. If the `--height` value is prefixed31 with `~`, fzf will automatically determine the height in the range according1338 unmodified lines