mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2025-01-15 19:56:55 +00:00
Compare commits
2 Commits
43eafdf4b7
...
4fdc07927f
Author | SHA1 | Date | |
---|---|---|---|
|
4fdc07927f | ||
|
9030b67e4f |
@ -332,12 +332,21 @@ func (o *previewOpts) Toggle() {
|
|||||||
o.hidden = !o.hidden
|
o.hidden = !o.hidden
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *previewOpts) HasBorderRight() bool {
|
func (o *previewOpts) Border() tui.BorderShape {
|
||||||
return o.border.HasRight() || o.border == tui.BorderLine && o.position == posLeft
|
shape := o.border
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
}
|
||||||
func (o *previewOpts) HasBorderTop() bool {
|
return shape
|
||||||
return o.border.HasTop() || o.border == tui.BorderLine && o.position == posDown
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultTmuxOptions(index int) *tmuxOptions {
|
func defaultTmuxOptions(index int) *tmuxOptions {
|
||||||
|
@ -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.HasBorderRight() {
|
if len(t.scrollbar) > 0 && !opts.Border().HasRight() {
|
||||||
// Need a column to show scrollbar
|
// Need a column to show scrollbar
|
||||||
minPreviewWidth++
|
minPreviewWidth++
|
||||||
}
|
}
|
||||||
@ -1756,11 +1756,14 @@ 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 {
|
||||||
@ -1770,19 +1773,7 @@ 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)
|
||||||
@ -1826,11 +1817,9 @@ 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
|
|
||||||
stickToRight = t.borderShape.HasRight() &&
|
listStickToRight = listStickToRight && !previewOpts.Border().HasRight()
|
||||||
!previewOpts.HasBorderRight() && !t.listBorderShape.HasRight() && !t.inputBorderShape.HasRight() &&
|
if listStickToRight {
|
||||||
(!t.headerVisible || !t.headerBorderShape.HasRight() || t.visibleHeaderLines() == 0)
|
|
||||||
if stickToRight {
|
|
||||||
innerWidth++
|
innerWidth++
|
||||||
width++
|
width++
|
||||||
}
|
}
|
||||||
@ -1903,9 +1892,12 @@ 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: fzf --preview 'cat {}' --preview-window border-left --border
|
// NOTE: Relaxed condition for the following cases
|
||||||
stickToRight = !previewOpts.HasBorderRight() && t.borderShape.HasRight()
|
// fzf --preview 'seq 500' --preview-window border-left --border
|
||||||
if stickToRight {
|
// fzf --preview 'seq 500' --preview-window border-left --border --list-border
|
||||||
|
// fzf --preview 'seq 500' --preview-window border-left --border --input-border
|
||||||
|
listStickToRight = t.borderShape.HasRight() && !previewOpts.Border().HasRight()
|
||||||
|
if listStickToRight {
|
||||||
innerWidth++
|
innerWidth++
|
||||||
width++
|
width++
|
||||||
}
|
}
|
||||||
@ -1919,7 +1911,7 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
|
|||||||
}
|
}
|
||||||
resizePreviewWindows(&t.previewOpts)
|
resizePreviewWindows(&t.previewOpts)
|
||||||
|
|
||||||
if t.borderShape.HasRight() && !stickToRight {
|
if t.borderShape.HasRight() && !listStickToRight {
|
||||||
// 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
|
||||||
@ -1942,7 +1934,7 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
|
|||||||
|
|
||||||
// Without preview window
|
// Without preview window
|
||||||
if t.window == nil {
|
if t.window == nil {
|
||||||
if t.borderShape.HasRight() && !hasListBorder {
|
if listStickToRight {
|
||||||
// Put scrollbar closer to the right border for consistent look
|
// Put scrollbar closer to the right border for consistent look
|
||||||
innerWidth++
|
innerWidth++
|
||||||
width++
|
width++
|
||||||
@ -2027,9 +2019,7 @@ 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)
|
||||||
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.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)
|
||||||
}
|
}
|
||||||
@ -2044,7 +2034,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, tui.BorderLine:
|
case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderBlock, tui.BorderThinBlock, tui.BorderDouble:
|
||||||
if redrawBorder {
|
if redrawBorder {
|
||||||
window.DrawHBorder()
|
window.DrawHBorder()
|
||||||
}
|
}
|
||||||
@ -3227,11 +3217,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.HasBorderRight() {
|
if !t.activePreviewOpts.Border().HasRight() {
|
||||||
xshift = -1
|
xshift = -1
|
||||||
}
|
}
|
||||||
yshift := 1
|
yshift := 1
|
||||||
if !t.activePreviewOpts.HasBorderTop() {
|
if !t.activePreviewOpts.Border().HasTop() {
|
||||||
yshift = 0
|
yshift = 0
|
||||||
}
|
}
|
||||||
for i := yoff; i < height; i++ {
|
for i := yoff; i < height; i++ {
|
||||||
@ -3893,13 +3883,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)
|
||||||
@ -4253,7 +4243,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()
|
||||||
|
Loading…
Reference in New Issue
Block a user