Fix header window location and size

This commit is contained in:
Junegunn Choi 2025-01-23 12:55:59 +09:00
parent fb885652cc
commit c587017830
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
2 changed files with 35 additions and 41 deletions

View File

@ -931,7 +931,7 @@ Position of the header label
.TP .TP
.BI "\-\-header\-lines\-border" [=STYLE] .BI "\-\-header\-lines\-border" [=STYLE]
Display header from \fB--header-lines\fR with a separate border. Pass Display header from \fB--header\-lines\fR with a separate border. Pass
\fBnone\fR to still separate the header lines but without a border. To combine \fBnone\fR to still separate the header lines but without a border. To combine
two headers, use \fB\-\-no\-header\-lines\-border\fR. two headers, use \fB\-\-no\-header\-lines\-border\fR.

View File

@ -2019,16 +2019,16 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
innerHeight-shrink, tui.WindowList, noBorder, true) innerHeight-shrink, tui.WindowList, noBorder, true)
} }
createInnerWindow := func(b tui.Window, shape tui.BorderShape, windowType tui.WindowType) tui.Window { createInnerWindow := func(b tui.Window, shape tui.BorderShape, windowType tui.WindowType, shift int) tui.Window {
top := b.Top() top := b.Top()
left := b.Left() left := b.Left() + shift
if shape.HasTop() { if shape.HasTop() {
top++ top++
} }
if shape.HasLeft() { if shape.HasLeft() {
left += t.borderWidth + 1 left += t.borderWidth + 1
} }
width := b.Width() - borderColumns(shape, t.borderWidth) width := b.Width() - borderColumns(shape, t.borderWidth) - shift
if shape.HasRight() { if shape.HasRight() {
width++ width++
} }
@ -2056,26 +2056,22 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
btop = w.Top() + w.Height() + headerBorderHeight + headerLinesHeight btop = w.Top() + w.Height() + headerBorderHeight + headerLinesHeight
} }
} }
left := w.Left() shift := 0
if !t.inputBorderShape.HasLeft() && t.listBorderShape.HasLeft() { if !t.inputBorderShape.HasLeft() && t.listBorderShape.HasLeft() {
left += t.borderWidth + 1 shift += t.borderWidth + 1
}
width := w.Width()
if t.listBorderShape.HasRight() && !t.inputBorderShape.HasRight() {
width -= t.borderWidth + 1
} }
t.inputBorder = t.tui.NewWindow( t.inputBorder = t.tui.NewWindow(
btop, btop,
left, w.Left(),
width, w.Width(),
inputBorderHeight, tui.WindowInput, tui.MakeBorderStyle(t.inputBorderShape, t.unicode), true) inputBorderHeight, tui.WindowInput, tui.MakeBorderStyle(t.inputBorderShape, t.unicode), true)
if left > w.Left() { if shift > 0 && !t.inputBorderShape.Visible() {
// Small box on the left to erase the residue // Small box on the left to erase the residue
// e.g. // e.g.
// fzf --list-border --header-border --bind 'space:change-header(hello),enter:change-header()' // fzf --list-border --header-border --bind 'space:change-header(hello),enter:change-header()'
t.tui.NewWindow(btop, w.Left(), left-w.Left(), inputBorderHeight, tui.WindowInput, noBorder, false).Erase() t.tui.NewWindow(btop, w.Left(), shift, inputBorderHeight, tui.WindowInput, noBorder, false).Erase()
} }
t.inputWindow = createInnerWindow(t.inputBorder, t.inputBorderShape, tui.WindowInput) t.inputWindow = createInnerWindow(t.inputBorder, t.inputBorderShape, tui.WindowInput, shift)
} }
// Set up header border // Set up header border
@ -2094,17 +2090,12 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
btop = w.Top() + w.Height() + headerLinesHeight btop = w.Top() + w.Height() + headerLinesHeight
} }
} }
width := w.Width()
if t.listBorderShape.HasRight() && !t.headerBorderShape.HasRight() {
width -= t.borderWidth + 1
}
t.headerBorder = t.tui.NewWindow( t.headerBorder = t.tui.NewWindow(
btop, btop,
w.Left(), w.Left(),
width, w.Width(),
headerBorderHeight, tui.WindowHeader, tui.MakeBorderStyle(t.headerBorderShape, t.unicode), true) headerBorderHeight, tui.WindowHeader, tui.MakeBorderStyle(t.headerBorderShape, t.unicode), true)
t.headerWindow = createInnerWindow(t.headerBorder, t.headerBorderShape, tui.WindowHeader) t.headerWindow = createInnerWindow(t.headerBorder, t.headerBorderShape, tui.WindowHeader, 0)
} }
// Set up header lines border // Set up header lines border
@ -2115,16 +2106,12 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
} else { } else {
btop = w.Top() + w.Height() btop = w.Top() + w.Height()
} }
width := w.Width()
if t.listBorderShape.HasRight() && !t.headerLinesShape.HasRight() {
width -= t.borderWidth + 1
}
t.headerLinesBorder = t.tui.NewWindow( t.headerLinesBorder = t.tui.NewWindow(
btop, btop,
w.Left(), w.Left(),
width, w.Width(),
headerLinesHeight, tui.WindowHeader, tui.MakeBorderStyle(t.headerLinesShape, t.unicode), true) headerLinesHeight, tui.WindowHeader, tui.MakeBorderStyle(t.headerLinesShape, t.unicode), true)
t.headerLinesWindow = createInnerWindow(t.headerLinesBorder, t.headerLinesShape, tui.WindowHeader) t.headerLinesWindow = createInnerWindow(t.headerLinesBorder, t.headerLinesShape, tui.WindowHeader, 0)
} }
// Print border label // Print border label
@ -2394,7 +2381,7 @@ func (t *Terminal) printInfoImpl() {
} }
if t.infoStyle == infoRight { if t.infoStyle == infoRight {
maxWidth := t.window.Width() maxWidth := t.window.Width() - 1
if t.reading { if t.reading {
// Need space for spinner and a margin column // Need space for spinner and a margin column
maxWidth -= 2 maxWidth -= 2
@ -2446,7 +2433,7 @@ func (t *Terminal) printInfoImpl() {
} }
} }
maxWidth := t.window.Width() - pos maxWidth := t.window.Width() - pos - 1
if outputPrinter == nil { if outputPrinter == nil {
output = t.trimMessage(output, maxWidth) output = t.trimMessage(output, maxWidth)
t.window.CPrint(tui.ColInfo, output) t.window.CPrint(tui.ColInfo, output)
@ -2464,7 +2451,7 @@ func (t *Terminal) printInfoImpl() {
return return
} }
fillLength := maxWidth - outputLen - 2 fillLength := maxWidth - outputLen - 1
if fillLength > 0 { if fillLength > 0 {
t.window.CPrint(tui.ColSeparator, " ") t.window.CPrint(tui.ColSeparator, " ")
printSeparator(fillLength, false) printSeparator(fillLength, false)
@ -2565,7 +2552,10 @@ func (t *Terminal) printHeaderImpl(window tui.Window, borderShape tui.BorderShap
t.printHighlighted(Result{item: item}, t.printHighlighted(Result{item: item},
tui.ColHeader, tui.ColHeader, false, false, line, line, true, tui.ColHeader, tui.ColHeader, false, false, line, line, true,
func(markerClass) { t.window.Print(indent) }, nil) func(markerClass) int {
t.window.Print(indent)
return indentSize
}, nil)
} }
t.wrap = wrap t.wrap = wrap
} }
@ -2725,11 +2715,12 @@ func (t *Terminal) printItem(result Result, line int, maxLine int, index int, cu
} }
return marker return marker
} }
indentSize := t.pointerLen + t.markerLen
if current { if current {
preTask := func(marker markerClass) { preTask := func(marker markerClass) int {
w := t.window.Width() - t.pointerLen w := t.window.Width() - t.pointerLen
if w < 0 { if w < 0 {
return return indentSize
} }
if len(label) == 0 { if len(label) == 0 {
t.window.CPrint(tui.ColCurrentCursorEmpty, t.pointerEmpty) t.window.CPrint(tui.ColCurrentCursorEmpty, t.pointerEmpty)
@ -2737,20 +2728,21 @@ func (t *Terminal) printItem(result Result, line int, maxLine int, index int, cu
t.window.CPrint(tui.ColCurrentCursor, label) t.window.CPrint(tui.ColCurrentCursor, label)
} }
if w-t.markerLen < 0 { if w-t.markerLen < 0 {
return return indentSize
} }
if selected { if selected {
t.window.CPrint(tui.ColCurrentMarker, markerFor(marker)) t.window.CPrint(tui.ColCurrentMarker, markerFor(marker))
} else { } else {
t.window.CPrint(tui.ColCurrentSelectedEmpty, t.markerEmpty) t.window.CPrint(tui.ColCurrentSelectedEmpty, t.markerEmpty)
} }
return indentSize
} }
finalLineNum = t.printHighlighted(result, tui.ColCurrent, tui.ColCurrentMatch, true, true, line, maxLine, forceRedraw, preTask, postTask) finalLineNum = t.printHighlighted(result, tui.ColCurrent, tui.ColCurrentMatch, true, true, line, maxLine, forceRedraw, preTask, postTask)
} else { } else {
preTask := func(marker markerClass) { preTask := func(marker markerClass) int {
w := t.window.Width() - t.pointerLen w := t.window.Width() - t.pointerLen
if w < 0 { if w < 0 {
return return indentSize
} }
if len(label) == 0 { if len(label) == 0 {
t.window.CPrint(tui.ColCursorEmpty, t.pointerEmpty) t.window.CPrint(tui.ColCursorEmpty, t.pointerEmpty)
@ -2758,13 +2750,14 @@ func (t *Terminal) printItem(result Result, line int, maxLine int, index int, cu
t.window.CPrint(tui.ColCursor, label) t.window.CPrint(tui.ColCursor, label)
} }
if w-t.markerLen < 0 { if w-t.markerLen < 0 {
return return indentSize
} }
if selected { if selected {
t.window.CPrint(tui.ColMarker, markerFor(marker)) t.window.CPrint(tui.ColMarker, markerFor(marker))
} else { } else {
t.window.Print(t.markerEmpty) t.window.Print(t.markerEmpty)
} }
return indentSize
} }
var base, match tui.ColorPair var base, match tui.ColorPair
if selected { if selected {
@ -2821,7 +2814,7 @@ func (t *Terminal) overflow(runes []rune, max int) bool {
return t.displayWidthWithLimit(runes, 0, max) > max return t.displayWidthWithLimit(runes, 0, max) > max
} }
func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMatch tui.ColorPair, current bool, match bool, lineNum int, maxLineNum int, forceRedraw bool, preTask func(markerClass), postTask func(int, int, bool, bool)) int { func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMatch tui.ColorPair, current bool, match bool, lineNum int, maxLineNum int, forceRedraw bool, preTask func(markerClass) int, postTask func(int, int, bool, bool)) int {
var displayWidth int var displayWidth int
item := result.item item := result.item
matchOffsets := []Offset{} matchOffsets := []Offset{}
@ -2950,6 +2943,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
} }
t.move(actualLineNum, 0, forceRedraw && postTask == nil) t.move(actualLineNum, 0, forceRedraw && postTask == nil)
indentSize := t.pointerLen + t.markerLen
if preTask != nil { if preTask != nil {
var marker markerClass var marker markerClass
if numItemLines == 1 { if numItemLines == 1 {
@ -2978,10 +2972,10 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
} }
} }
preTask(marker) indentSize = preTask(marker)
} }
maxWidth := t.window.Width() - (t.pointerLen + t.markerLen + 1) maxWidth := t.window.Width() - (indentSize + 1)
wasWrapped := false wasWrapped := false
if wrapped { if wrapped {
maxWidth -= t.wrapSignWidth maxWidth -= t.wrapSignWidth