Compare commits

..

No commits in common. "4fdc07927f1ba247563f6d9630b47536c305be75" and "43eafdf4b7390242eb0b9391b8586b08c5a518b2" have entirely different histories.

2 changed files with 44 additions and 43 deletions

View File

@ -332,21 +332,12 @@ func (o *previewOpts) Toggle() {
o.hidden = !o.hidden o.hidden = !o.hidden
} }
func (o *previewOpts) Border() tui.BorderShape { func (o *previewOpts) HasBorderRight() bool {
shape := o.border return o.border.HasRight() || o.border == tui.BorderLine && o.position == posLeft
if shape == tui.BorderLine {
switch o.position {
case posUp:
shape = tui.BorderBottom
case posDown:
shape = tui.BorderTop
case posLeft:
shape = tui.BorderRight
case posRight:
shape = tui.BorderLeft
} }
}
return shape func (o *previewOpts) HasBorderTop() bool {
return o.border.HasTop() || o.border == tui.BorderLine && o.position == posDown
} }
func defaultTmuxOptions(index int) *tmuxOptions { func defaultTmuxOptions(index int) *tmuxOptions {

View File

@ -782,7 +782,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
// Minimum height required to render fzf excluding margin and padding // Minimum height required to render fzf excluding margin and padding
effectiveMinHeight := minHeight effectiveMinHeight := minHeight
if previewBox != nil && opts.Preview.aboveOrBelow() { if previewBox != nil && opts.Preview.aboveOrBelow() {
effectiveMinHeight += 1 + borderLines(opts.Preview.Border()) effectiveMinHeight += 1 + borderLines(opts.Preview.border)
} }
if noSeparatorLine(opts.InfoStyle, opts.Separator == nil || uniseg.StringWidth(*opts.Separator) > 0) { if noSeparatorLine(opts.InfoStyle, opts.Separator == nil || uniseg.StringWidth(*opts.Separator) > 0) {
effectiveMinHeight-- effectiveMinHeight--
@ -1521,12 +1521,12 @@ func calculateSize(base int, size sizeSpec, occupied int, minSize int) int {
} }
func (t *Terminal) minPreviewSize(opts *previewOpts) (int, int) { func (t *Terminal) minPreviewSize(opts *previewOpts) (int, int) {
minPreviewWidth := 1 + borderColumns(opts.Border(), t.borderWidth) minPreviewWidth := 1 + borderColumns(opts.border, t.borderWidth)
minPreviewHeight := 1 + borderLines(opts.Border()) minPreviewHeight := 1 + borderLines(opts.border)
switch opts.position { switch opts.position {
case posLeft, posRight: case posLeft, posRight:
if len(t.scrollbar) > 0 && !opts.Border().HasRight() { if len(t.scrollbar) > 0 && !opts.HasBorderRight() {
// Need a column to show scrollbar // Need a column to show scrollbar
minPreviewWidth++ minPreviewWidth++
} }
@ -1756,14 +1756,11 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
t.areaLines = height t.areaLines = height
t.areaColumns = width t.areaColumns = width
// If none of the inner borders has the right side, but the outer border does, increase the list width by 1 column
listStickToRight := t.borderShape.HasRight() && !t.listBorderShape.HasRight() && !t.inputBorderShape.HasRight() &&
(!t.headerVisible || !t.headerBorderShape.HasRight() || t.visibleHeaderLines() == 0)
// Set up preview window // Set up preview window
noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode) noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode)
if forcePreview || t.needPreviewWindow() { if forcePreview || t.needPreviewWindow() {
var resizePreviewWindows func(previewOpts *previewOpts) var resizePreviewWindows func(previewOpts *previewOpts)
stickToRight := false
resizePreviewWindows = func(previewOpts *previewOpts) { resizePreviewWindows = func(previewOpts *previewOpts) {
t.activePreviewOpts = previewOpts t.activePreviewOpts = previewOpts
if previewOpts.size.size == 0 { if previewOpts.size.size == 0 {
@ -1773,7 +1770,19 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
createPreviewWindow := func(y int, x int, w int, h int) { createPreviewWindow := func(y int, x int, w int, h int) {
pwidth := w pwidth := w
pheight := h pheight := h
shape := previewOpts.Border() shape := previewOpts.border
if shape == tui.BorderLine {
switch previewOpts.position {
case posUp:
shape = tui.BorderBottom
case posDown:
shape = tui.BorderTop
case posLeft:
shape = tui.BorderRight
case posRight:
shape = tui.BorderLeft
}
}
previewBorder := tui.MakeBorderStyle(shape, t.unicode) previewBorder := tui.MakeBorderStyle(shape, t.unicode)
t.pborder = t.tui.NewWindow(y, x, w, h, tui.WindowPreview, previewBorder, false) t.pborder = t.tui.NewWindow(y, x, w, h, tui.WindowPreview, previewBorder, false)
pwidth -= borderColumns(shape, bw) pwidth -= borderColumns(shape, bw)
@ -1817,9 +1826,11 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
if previewOpts.hidden { if previewOpts.hidden {
return return
} }
// If none of the inner borders has the right side, but the outer border does, increase the width by 1 column
listStickToRight = listStickToRight && !previewOpts.Border().HasRight() stickToRight = t.borderShape.HasRight() &&
if listStickToRight { !previewOpts.HasBorderRight() && !t.listBorderShape.HasRight() && !t.inputBorderShape.HasRight() &&
(!t.headerVisible || !t.headerBorderShape.HasRight() || t.visibleHeaderLines() == 0)
if stickToRight {
innerWidth++ innerWidth++
width++ width++
} }
@ -1892,12 +1903,9 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
innerBorderFn(marginInt[0], marginInt[3]+pwidth, width-pwidth, height) innerBorderFn(marginInt[0], marginInt[3]+pwidth, width-pwidth, height)
createPreviewWindow(marginInt[0], marginInt[3], pwidth, height) createPreviewWindow(marginInt[0], marginInt[3], pwidth, height)
} else { } else {
// NOTE: Relaxed condition for the following cases // NOTE: fzf --preview 'cat {}' --preview-window border-left --border
// fzf --preview 'seq 500' --preview-window border-left --border stickToRight = !previewOpts.HasBorderRight() && t.borderShape.HasRight()
// fzf --preview 'seq 500' --preview-window border-left --border --list-border if stickToRight {
// fzf --preview 'seq 500' --preview-window border-left --border --input-border
listStickToRight = t.borderShape.HasRight() && !previewOpts.Border().HasRight()
if listStickToRight {
innerWidth++ innerWidth++
width++ width++
} }
@ -1911,7 +1919,7 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
} }
resizePreviewWindows(&t.previewOpts) resizePreviewWindows(&t.previewOpts)
if t.borderShape.HasRight() && !listStickToRight { if t.borderShape.HasRight() && !stickToRight {
// Need to clear the extra margin between the borders // Need to clear the extra margin between the borders
// fzf --preview 'seq 1000' --preview-window border-left --bind space:change-preview-window:border-rounded --border vertical // fzf --preview 'seq 1000' --preview-window border-left --bind space:change-preview-window:border-rounded --border vertical
// fzf --preview 'seq 1000' --preview-window up,hidden --bind space:toggle-preview --border vertical // fzf --preview 'seq 1000' --preview-window up,hidden --bind space:toggle-preview --border vertical
@ -1934,7 +1942,7 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
// Without preview window // Without preview window
if t.window == nil { if t.window == nil {
if listStickToRight { if t.borderShape.HasRight() && !hasListBorder {
// Put scrollbar closer to the right border for consistent look // Put scrollbar closer to the right border for consistent look
innerWidth++ innerWidth++
width++ width++
@ -2019,7 +2027,9 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
// Print border label // Print border label
t.printLabel(t.wborder, t.listLabel, t.listLabelOpts, t.listLabelLen, t.listBorderShape, false) t.printLabel(t.wborder, t.listLabel, t.listLabelOpts, t.listLabelLen, t.listBorderShape, false)
t.printLabel(t.border, t.borderLabel, t.borderLabelOpts, t.borderLabelLen, t.borderShape, false) t.printLabel(t.border, t.borderLabel, t.borderLabelOpts, t.borderLabelLen, t.borderShape, false)
t.printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.activePreviewOpts.Border(), false) if t.pborder != nil && t.pwindow.Height() != t.pborder.Height() { // To address --preview-border=line with different positions
t.printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.activePreviewOpts.border, false)
}
t.printLabel(t.inputBorder, t.inputLabel, t.inputLabelOpts, t.inputLabelLen, t.inputBorderShape, false) t.printLabel(t.inputBorder, t.inputLabel, t.inputLabelOpts, t.inputLabelLen, t.inputBorderShape, false)
t.printLabel(t.headerBorder, t.headerLabel, t.headerLabelOpts, t.headerLabelLen, t.headerBorderShape, false) t.printLabel(t.headerBorder, t.headerLabel, t.headerLabelOpts, t.headerLabelLen, t.headerBorderShape, false)
} }
@ -2034,7 +2044,7 @@ func (t *Terminal) printLabel(window tui.Window, render labelPrinter, opts label
} }
switch borderShape { switch borderShape {
case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderBlock, tui.BorderThinBlock, tui.BorderDouble: case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderBlock, tui.BorderThinBlock, tui.BorderDouble, tui.BorderLine:
if redrawBorder { if redrawBorder {
window.DrawHBorder() window.DrawHBorder()
} }
@ -3217,11 +3227,11 @@ func (t *Terminal) renderPreviewScrollbar(yoff int, barLength int, barStart int)
t.previewer.xw = xw t.previewer.xw = xw
} }
xshift := -1 - t.borderWidth xshift := -1 - t.borderWidth
if !t.activePreviewOpts.Border().HasRight() { if !t.activePreviewOpts.HasBorderRight() {
xshift = -1 xshift = -1
} }
yshift := 1 yshift := 1
if !t.activePreviewOpts.Border().HasTop() { if !t.activePreviewOpts.HasBorderTop() {
yshift = 0 yshift = 0
} }
for i := yoff; i < height; i++ { for i := yoff; i < height; i++ {
@ -3883,13 +3893,13 @@ func (t *Terminal) Loop() error {
if t.activePreviewOpts.aboveOrBelow() { if t.activePreviewOpts.aboveOrBelow() {
if t.activePreviewOpts.size.percent { if t.activePreviewOpts.size.percent {
newContentHeight := int(float64(contentHeight) * 100. / (100. - t.activePreviewOpts.size.size)) newContentHeight := int(float64(contentHeight) * 100. / (100. - t.activePreviewOpts.size.size))
contentHeight = util.Max(contentHeight+1+borderLines(t.activePreviewOpts.Border()), newContentHeight) contentHeight = util.Max(contentHeight+1+borderLines(t.activePreviewOpts.border), newContentHeight)
} else { } else {
contentHeight += int(t.activePreviewOpts.size.size) + borderLines(t.activePreviewOpts.Border()) contentHeight += int(t.activePreviewOpts.size.size) + borderLines(t.activePreviewOpts.border)
} }
} else { } else {
// Minimum height if preview window can appear // Minimum height if preview window can appear
contentHeight = util.Max(contentHeight, 1+borderLines(t.activePreviewOpts.Border())) contentHeight = util.Max(contentHeight, 1+borderLines(t.activePreviewOpts.border))
} }
} }
return util.Min(termHeight, contentHeight+pad) return util.Min(termHeight, contentHeight+pad)
@ -4243,7 +4253,7 @@ func (t *Terminal) Loop() error {
case reqRedrawBorderLabel: case reqRedrawBorderLabel:
t.printLabel(t.border, t.borderLabel, t.borderLabelOpts, t.borderLabelLen, t.borderShape, true) t.printLabel(t.border, t.borderLabel, t.borderLabelOpts, t.borderLabelLen, t.borderShape, true)
case reqRedrawPreviewLabel: case reqRedrawPreviewLabel:
t.printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.activePreviewOpts.Border(), true) t.printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.activePreviewOpts.border, true)
case reqReinit: case reqReinit:
t.tui.Resume(t.fullscreen, true) t.tui.Resume(t.fullscreen, true)
t.fullRedraw() t.fullRedraw()