Skip to content
Myr

Allow putting border label on the bottom line

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

Related #3022

authored by Junegunn Choi · committed by Junegunn Choi · parent 31bbaad · Browse files · 4 files+229 added−177 removed
This commit

State

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

Diff stats

4 files+229 added−177 removed

  • other:+229 added−177 removed

4 files+229 added−177 removed

modified:man/man1/fzf.1+38 added-10 removed
248 unmodified lines
249 # (with https://github.com/busyloop/lolcat)250 label=$(curl -s http://metaphorpsum.com/sentences/1 | lolcat -f)251252 # Border label at the center253 fzf --height=10 --border-label="╢ $label ╟" --border --color=label:italic:black253 fzf --height=10 --border --border-label="╢ $label ╟" --color=label:italic:black254255 # Left-aligned (positive integer)256 fzf --height=10 --border-label="╢ $label ╟" --border=top --border-label-pos=3 --color=label:italic:black256 fzf --height=10 --border --border-label="╢ $label ╟" --border-label-pos=3 --color=label:italic:black257258 # Right-aligned (negative integer)259 fzf --height=10 --border-label="╢ $label ╟" --border=bottom --border-label-pos=-3 --color=label:italic:black\fR258 # Right-aligned (negative integer) on the bottom line (:bottom)259 fzf --height=10 --border --border-label="╢ $label ╟" --border-label-pos=-3:bottom --color=label:italic:black\fR260261.TP262.BI "--border-label-pos" [=COL]263Horizontal position of the border label on the border line. Specify a positive264integer as the column position from the left. Specify a negative integer to265right-align the label. The default value 0 (or \fBcenter\fR) will put266the label at the center of the border line.262.BI "--border-label-pos" [=N[:top|bottom]]263Position of the border label on the border line. Specify a positive integer as264the column position from the left. Specify a negative integer to right-align265the label. Label is printed on the top border line by default, add266\fB:bottom\fR to put it on the border line on the bottom. The default value267\fB0 (or \fBcenter\fR) will put the label at the center of the border line.268269.TP270.B "--no-unicode"271Use ASCII characters instead of Unicode box drawing characters to draw border
124 unmodified lines
396 \fBdisabled \fRQuery string when search is disabled397 \fBinfo \fRInfo line (match counters)398 \fBseparator \fRHorizontal separator on info line (match counters)399 \fBborder \fRBorder around the window (\fB--border\fR and \fB--preview\fR)399 \fBlabel \fRBorder label (\fB--border-label\fR)400 \fBlabel \fRBorder label (\fB--border-label\fR and \fB--preview-label\fR)401 \fBprompt \fRPrompt402 \fBpointer \fRPointer to the current line403 \fBmarker \fRMulti-select marker404 \fBspinner \fRStreaming input indicator
122 unmodified lines
527 echo "$i"528 sleep 0.01529 done'\fR530.RE531532.TP533.BI "--preview-label" [=LABEL]534Label to print on the horizontal border line of the preview window.535Should be used with one of the following \fB--preview-window\fR options.536537.br538.B * border-rounded (default)539.br540.B * border-sharp541.br542.B * border-horizontal543.br544.B * border-top545.br546.B * border-bottom547.br548549.TP550.BI "--preview-label-pos" [=N[:top|bottom]]551Position of the border label on the border line of the preview window. Specify552a positive integer as the column position from the left. Specify a negative553integer to right-align the label. Label is printed on the top border line by554default, add \fB:bottom\fR to put it on the border line on the bottom. The555default value 0 (or \fBcenter\fR) will put the label at the center of the556border line.557558.TP559.BI "--preview-window=" "[POSITION][,SIZE[%]][,border-BORDER_OPT][,[no]wrap][,[no]follow][,[no]cycle][,[no]hidden][,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES][,default][,<SIZE_THRESHOLD(ALTERNATIVE_LAYOUT)]"560561.RS562.B POSITION: (default: right)
558 unmodified lines
modified:src/options.go+160 added-138 removed
64 unmodified lines
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)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]]74 --prompt=STR Input prompt (default: '> ')
22 unmodified lines
97 [,border-BORDER_OPT]98 [,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES]99 [,default][,<SIZE_THRESHOLD(ALTERNATIVE_LAYOUT)]100 --preview-label=LABEL100 --preview-label-pos=COL101 --preview-label-pos=N Same as --border-label and --border-label-pos,102 but for preview window103104 Scripting105 -q, --query=STR Start the finder with the given query106 -1, --select-1 Automatically select the only match
77 unmodified lines
184 infoInline185 infoHidden186)187188type labelOpts struct {189 label string190 column int191 bottom bool192}193194type previewOpts struct {195 command string196 position windowPosition197 size sizeSpec
7 unmodified lines
205 threshold int206 alternative *previewOpts207}208201func parseLabelPosition(arg string) int {202 if strings.ToLower(arg) == "center" {203 return 0209func parseLabelPosition(opts *labelOpts, arg string) {210 opts.column = 0211 opts.bottom = false212 for _, token := range splitRegexp.Split(strings.ToLower(arg), -1) {213 switch token {214 case "center":215 opts.column = 0216 case "bottom":217 opts.bottom = true218 case "top":219 opts.bottom = false220 default:221 opts.column = atoi(token)222 }223 }205 return atoi(arg)224}225226func (a previewOpts) aboveOrBelow() bool {227 return a.size.size > 0 && (a.position == posUp || a.position == posDown)
10 unmodified lines
238}239240// Options stores the values of command-line options241type Options struct {224 Fuzzy bool225 FuzzyAlgo algo.Algo226 Scheme string227 Extended bool228 Phony bool229 Case Case230 Normalize bool231 Nth []Range232 WithNth []Range233 Delimiter Delimiter234 Sort int235 Tac bool236 Criteria []criterion237 Multi int238 Ansi bool239 Mouse bool240 Theme *tui.ColorTheme241 Black bool242 Bold bool243 Height heightSpec244 MinHeight int245 Layout layoutType246 Cycle bool247 KeepRight bool248 Hscroll bool249 HscrollOff int250 ScrollOff int251 FileWord bool252 InfoStyle infoStyle253 JumpLabels string254 Prompt string255 Pointer string256 Marker string257 Query string258 Select1 bool259 Exit0 bool260 Filter *string261 ToggleSort bool262 Expect map[tui.Event]string263 Keymap map[tui.Event][]*action264 Preview previewOpts265 PrintQuery bool266 ReadZero bool267 Printer func(string)268 PrintSep string269 Sync bool270 History *History271 Header []string272 HeaderLines int273 HeaderFirst bool274 Ellipsis string275 Margin [4]sizeSpec276 Padding [4]sizeSpec277 BorderShape tui.BorderShape278 Label string279 LabelPos int280 PLabel string281 PLabelPos int282 Unicode bool283 Tabstop int284 ClearOnExit bool285 Version bool242 Fuzzy bool243 FuzzyAlgo algo.Algo244 Scheme string245 Extended bool246 Phony bool247 Case Case248 Normalize bool249 Nth []Range250 WithNth []Range251 Delimiter Delimiter252 Sort int253 Tac bool254 Criteria []criterion255 Multi int256 Ansi bool257 Mouse bool258 Theme *tui.ColorTheme259 Black bool260 Bold bool261 Height heightSpec262 MinHeight int263 Layout layoutType264 Cycle bool265 KeepRight bool266 Hscroll bool267 HscrollOff int268 ScrollOff int269 FileWord bool270 InfoStyle infoStyle271 JumpLabels string272 Prompt string273 Pointer string274 Marker string275 Query string276 Select1 bool277 Exit0 bool278 Filter *string279 ToggleSort bool280 Expect map[tui.Event]string281 Keymap map[tui.Event][]*action282 Preview previewOpts283 PrintQuery bool284 ReadZero bool285 Printer func(string)286 PrintSep string287 Sync bool288 History *History289 Header []string290 HeaderLines int291 HeaderFirst bool292 Ellipsis string293 Margin [4]sizeSpec294 Padding [4]sizeSpec295 BorderShape tui.BorderShape296 BorderLabel labelOpts297 PreviewLabel labelOpts298 Unicode bool299 Tabstop int300 ClearOnExit bool301 Version bool302}303304func defaultPreviewOpts(command string) previewOpts {305 return previewOpts{command, posRight, sizeSpec{50, true}, "", false, false, false, false, tui.BorderRounded, 0, 0, nil}306}307308func defaultOptions() *Options {309 return &Options{294 Fuzzy: true,295 FuzzyAlgo: algo.FuzzyMatchV2,296 Scheme: "default",297 Extended: true,298 Phony: false,299 Case: CaseSmart,300 Normalize: true,301 Nth: make([]Range, 0),302 WithNth: make([]Range, 0),303 Delimiter: Delimiter{},304 Sort: 1000,305 Tac: false,306 Criteria: []criterion{byScore, byLength},307 Multi: 0,308 Ansi: false,309 Mouse: true,310 Theme: tui.EmptyTheme(),311 Black: false,312 Bold: true,313 MinHeight: 10,314 Layout: layoutDefault,315 Cycle: false,316 KeepRight: false,317 Hscroll: true,318 HscrollOff: 10,319 ScrollOff: 0,320 FileWord: false,321 InfoStyle: infoStyle{layout: infoDefault, separator: true},322 JumpLabels: defaultJumpLabels,323 Prompt: "> ",324 Pointer: ">",325 Marker: ">",326 Query: "",327 Select1: false,328 Exit0: false,329 Filter: nil,330 ToggleSort: false,331 Expect: make(map[tui.Event]string),332 Keymap: make(map[tui.Event][]*action),333 Preview: defaultPreviewOpts(""),334 PrintQuery: false,335 ReadZero: false,336 Printer: func(str string) { fmt.Println(str) },337 PrintSep: "\n",338 Sync: false,339 History: nil,340 Header: make([]string, 0),341 HeaderLines: 0,342 HeaderFirst: false,343 Ellipsis: "..",344 Margin: defaultMargin(),345 Padding: defaultMargin(),346 Unicode: true,347 Tabstop: 8,348 Label: "",349 LabelPos: 0,350 PLabel: "",351 PLabelPos: 0,352 ClearOnExit: true,353 Version: false}310 Fuzzy: true,311 FuzzyAlgo: algo.FuzzyMatchV2,312 Scheme: "default",313 Extended: true,314 Phony: false,315 Case: CaseSmart,316 Normalize: true,317 Nth: make([]Range, 0),318 WithNth: make([]Range, 0),319 Delimiter: Delimiter{},320 Sort: 1000,321 Tac: false,322 Criteria: []criterion{byScore, byLength},323 Multi: 0,324 Ansi: false,325 Mouse: true,326 Theme: tui.EmptyTheme(),327 Black: false,328 Bold: true,329 MinHeight: 10,330 Layout: layoutDefault,331 Cycle: false,332 KeepRight: false,333 Hscroll: true,334 HscrollOff: 10,335 ScrollOff: 0,336 FileWord: false,337 InfoStyle: infoStyle{layout: infoDefault, separator: true},338 JumpLabels: defaultJumpLabels,339 Prompt: "> ",340 Pointer: ">",341 Marker: ">",342 Query: "",343 Select1: false,344 Exit0: false,345 Filter: nil,346 ToggleSort: false,347 Expect: make(map[tui.Event]string),348 Keymap: make(map[tui.Event][]*action),349 Preview: defaultPreviewOpts(""),350 PrintQuery: false,351 ReadZero: false,352 Printer: func(str string) { fmt.Println(str) },353 PrintSep: "\n",354 Sync: false,355 History: nil,356 Header: make([]string, 0),357 HeaderLines: 0,358 HeaderFirst: false,359 Ellipsis: "..",360 Margin: defaultMargin(),361 Padding: defaultMargin(),362 Unicode: true,363 Tabstop: 8,364 BorderLabel: labelOpts{},365 PreviewLabel: labelOpts{},366 ClearOnExit: true,367 Version: false}368}369370func help(code int) {371 os.Stdout.WriteString(usage)
488 unmodified lines
860 }861 return theme862}863864var (850var executeRegexp *regexp.Regexp865 executeRegexp *regexp.Regexp866 splitRegexp *regexp.Regexp867)868869func firstKey(keymap map[tui.Event]string) tui.Event {870 for k := range keymap {871 return k
11 unmodified lines
883 // Backreferences are not supported.884 // "~!@#$%^&*;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')885 executeRegexp = regexp.MustCompile(886 `(?si)[:+](execute(?:-multi|-silent)?|reload|preview|change-prompt|change-preview-window|change-preview|(?:re|un)bind):.+|[:+](execute(?:-multi|-silent)?|reload|preview|change-prompt|change-preview-window|change-preview|(?:re|un)bind)(\([^)]*\)|\[[^\]]*\]|~[^~]*~|![^!]*!|@[^@]*@|\#[^\#]*\#|\$[^\$]*\$|%[^%]*%|\^[^\^]*\^|&[^&]*&|\*[^\*]*\*|;[^;]*;|/[^/]*/|\|[^\|]*\|)`)887 splitRegexp = regexp.MustCompile("[,:]+")888}889890func parseKeymap(keymap map[tui.Event][]*action, str string) {891 masked := executeRegexp.ReplaceAllStringFunc(str, func(src string) string {
354 unmodified lines
1246func parseInfoStyle(str string) infoStyle {1247 layout := infoDefault1248 separator := true12491232 for _, token := range regexp.MustCompile("[,:]").Split(strings.ToLower(str), -1) {1250 for _, token := range splitRegexp.Split(strings.ToLower(str), -1) {1251 switch token {1252 case "default":1253 layout = infoDefault1254 case "inline":
356 unmodified lines
1611 opts.BorderShape = tui.BorderNone1612 case "--border":1613 hasArg, arg := optionalNextString(allArgs, &i)1614 opts.BorderShape = parseBorder(arg, !hasArg)1615 case "--no-border-label":1616 opts.BorderLabel.label = ""1617 case "--border-label":1598 opts.Label = nextString(allArgs, &i, "label required")1618 opts.BorderLabel.label = nextString(allArgs, &i, "label required")1619 case "--border-label-pos":1620 pos := nextString(allArgs, &i, "label position required (positive or negative integer or 'center')")1601 opts.LabelPos = parseLabelPosition(pos)1621 parseLabelPosition(&opts.BorderLabel, pos)1622 case "--no-preview-label":1623 opts.PreviewLabel.label = ""1624 case "--preview-label":1603 opts.PLabel = nextString(allArgs, &i, "preview label required")1625 opts.PreviewLabel.label = nextString(allArgs, &i, "preview label required")1626 case "--preview-label-pos":1627 pos := nextString(allArgs, &i, "preview label position required (positive or negative integer or 'center')")1606 opts.PLabelPos = parseLabelPosition(pos)1628 parseLabelPosition(&opts.PreviewLabel, pos)1629 case "--no-unicode":1630 opts.Unicode = false1631 case "--unicode":1632 opts.Unicode = true
28 unmodified lines
1661 opts.Delimiter = delimiterRegexp(value)1662 } else if match, value := optString(arg, "--border="); match {1663 opts.BorderShape = parseBorder(value, false)1664 } else if match, value := optString(arg, "--border-label="); match {1643 opts.Label = value1665 opts.BorderLabel.label = value1666 } else if match, value := optString(arg, "--border-label-pos="); match {1645 opts.LabelPos = parseLabelPosition(value)1667 parseLabelPosition(&opts.BorderLabel, value)1668 } else if match, value := optString(arg, "--preview-label="); match {1647 opts.PLabel = value1669 opts.PreviewLabel.label = value1670 } else if match, value := optString(arg, "--preview-label-pos="); match {1649 opts.PLabelPos = parseLabelPosition(value)1671 parseLabelPosition(&opts.PreviewLabel, value)1672 } else if match, value := optString(arg, "--prompt="); match {1673 opts.Prompt = value1674 } else if match, value := optString(arg, "--pointer="); match {1675 opts.Pointer = value
250 unmodified lines
modified:src/terminal.go+24 added-25 removed
112 unmodified lines
113 infoStyle infoStyle114 spinner []string115 prompt func()116 promptLen int117 borderLabel func()117 borderLabel func(tui.Window)118 borderLabelLen int119 borderLabelPos int120 previewLabel func()119 borderLabelOpts labelOpts120 previewLabel func(tui.Window)121 previewLabelLen int122 previewLabelPos int122 previewLabelOpts labelOpts123 pointer string124 pointerLen int125 pointerEmpty string126 marker string
423 unmodified lines
550 padding: opts.Padding,551 unicode: opts.Unicode,552 borderShape: opts.BorderShape,553 borderLabel: nil,554 borderLabelPos: opts.LabelPos,554 borderLabelOpts: opts.BorderLabel,555 previewLabel: nil,556 previewLabelPos: opts.PLabelPos,556 previewLabelOpts: opts.PreviewLabel,557 cleanExit: opts.ClearOnExit,558 paused: opts.Phony,559 strong: strongAttr,560 cycle: opts.Cycle,
35 unmodified lines
596 t.marker, t.markerLen = t.processTabs([]rune(opts.Marker), 0)597 // Pre-calculated empty pointer and marker signs598 t.pointerEmpty = strings.Repeat(" ", t.pointerLen)599 t.markerEmpty = strings.Repeat(" ", t.markerLen)600 if len(opts.Label) > 0 {601 t.borderLabel, t.borderLabelLen = t.parseBorderLabel(opts.Label)602 }603 if len(opts.PLabel) > 0 {604 t.previewLabel, t.previewLabelLen = t.parseBorderLabel(opts.PLabel)605 }600 t.borderLabel, t.borderLabelLen = t.parseBorderLabel(opts.BorderLabel.label)601 t.previewLabel, t.previewLabelLen = t.parseBorderLabel(opts.PreviewLabel.label)602603 return &t604}605
22 unmodified lines
628 fit := screenHeight - padHeight - t.extraLines()629 return fit, padHeight630}631636func (t *Terminal) parseBorderLabel(borderLabel string) (func(), int) {632func (t *Terminal) parseBorderLabel(borderLabel string) (func(tui.Window), int) {633 if len(borderLabel) == 0 {634 return nil, 0635 }636 text, colors, _ := extractColor(borderLabel, nil, nil)637 runes := []rune(text)638 item := &Item{text: util.RunesToChars(runes), colors: colors}639 result := Result{item: item}640641 var offsets []colorOffset643 borderLabelFn := func() {642 borderLabelFn := func(window tui.Window) {643 if offsets == nil {644 // tui.Col* are not initialized until renderer.Init()645 offsets = result.colorOffsets(nil, t.theme, tui.ColBorderLabel, tui.ColBorderLabel, false)646 }648 text, _ := t.trimRight(runes, t.border.Width())649 t.printColoredString(t.border, text, offsets, tui.ColBorderLabel)647 text, _ := t.trimRight(runes, window.Width())648 t.printColoredString(window, text, offsets, tui.ColBorderLabel)649 }650 borderLabelLen := runewidth.StringWidth(text)651 return borderLabelFn, borderLabelLen652}
397 unmodified lines
1050 height, false, noBorder)1051 }10521053 // Print border label1055 printLabel := func(window tui.Window, render func(), pos int, length int, borderShape tui.BorderShape) {1054 printLabel := func(window tui.Window, render func(tui.Window), opts labelOpts, length int, borderShape tui.BorderShape) {1055 if window == nil || render == nil {1056 return1057 }10581059 switch borderShape {1060 case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp:1061 var col int1063 if pos == 0 {1062 if opts.column == 0 {1063 col = util.Max(0, (window.Width()-length)/2)1065 } else if pos < 0 {1066 col = util.Max(0, window.Width()+pos+1-length)1064 } else if opts.column < 0 {1065 col = util.Max(0, window.Width()+opts.column+1-length)1066 } else {1068 col = util.Min(pos-1, window.Width()-length)1067 col = util.Min(opts.column-1, window.Width()-length)1068 }1069 row := 01071 if borderShape == tui.BorderBottom {1070 if borderShape == tui.BorderBottom || opts.bottom {1071 row = window.Height() - 11072 }1073 window.Move(row, col)1075 render()1074 render(window)1075 }1076 }1078 printLabel(t.border, t.borderLabel, t.borderLabelPos, t.borderLabelLen, t.borderShape)1079 printLabel(t.pborder, t.previewLabel, t.previewLabelPos, t.previewLabelLen, t.previewOpts.border)1077 printLabel(t.border, t.borderLabel, t.borderLabelOpts, t.borderLabelLen, t.borderShape)1078 printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.previewOpts.border)10791080 for i := 0; i < t.window.Height(); i++ {1081 t.window.MoveAndClear(i, 0)1082 }
2009 unmodified lines
modified:CHANGELOG.md+7 added-4 removed
14 unmodified lines
15 # (with https://github.com/busyloop/lolcat)16 label=$(curl -s http://metaphorpsum.com/sentences/1 | lolcat -f)1718 # Border label at the center19 fzf --height=10 --border-label="╢ $label ╟" --border --color=label:italic:black19 fzf --height=10 --border --border-label="╢ $label ╟" --color=label:italic:black2021 # Left-aligned (positive integer)22 fzf --height=10 --border-label="╢ $label ╟" --border=top --border-label-pos=3 --color=label:italic:black22 fzf --height=10 --border --border-label="╢ $label ╟" --border-label-pos=3 --color=label:italic:black2324 # Right-aligned (negative integer)25 fzf --height=10 --border-label="╢ $label ╟" --border=bottom --border-label-pos=-3 --color=label:italic:black24 # Right-aligned (negative integer) on the bottom line (:bottom)25 fzf --height=10 --border --border-label="╢ $label ╟" --border-label-pos=-3:bottom --color=label:italic:black26 ```27- Also added `--preview-label` and `--preview-label-pos` for the border of the28 ```sh29 fzf --preview 'cat {}' --border --preview-label=' Preview ' --preview-label-pos=230 ```31 preview window32- Info panel (counter) will be followed by a horizontal separator by default33 - The color of the separator can be customized via `--color=separator:...`34 - Separator can be disabled by adding `:nosep` to `--info`
1345 unmodified lines