summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/options.go15
-rw-r--r--src/terminal.go57
2 files changed, 51 insertions, 21 deletions
diff --git a/src/options.go b/src/options.go
index 36fd2055..d536dae6 100644
--- a/src/options.go
+++ b/src/options.go
@@ -96,6 +96,8 @@ const usage = `usage: fzf [options]
[,border-BORDER_OPT]
[,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES]
[,default][,<SIZE_THRESHOLD(ALTERNATIVE_LAYOUT)]
+ --preview-label=LABEL
+ --preview-label-pos=COL
Scripting
-q, --query=STR Start the finder with the given query
@@ -275,6 +277,8 @@ type Options struct {
BorderShape tui.BorderShape
Label string
LabelPos int
+ PLabel string
+ PLabelPos int
Unicode bool
Tabstop int
ClearOnExit bool
@@ -343,6 +347,8 @@ func defaultOptions() *Options {
Tabstop: 8,
Label: "",
LabelPos: 0,
+ PLabel: "",
+ PLabelPos: 0,
ClearOnExit: true,
Version: false}
}
@@ -1593,6 +1599,11 @@ func parseOptions(opts *Options, allArgs []string) {
case "--border-label-pos":
pos := nextString(allArgs, &i, "label position required (positive or negative integer or 'center')")
opts.LabelPos = parseLabelPosition(pos)
+ case "--preview-label":
+ opts.PLabel = nextString(allArgs, &i, "preview label required")
+ case "--preview-label-pos":
+ pos := nextString(allArgs, &i, "preview label position required (positive or negative integer or 'center')")
+ opts.PLabelPos = parseLabelPosition(pos)
case "--no-unicode":
opts.Unicode = false
case "--unicode":
@@ -1632,6 +1643,10 @@ func parseOptions(opts *Options, allArgs []string) {
opts.Label = value
} else if match, value := optString(arg, "--border-label-pos="); match {
opts.LabelPos = parseLabelPosition(value)
+ } else if match, value := optString(arg, "--preview-label="); match {
+ opts.PLabel = value
+ } else if match, value := optString(arg, "--preview-label-pos="); match {
+ opts.PLabelPos = parseLabelPosition(value)
} else if match, value := optString(arg, "--prompt="); match {
opts.Prompt = value
} else if match, value := optString(arg, "--pointer="); match {
diff --git a/src/terminal.go b/src/terminal.go
index ca50de42..2764ff85 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -117,6 +117,9 @@ type Terminal struct {
borderLabel func()
borderLabelLen int
borderLabelPos int
+ previewLabel func()
+ previewLabelLen int
+ previewLabelPos int
pointer string
pointerLen int
pointerEmpty string
@@ -549,6 +552,8 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
borderShape: opts.BorderShape,
borderLabel: nil,
borderLabelPos: opts.LabelPos,
+ previewLabel: nil,
+ previewLabelPos: opts.PLabelPos,
cleanExit: opts.ClearOnExit,
paused: opts.Phony,
strong: strongAttr,
@@ -595,6 +600,9 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
if len(opts.Label) > 0 {
t.borderLabel, t.borderLabelLen = t.parseBorderLabel(opts.Label)
}
+ if len(opts.PLabel) > 0 {
+ t.previewLabel, t.previewLabelLen = t.parseBorderLabel(opts.PLabel)
+ }
return &t
}
@@ -938,27 +946,6 @@ func (t *Terminal) resizeWindows() {
false, tui.MakeBorderStyle(t.borderShape, t.unicode))
}
- // Print border label
- if t.border != nil && t.borderLabel != nil {
- switch t.borderShape {
- case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp:
- var col int
- if t.borderLabelPos == 0 {
- col = util.Max(0, (t.border.Width()-t.borderLabelLen)/2)
- } else if t.borderLabelPos < 0 {
- col = util.Max(0, t.border.Width()+t.borderLabelPos+1-t.borderLabelLen)
- } else {
- col = util.Min(t.borderLabelPos-1, t.border.Width()-t.borderLabelLen)
- }
- row := 0
- if t.borderShape == tui.BorderBottom {
- row = t.border.Height() - 1
- }
- t.border.Move(row, col)
- t.borderLabel()
- }
- }
-
// Add padding to margin
for idx, val := range paddingInt {
marginInt[idx] += val
@@ -1063,6 +1050,34 @@ func (t *Terminal) resizeWindows() {
width,
height, false, noBorder)
}
+
+ // Print border label
+ printLabel := func(window tui.Window, render func(), pos int, length int, borderShape tui.BorderShape) {
+ if window == nil || render == nil {
+ return
+ }
+
+ switch borderShape {
+ case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp:
+ var col int
+ if pos == 0 {
+ col = util.Max(0, (window.Width()-length)/2)
+ } else if pos < 0 {
+ col = util.Max(0, window.Width()+pos+1-length)
+ } else {
+ col = util.Min(pos-1, window.Width()-length)
+ }
+ row := 0
+ if borderShape == tui.BorderBottom {
+ row = window.Height() - 1
+ }
+ window.Move(row, col)
+ render()
+ }
+ }
+ printLabel(t.border, t.borderLabel, t.borderLabelPos, t.borderLabelLen, t.borderShape)
+ printLabel(t.pborder, t.previewLabel, t.previewLabelPos, t.previewLabelLen, t.previewOpts.border)
+
for i := 0; i < t.window.Height(); i++ {
t.window.MoveAndClear(i, 0)
}