Add --preview-label and --preview-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 b9ca1fe · Browse files · 3 files·+53 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
3 files+53 added−21 removed
- other:+53 added−21 removed
Provenance
- Commit
31bbaad- Tree
e751727- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
b9ca1fe
3 files changed+53 added−21 removed
modified:src/options.go+15 added
94 unmodified lines95 [,[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+ --preview-label=LABEL100+ --preview-label-pos=COL101 102 Scripting103 -q, --query=STR Start the finder with the given query104 -1, --select-1 Automatically select the only match171 unmodified lines276 Padding [4]sizeSpec277 BorderShape tui.BorderShape278 Label string279 LabelPos int280+ PLabel string281+ PLabelPos int282 Unicode bool283 Tabstop int284 ClearOnExit bool285 Version bool60 unmodified lines346 Unicode: true,347 Tabstop: 8,348 Label: "",349 LabelPos: 0,350+ PLabel: "",351+ PLabelPos: 0,352 ClearOnExit: true,353 Version: false}354 }355 1242 unmodified lines1598 opts.Label = nextString(allArgs, &i, "label required")1599 case "--border-label-pos":1600 pos := nextString(allArgs, &i, "label position required (positive or negative integer or 'center')")1601 opts.LabelPos = parseLabelPosition(pos)1602+ case "--preview-label":1603+ opts.PLabel = nextString(allArgs, &i, "preview label required")1604+ case "--preview-label-pos":1605+ pos := nextString(allArgs, &i, "preview label position required (positive or negative integer or 'center')")1606+ opts.PLabelPos = parseLabelPosition(pos)1607 case "--no-unicode":1608 opts.Unicode = false1609 case "--unicode":1610 opts.Unicode = true31 unmodified lines1642 } else if match, value := optString(arg, "--border-label="); match {1643 opts.Label = value1644 } else if match, value := optString(arg, "--border-label-pos="); match {1645 opts.LabelPos = parseLabelPosition(value)1646+ } else if match, value := optString(arg, "--preview-label="); match {1647+ opts.PLabel = value1648+ } else if match, value := optString(arg, "--preview-label-pos="); match {1649+ opts.PLabelPos = parseLabelPosition(value)1650 } else if match, value := optString(arg, "--prompt="); match {1651 opts.Prompt = value1652 } else if match, value := optString(arg, "--pointer="); match {1653 opts.Pointer = value250 unmodified linesmodified:src/terminal.go+36 added-21 removed
115 unmodified lines116 promptLen int117 borderLabel func()118 borderLabelLen int119 borderLabelPos int120+ previewLabel func()121+ previewLabelLen int122+ previewLabelPos int123 pointer string124 pointerLen int125 pointerEmpty string126 marker string424 unmodified lines551 unicode: opts.Unicode,552 borderShape: opts.BorderShape,553 borderLabel: nil,554 borderLabelPos: opts.LabelPos,555+ previewLabel: nil,556+ previewLabelPos: opts.PLabelPos,557 cleanExit: opts.ClearOnExit,558 paused: opts.Phony,559 strong: strongAttr,560 cycle: opts.Cycle,38 unmodified lines599 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+ }606 607 return &t608 }609 335 unmodified lines945 marginInt[0]-1, marginInt[3]-2, width+4, height+2,946 false, tui.MakeBorderStyle(t.borderShape, t.unicode))947 }948 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-949 // Add padding to margin950 for idx, val := range paddingInt {951 marginInt[idx] += val952 }96 unmodified lines1049 marginInt[3],1050 width,1051 height, false, noBorder)1052 }1053+1054+ // Print border label1055+ printLabel := func(window tui.Window, render func(), pos int, length int, borderShape tui.BorderShape) {1056+ if window == nil || render == nil {1057+ return1058+ }1059+1060+ switch borderShape {1061+ case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp:1062+ var col int1063+ if pos == 0 {1064+ col = util.Max(0, (window.Width()-length)/2)1065+ } else if pos < 0 {1066+ col = util.Max(0, window.Width()+pos+1-length)1067+ } else {1068+ col = util.Min(pos-1, window.Width()-length)1069+ }1070+ row := 01071+ if borderShape == tui.BorderBottom {1072+ row = window.Height() - 11073+ }1074+ window.Move(row, col)1075+ render()1076+ }1077+ }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)1080+1081 for i := 0; i < t.window.Height(); i++ {1082 t.window.MoveAndClear(i, 0)1083 }1084 }2008 unmodified linesmodified:CHANGELOG.md+2 added
22 unmodified lines23 24 # Right-aligned (negative integer)25 fzf --height=10 --border-label="╢ $label ╟" --border=bottom --border-label-pos=-3 --color=label:italic:black26 ```27+- Also added `--preview-label` and `--preview-label-pos` for the border of the28+ preview window29 - Info panel (counter) will be followed by a horizontal separator by default30 - The color of the separator can be customized via `--color=separator:...`31 - Separator can be disabled by adding `:nosep` to `--info`32 - `--info=nosep`1344 unmodified lines