Skip to content

Commit 4fdc079

Browse files
committed
Refactor --preview-border=line
1 parent 9030b67 commit 4fdc079

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

src/options.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,21 @@ func (o *previewOpts) Toggle() {
332332
o.hidden = !o.hidden
333333
}
334334

335-
func (o *previewOpts) HasBorderRight() bool {
336-
return o.border.HasRight() || o.border == tui.BorderLine && o.position == posLeft
337-
}
338-
339-
func (o *previewOpts) HasBorderTop() bool {
340-
return o.border.HasTop() || o.border == tui.BorderLine && o.position == posDown
335+
func (o *previewOpts) Border() tui.BorderShape {
336+
shape := o.border
337+
if shape == tui.BorderLine {
338+
switch o.position {
339+
case posUp:
340+
shape = tui.BorderBottom
341+
case posDown:
342+
shape = tui.BorderTop
343+
case posLeft:
344+
shape = tui.BorderRight
345+
case posRight:
346+
shape = tui.BorderLeft
347+
}
348+
}
349+
return shape
341350
}
342351

343352
func defaultTmuxOptions(index int) *tmuxOptions {

src/terminal.go

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
782782
// Minimum height required to render fzf excluding margin and padding
783783
effectiveMinHeight := minHeight
784784
if previewBox != nil && opts.Preview.aboveOrBelow() {
785-
effectiveMinHeight += 1 + borderLines(opts.Preview.border)
785+
effectiveMinHeight += 1 + borderLines(opts.Preview.Border())
786786
}
787787
if noSeparatorLine(opts.InfoStyle, opts.Separator == nil || uniseg.StringWidth(*opts.Separator) > 0) {
788788
effectiveMinHeight--
@@ -1521,12 +1521,12 @@ func calculateSize(base int, size sizeSpec, occupied int, minSize int) int {
15211521
}
15221522

15231523
func (t *Terminal) minPreviewSize(opts *previewOpts) (int, int) {
1524-
minPreviewWidth := 1 + borderColumns(opts.border, t.borderWidth)
1525-
minPreviewHeight := 1 + borderLines(opts.border)
1524+
minPreviewWidth := 1 + borderColumns(opts.Border(), t.borderWidth)
1525+
minPreviewHeight := 1 + borderLines(opts.Border())
15261526

15271527
switch opts.position {
15281528
case posLeft, posRight:
1529-
if len(t.scrollbar) > 0 && !opts.HasBorderRight() {
1529+
if len(t.scrollbar) > 0 && !opts.Border().HasRight() {
15301530
// Need a column to show scrollbar
15311531
minPreviewWidth++
15321532
}
@@ -1773,19 +1773,7 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
17731773
createPreviewWindow := func(y int, x int, w int, h int) {
17741774
pwidth := w
17751775
pheight := h
1776-
shape := previewOpts.border
1777-
if shape == tui.BorderLine {
1778-
switch previewOpts.position {
1779-
case posUp:
1780-
shape = tui.BorderBottom
1781-
case posDown:
1782-
shape = tui.BorderTop
1783-
case posLeft:
1784-
shape = tui.BorderRight
1785-
case posRight:
1786-
shape = tui.BorderLeft
1787-
}
1788-
}
1776+
shape := previewOpts.Border()
17891777
previewBorder := tui.MakeBorderStyle(shape, t.unicode)
17901778
t.pborder = t.tui.NewWindow(y, x, w, h, tui.WindowPreview, previewBorder, false)
17911779
pwidth -= borderColumns(shape, bw)
@@ -1830,7 +1818,7 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
18301818
return
18311819
}
18321820

1833-
listStickToRight = listStickToRight && !previewOpts.HasBorderRight()
1821+
listStickToRight = listStickToRight && !previewOpts.Border().HasRight()
18341822
if listStickToRight {
18351823
innerWidth++
18361824
width++
@@ -1908,7 +1896,7 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
19081896
// fzf --preview 'seq 500' --preview-window border-left --border
19091897
// fzf --preview 'seq 500' --preview-window border-left --border --list-border
19101898
// fzf --preview 'seq 500' --preview-window border-left --border --input-border
1911-
listStickToRight = t.borderShape.HasRight() && !previewOpts.HasBorderRight()
1899+
listStickToRight = t.borderShape.HasRight() && !previewOpts.Border().HasRight()
19121900
if listStickToRight {
19131901
innerWidth++
19141902
width++
@@ -2031,9 +2019,7 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
20312019
// Print border label
20322020
t.printLabel(t.wborder, t.listLabel, t.listLabelOpts, t.listLabelLen, t.listBorderShape, false)
20332021
t.printLabel(t.border, t.borderLabel, t.borderLabelOpts, t.borderLabelLen, t.borderShape, false)
2034-
if t.pborder != nil && t.pwindow.Height() != t.pborder.Height() { // To address --preview-border=line with different positions
2035-
t.printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.activePreviewOpts.border, false)
2036-
}
2022+
t.printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.activePreviewOpts.Border(), false)
20372023
t.printLabel(t.inputBorder, t.inputLabel, t.inputLabelOpts, t.inputLabelLen, t.inputBorderShape, false)
20382024
t.printLabel(t.headerBorder, t.headerLabel, t.headerLabelOpts, t.headerLabelLen, t.headerBorderShape, false)
20392025
}
@@ -2048,7 +2034,7 @@ func (t *Terminal) printLabel(window tui.Window, render labelPrinter, opts label
20482034
}
20492035

20502036
switch borderShape {
2051-
case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderBlock, tui.BorderThinBlock, tui.BorderDouble, tui.BorderLine:
2037+
case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderBlock, tui.BorderThinBlock, tui.BorderDouble:
20522038
if redrawBorder {
20532039
window.DrawHBorder()
20542040
}
@@ -3231,11 +3217,11 @@ func (t *Terminal) renderPreviewScrollbar(yoff int, barLength int, barStart int)
32313217
t.previewer.xw = xw
32323218
}
32333219
xshift := -1 - t.borderWidth
3234-
if !t.activePreviewOpts.HasBorderRight() {
3220+
if !t.activePreviewOpts.Border().HasRight() {
32353221
xshift = -1
32363222
}
32373223
yshift := 1
3238-
if !t.activePreviewOpts.HasBorderTop() {
3224+
if !t.activePreviewOpts.Border().HasTop() {
32393225
yshift = 0
32403226
}
32413227
for i := yoff; i < height; i++ {
@@ -3897,13 +3883,13 @@ func (t *Terminal) Loop() error {
38973883
if t.activePreviewOpts.aboveOrBelow() {
38983884
if t.activePreviewOpts.size.percent {
38993885
newContentHeight := int(float64(contentHeight) * 100. / (100. - t.activePreviewOpts.size.size))
3900-
contentHeight = util.Max(contentHeight+1+borderLines(t.activePreviewOpts.border), newContentHeight)
3886+
contentHeight = util.Max(contentHeight+1+borderLines(t.activePreviewOpts.Border()), newContentHeight)
39013887
} else {
3902-
contentHeight += int(t.activePreviewOpts.size.size) + borderLines(t.activePreviewOpts.border)
3888+
contentHeight += int(t.activePreviewOpts.size.size) + borderLines(t.activePreviewOpts.Border())
39033889
}
39043890
} else {
39053891
// Minimum height if preview window can appear
3906-
contentHeight = util.Max(contentHeight, 1+borderLines(t.activePreviewOpts.border))
3892+
contentHeight = util.Max(contentHeight, 1+borderLines(t.activePreviewOpts.Border()))
39073893
}
39083894
}
39093895
return util.Min(termHeight, contentHeight+pad)
@@ -4257,7 +4243,7 @@ func (t *Terminal) Loop() error {
42574243
case reqRedrawBorderLabel:
42584244
t.printLabel(t.border, t.borderLabel, t.borderLabelOpts, t.borderLabelLen, t.borderShape, true)
42594245
case reqRedrawPreviewLabel:
4260-
t.printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.activePreviewOpts.border, true)
4246+
t.printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.activePreviewOpts.Border(), true)
42614247
case reqReinit:
42624248
t.tui.Resume(t.fullscreen, true)
42634249
t.fullRedraw()

0 commit comments

Comments
 (0)