Skip to content
Myr

Add --{header,header-lines,footer}-border=inline

Before adoption: this commit came in with the history the project adopted, so no landing records it.

New BorderShape that embeds the section inside the --list-border frame, joined to the list content by a horizontal separator with T-junctions where the list shape has side borders. Requires a list border with both top and bottom segments; falls back to 'line' otherwise. Stacks when multiple sections are inline. Sections inherit --color list-border by default and are colored as a uniform block via their own --color *-border and *-bg. Incompatible with --header-first. --header-border=inline requires --header-lines-border to be inline or unset.

authored by Junegunn Choi · committed by Junegunn Choi · parent ef6eba1 · Browse files · 9 files+897 added−233 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

9 files+897 added−233 removed

  • tests:+214 added−0 removed
  • other:+683 added−233 removed

9 files+897 added−233 removed

modified:man/man1/fzf.1+15 added-2 removed
1098 unmodified lines
1099(\fB\-\-header\-lines\fR) are present, this applies only to the normal header.1100.TP1101.BI "\-\-header\-border" [=STYLE]1102Draw border around the header section. \fBline\fR style draws a single1103separator line between the header window and the list section.1103separator line between the header window and the list section. \fBinline\fR1104style embeds the header inside the list border frame, joined to the list1105section by a horizontal separator with T-junctions; it requires a1106line-drawing \fB\-\-list\-border\fR (rounded / sharp / bold / double /1107horizontal) and falls back to \fBline\fR otherwise. Not compatible with1108\fB\-\-header\-first\fR, and when \fB\-\-header\-lines\fR is also set1109\fB\-\-header\-lines\-border\fR must also be \fBinline\fR.11101111.TP1112.BI "\-\-header\-label" [=LABEL]1113Label to print on the header border
7 unmodified lines
1121Display header from \fB--header\-lines\fR with a separate border. Pass1122\fBnone\fR to still separate the header lines but without a border. To combine1123two headers, use \fB\-\-no\-header\-lines\-border\fR. \fBline\fR style draws1124a single separator line between the header lines and the list section.1125\fBinline\fR style embeds the header lines inside the list border frame1126with a T-junction separator; it requires a line-drawing1127\fB\-\-list\-border\fR, falls back to \fBline\fR otherwise, and is not1128compatible with \fB\-\-header\-first\fR.11291130.SS FOOTER11311132.TP
5 unmodified lines
11381139.TP1140.BI "\-\-footer\-border" [=STYLE]1141Draw border around the footer section. \fBline\fR style draws a single1132separator line between the footer and the list section.1142separator line between the footer and the list section. \fBinline\fR style1143embeds the footer inside the list border frame with a T-junction separator;1144it requires a line-drawing \fB\-\-list\-border\fR and falls back to1145\fBline\fR otherwise.11461147.TP1148.BI "\-\-footer\-label" [=LABEL]1149Label to print on the footer border
1135 unmodified lines
modified:src/tui/light.go+117 added-102 removed
1127 unmodified lines
1128func (w *LightWindow) DrawHBorder() {1129 w.drawBorder(true)1130}11311132func (w *LightWindow) drawBorder(onlyHorizontal bool) {1133 if w.height == 0 {1134 return1132// drawHLine fills row `row` with `line` between optional left/right caps.1133// A zero rune means "no cap"; caps are placed at the very edges of `w`.1134func (w *LightWindow) drawHLine(row int, line, leftCap, rightCap rune, color ColorPair) {1135 w.Move(row, 0)1136 hw := runeWidth(line)1137 width := w.width1138 if leftCap != 0 {1139 w.CPrint(color, string(leftCap))1140 width -= runeWidth(leftCap)1141 }1136 switch w.border.shape {1137 case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble:1138 w.drawBorderAround(onlyHorizontal)1139 case BorderHorizontal:1140 w.drawBorderHorizontal(true, true)1141 case BorderVertical:1142 if onlyHorizontal {1143 return1144 }1145 w.drawBorderVertical(true, true)1146 case BorderTop:1147 w.drawBorderHorizontal(true, false)1148 case BorderBottom:1149 w.drawBorderHorizontal(false, true)1150 case BorderLeft:1151 if onlyHorizontal {1152 return1153 }1154 w.drawBorderVertical(true, false)1155 case BorderRight:1156 if onlyHorizontal {1157 return1158 }1159 w.drawBorderVertical(false, true)1142 if rightCap != 0 {1143 width -= runeWidth(rightCap)1144 }1145 if width < 0 {1146 width = 01147 }1148 inner := width / hw1149 rem := width - inner*hw1150 w.CPrint(color, repeat(line, inner)+repeat(' ', rem))1151 if rightCap != 0 {1152 w.CPrint(color, string(rightCap))1153 }1154}11551163func (w *LightWindow) drawBorderHorizontal(top, bottom bool) {1164 color := ColBorder1165 switch w.windowType {1166 case WindowList:1167 color = ColListBorder1168 case WindowInput:1169 color = ColInputBorder1170 case WindowHeader:1171 color = ColHeaderBorder1172 case WindowFooter:1173 color = ColFooterBorder1174 case WindowPreview:1175 color = ColPreviewBorder1156func (w *LightWindow) DrawHSeparator(row int, windowType WindowType, useBottom bool) {1157 if w.height == 0 {1158 return1159 }1177 hw := runeWidth(w.border.top)1178 if top {1179 w.Move(0, 0)1180 w.CPrint(color, repeat(w.border.top, w.width/hw))1160 shape := w.border.shape1161 if shape == BorderNone {1162 return1163 }11821183 if bottom {1184 w.Move(w.height-1, 0)1185 w.CPrint(color, repeat(w.border.bottom, w.width/hw))1164 color := BorderColor(windowType)1165 line := w.border.top1166 if useBottom {1167 line = w.border.bottom1168 }1169 var leftCap, rightCap rune1170 if shape.HasLeft() || shape.HasRight() {1171 leftCap = w.border.leftMid1172 rightCap = w.border.rightMid1173 }1174 w.drawHLine(row, line, leftCap, rightCap, color)1175}11761189func (w *LightWindow) drawBorderVertical(left, right bool) {1190 vw := runeWidth(w.border.left)1191 color := ColBorder1192 switch w.windowType {1193 case WindowList:1194 color = ColListBorder1195 case WindowInput:1196 color = ColInputBorder1197 case WindowHeader:1198 color = ColHeaderBorder1199 case WindowFooter:1200 color = ColFooterBorder1201 case WindowPreview:1202 color = ColPreviewBorder1177func (w *LightWindow) PaintSectionFrame(topContent, bottomContent int, windowType WindowType, edge SectionEdge) {1178 if w.height == 0 || w.border.shape == BorderNone {1179 return1180 }1204 for y := 0; y < w.height; y++ {1205 if left {1206 w.Move(y, 0)1207 w.CPrint(color, string(w.border.left))1208 w.CPrint(color, " ") // Margin1181 color := BorderColor(windowType)1182 shape := w.border.shape1183 hasLeft := shape.HasLeft()1184 hasRight := shape.HasRight()1185 rightW := runeWidth(w.border.right)1186 // Content rows: overpaint left/right verticals + their 1-char margin.1187 for row := topContent; row <= bottomContent; row++ {1188 if hasLeft {1189 w.Move(row, 0)1190 w.CPrint(color, string(w.border.left)+" ")1191 }1210 if right {1211 w.Move(y, w.width-vw-1)1212 w.CPrint(color, " ") // Margin1213 w.CPrint(color, string(w.border.right))1192 if hasRight {1193 w.Move(row, w.width-rightW-1)1194 w.CPrint(color, " "+string(w.border.right))1195 }1196 }1197 if edge == SectionEdgeTop && shape.HasTop() {1198 var leftCap, rightCap rune1199 if hasLeft {1200 leftCap = w.border.topLeft1201 }1202 if hasRight {1203 rightCap = w.border.topRight1204 }1205 w.drawHLine(0, w.border.top, leftCap, rightCap, color)1206 }1207 if edge == SectionEdgeBottom && shape.HasBottom() {1208 var leftCap, rightCap rune1209 if hasLeft {1210 leftCap = w.border.bottomLeft1211 }1212 if hasRight {1213 rightCap = w.border.bottomRight1214 }1215 w.drawHLine(w.height-1, w.border.bottom, leftCap, rightCap, color)1216 }1217}12181218func (w *LightWindow) drawBorderAround(onlyHorizontal bool) {1219 w.Move(0, 0)1220 color := ColBorder1221 switch w.windowType {1222 case WindowList:1223 color = ColListBorder1224 case WindowInput:1225 color = ColInputBorder1226 case WindowHeader:1227 color = ColHeaderBorder1228 case WindowFooter:1229 color = ColFooterBorder1230 case WindowPreview:1231 color = ColPreviewBorder1219func (w *LightWindow) drawBorder(onlyHorizontal bool) {1220 if w.height == 0 {1221 return1222 }1233 hw := runeWidth(w.border.top)1234 tcw := runeWidth(w.border.topLeft) + runeWidth(w.border.topRight)1235 bcw := runeWidth(w.border.bottomLeft) + runeWidth(w.border.bottomRight)1236 rem := (w.width - tcw) % hw1237 w.CPrint(color, string(w.border.topLeft)+repeat(w.border.top, (w.width-tcw)/hw)+repeat(' ', rem)+string(w.border.topRight))1238 if !onlyHorizontal {1239 vw := runeWidth(w.border.left)1240 for y := 1; y < w.height-1; y++ {1241 w.Move(y, 0)1242 w.CPrint(color, string(w.border.left))1243 w.CPrint(color, " ") // Margin1223 shape := w.border.shape1224 if shape == BorderNone {1225 return1226 }1227 color := BorderColor(w.windowType)1228 hasLeft := shape.HasLeft()1229 hasRight := shape.HasRight()12301245 w.Move(y, w.width-vw-1)1246 w.CPrint(color, " ") // Margin1247 w.CPrint(color, string(w.border.right))1231 if shape.HasTop() {1232 var leftCap, rightCap rune1233 if hasLeft {1234 leftCap = w.border.topLeft1235 }1236 if hasRight {1237 rightCap = w.border.topRight1238 }1239 w.drawHLine(0, w.border.top, leftCap, rightCap, color)1240 }1250 w.Move(w.height-1, 0)1251 rem = (w.width - bcw) % hw1252 w.CPrint(color, string(w.border.bottomLeft)+repeat(w.border.bottom, (w.width-bcw)/hw)+repeat(' ', rem)+string(w.border.bottomRight))1241 if !onlyHorizontal && (hasLeft || hasRight) {1242 vw := runeWidth(w.border.left)1243 for y := 0; y < w.height; y++ {1244 // Corner rows are already painted by drawHLine above / below.1245 if (y == 0 && shape.HasTop()) || (y == w.height-1 && shape.HasBottom()) {1246 continue1247 }1248 if hasLeft {1249 w.Move(y, 0)1250 w.CPrint(color, string(w.border.left)+" ")1251 }1252 if hasRight {1253 w.Move(y, w.width-vw-1)1254 w.CPrint(color, " "+string(w.border.right))1255 }1256 }1257 }1258 if shape.HasBottom() {1259 var leftCap, rightCap rune1260 if hasLeft {1261 leftCap = w.border.bottomLeft1262 }1263 if hasRight {1264 rightCap = w.border.bottomRight1265 }1266 w.drawHLine(w.height-1, w.border.bottom, leftCap, rightCap, color)1267 }1268}12691270func (w *LightWindow) csi(code string) string {1271 return w.renderer.csi(code)
288 unmodified lines
modified:src/tui/tcell.go+133 added-54 removed
1015 unmodified lines
1016func (w *TcellWindow) DrawHBorder() {1017 w.drawBorder(true)1018}10191020// borderStyleFor returns the tcell.Style used to draw borders for `wt`, honoring1021// whether the window is rendering with colors.1022func (w *TcellWindow) borderStyleFor(wt WindowType) tcell.Style {1023 if !w.color {1024 return w.normal.style()1025 }1026 return BorderColor(wt).style()1027}10281029// drawHLine fills row `y` with `line` between optional left/right caps.1030// A zero rune means "no cap"; caps are placed at the very edges of `w`.1031// tcell has an issue displaying two overlapping wide runes, so the line1032// stops before the cap position rather than overpainting.1033func (w *TcellWindow) drawHLine(y int, line, leftCap, rightCap rune, style tcell.Style) {1034 left := w.left1035 right := left + w.width1036 hw := runeWidth(line)1037 lw := 01038 rw := 01039 if leftCap != 0 {1040 lw = runeWidth(leftCap)1041 }1042 if rightCap != 0 {1043 rw = runeWidth(rightCap)1044 }1045 for x := left + lw; x <= right-rw-hw; x += hw {1046 _screen.SetContent(x, y, line, nil, style)1047 }1048 if leftCap != 0 {1049 _screen.SetContent(left, y, leftCap, nil, style)1050 }1051 if rightCap != 0 {1052 _screen.SetContent(right-rw, y, rightCap, nil, style)1053 }1054}10551056func (w *TcellWindow) DrawHSeparator(row int, windowType WindowType, useBottom bool) {1057 if w.height == 0 {1058 return1059 }1060 shape := w.borderStyle.shape1061 if shape == BorderNone {1062 return1063 }1064 style := w.borderStyleFor(windowType)1065 line := w.borderStyle.top1066 if useBottom {1067 line = w.borderStyle.bottom1068 }1069 var leftCap, rightCap rune1070 if shape.HasLeft() || shape.HasRight() {1071 leftCap = w.borderStyle.leftMid1072 rightCap = w.borderStyle.rightMid1073 }1074 w.drawHLine(w.top+row, line, leftCap, rightCap, style)1075}10761077func (w *TcellWindow) PaintSectionFrame(topContent, bottomContent int, windowType WindowType, edge SectionEdge) {1078 if w.height == 0 {1079 return1080 }1081 shape := w.borderStyle.shape1082 if shape == BorderNone {1083 return1084 }1085 style := w.borderStyleFor(windowType)1086 left := w.left1087 right := left + w.width1088 hasLeft := shape.HasLeft()1089 hasRight := shape.HasRight()1090 leftW := runeWidth(w.borderStyle.left)1091 rightW := runeWidth(w.borderStyle.right)1092 // Content rows: overpaint the left and right verticals (+ their 1-char margin) in1093 // the section's color. Inner margin stays at whatever bg the sub-window set.1094 for row := topContent; row <= bottomContent; row++ {1095 y := w.top + row1096 if hasLeft {1097 _screen.SetContent(left, y, w.borderStyle.left, nil, style)1098 _screen.SetContent(left+leftW, y, ' ', nil, style)1099 }1100 if hasRight {1101 _screen.SetContent(right-rightW-1, y, ' ', nil, style)1102 _screen.SetContent(right-rightW, y, w.borderStyle.right, nil, style)1103 }1104 }1105 if edge == SectionEdgeTop && shape.HasTop() {1106 var leftCap, rightCap rune1107 if hasLeft {1108 leftCap = w.borderStyle.topLeft1109 }1110 if hasRight {1111 rightCap = w.borderStyle.topRight1112 }1113 w.drawHLine(w.top, w.borderStyle.top, leftCap, rightCap, style)1114 }1115 if edge == SectionEdgeBottom && shape.HasBottom() {1116 var leftCap, rightCap rune1117 if hasLeft {1118 leftCap = w.borderStyle.bottomLeft1119 }1120 if hasRight {1121 rightCap = w.borderStyle.bottomRight1122 }1123 w.drawHLine(w.top+w.height-1, w.borderStyle.bottom, leftCap, rightCap, style)1124 }1125}11261127func (w *TcellWindow) drawBorder(onlyHorizontal bool) {1128 if w.height == 0 {1129 return1130 }
6 unmodified lines
1137 right := left + w.width1138 top := w.top1139 bot := top + w.height11401034 var style tcell.Style1035 if w.color {1036 switch w.windowType {1037 case WindowBase:1038 style = ColBorder.style()1039 case WindowList:1040 style = ColListBorder.style()1041 case WindowHeader:1042 style = ColHeaderBorder.style()1043 case WindowFooter:1044 style = ColFooterBorder.style()1045 case WindowInput:1046 style = ColInputBorder.style()1047 case WindowPreview:1048 style = ColPreviewBorder.style()1049 }1050 } else {1051 style = w.normal.style()1052 }1141 style := w.borderStyleFor(w.windowType)11421054 hw := runeWidth(w.borderStyle.top)1055 switch shape {1056 case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble, BorderHorizontal, BorderTop:1057 max := right - 2*hw1058 if shape == BorderHorizontal || shape == BorderTop {1059 max = right - hw1143 hasLeft := shape.HasLeft()1144 hasRight := shape.HasRight()11451146 if shape.HasTop() {1147 var leftCap, rightCap rune1148 if hasLeft {1149 leftCap = w.borderStyle.topLeft1150 }1061 // tcell has an issue displaying two overlapping wide runes1062 // e.g. SetContent( HH )1063 // SetContent( TR )1064 // ==================1065 // ( HH ) => TR is ignored1066 for x := left; x <= max; x += hw {1067 _screen.SetContent(x, top, w.borderStyle.top, nil, style)1151 if hasRight {1152 rightCap = w.borderStyle.topRight1153 }1154 w.drawHLine(top, w.borderStyle.top, leftCap, rightCap, style)1155 }1070 switch shape {1071 case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble, BorderHorizontal, BorderBottom:1072 max := right - 2*hw1073 if shape == BorderHorizontal || shape == BorderBottom {1074 max = right - hw1156 if shape.HasBottom() {1157 var leftCap, rightCap rune1158 if hasLeft {1159 leftCap = w.borderStyle.bottomLeft1160 }1076 for x := left; x <= max; x += hw {1077 _screen.SetContent(x, bot-1, w.borderStyle.bottom, nil, style)1161 if hasRight {1162 rightCap = w.borderStyle.bottomRight1163 }1164 w.drawHLine(bot-1, w.borderStyle.bottom, leftCap, rightCap, style)1165 }1166 if !onlyHorizontal {1081 switch shape {1082 case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble, BorderVertical, BorderLeft:1083 for y := top; y < bot; y++ {1167 vw := runeWidth(w.borderStyle.right)1168 for y := top; y < bot; y++ {1169 // Corner rows are already painted by drawHLine above / below.1170 if (y == top && shape.HasTop()) || (y == bot-1 && shape.HasBottom()) {1171 continue1172 }1173 if hasLeft {1174 _screen.SetContent(left, y, w.borderStyle.left, nil, style)1175 }1086 }1087 switch shape {1088 case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble, BorderVertical, BorderRight:1089 vw := runeWidth(w.borderStyle.right)1090 for y := top; y < bot; y++ {1176 if hasRight {1177 _screen.SetContent(right-vw, y, w.borderStyle.right, nil, style)1178 }1179 }1180 }1095 switch shape {1096 case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble:1097 _screen.SetContent(left, top, w.borderStyle.topLeft, nil, style)1098 _screen.SetContent(right-runeWidth(w.borderStyle.topRight), top, w.borderStyle.topRight, nil, style)1099 _screen.SetContent(left, bot-1, w.borderStyle.bottomLeft, nil, style)1100 _screen.SetContent(right-runeWidth(w.borderStyle.bottomRight), bot-1, w.borderStyle.bottomRight, nil, style)1101 }1181}
modified:src/tui/tui.go+80 added-8 removed
593 unmodified lines
594 BorderTop595 BorderBottom596 BorderLeft597 BorderRight598 BorderInline599)600601func (s BorderShape) HasLeft() bool {602 switch s {602 case BorderNone, BorderPhantom, BorderLine, BorderRight, BorderTop, BorderBottom, BorderHorizontal: // No Left603 case BorderNone, BorderPhantom, BorderLine, BorderInline, BorderRight, BorderTop, BorderBottom, BorderHorizontal: // No Left604 return false605 }606 return true607}608609func (s BorderShape) HasRight() bool {610 switch s {610 case BorderNone, BorderPhantom, BorderLine, BorderLeft, BorderTop, BorderBottom, BorderHorizontal: // No right611 case BorderNone, BorderPhantom, BorderLine, BorderInline, BorderLeft, BorderTop, BorderBottom, BorderHorizontal: // No right612 return false613 }614 return true615}616617func (s BorderShape) HasTop() bool {618 switch s {618 case BorderNone, BorderPhantom, BorderLine, BorderLeft, BorderRight, BorderBottom, BorderVertical: // No top619 case BorderNone, BorderPhantom, BorderLine, BorderInline, BorderLeft, BorderRight, BorderBottom, BorderVertical: // No top620 return false621 }622 return true623}624625func (s BorderShape) HasBottom() bool {626 switch s {626 case BorderNone, BorderPhantom, BorderLine, BorderLeft, BorderRight, BorderTop, BorderVertical: // No bottom627 case BorderNone, BorderPhantom, BorderLine, BorderInline, BorderLeft, BorderRight, BorderTop, BorderVertical: // No bottom628 return false629 }630 return true631}
11 unmodified lines
643 topLeft rune644 topRight rune645 bottomLeft rune646 bottomRight rune647 leftMid rune648 rightMid rune649}650651type BorderCharacter int652
7 unmodified lines
660 right: ' ',661 topLeft: ' ',662 topRight: ' ',663 bottomLeft: ' ',661 bottomRight: ' '}664 bottomRight: ' ',665 leftMid: ' ',666 rightMid: ' '}667 }668 if !unicode {669 return BorderStyle{670 shape: shape,
4 unmodified lines
675 topLeft: '+',676 topRight: '+',677 bottomLeft: '+',678 bottomRight: '+',679 leftMid: '+',680 rightMid: '+',681 }682 }683 switch shape {684 case BorderSharp:
6 unmodified lines
691 topLeft: '┌',692 topRight: '┐',693 bottomLeft: '└',694 bottomRight: '┘',695 leftMid: '├',696 rightMid: '┤',697 }698 case BorderBold:699 return BorderStyle{700 shape: shape,
4 unmodified lines
705 topLeft: '┏',706 topRight: '┓',707 bottomLeft: '┗',708 bottomRight: '┛',709 leftMid: '┣',710 rightMid: '┫',711 }712 case BorderBlock:713 // ▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜714 // ▌ ▐
7 unmodified lines
722 topLeft: '▛',723 topRight: '▜',724 bottomLeft: '▙',725 bottomRight: '▟',726 leftMid: '▌',727 rightMid: '▐',728 }729730 case BorderThinBlock:731 // 🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾
8 unmodified lines
740 topLeft: '🭽',741 topRight: '🭾',742 bottomLeft: '🭼',743 bottomRight: '🭿',744 leftMid: '▏',745 rightMid: '▕',746 }747748 case BorderDouble:749 return BorderStyle{
5 unmodified lines
755 topLeft: '╔',756 topRight: '╗',757 bottomLeft: '╚',758 bottomRight: '╝',759 leftMid: '╠',760 rightMid: '╣',761 }762 }763 return BorderStyle{764 shape: shape,
4 unmodified lines
769 topLeft: '╭',770 topRight: '╮',771 bottomLeft: '╰',772 bottomRight: '╯',773 leftMid: '├',774 rightMid: '┤',775 }776}777778type TermSize struct {
13 unmodified lines
792 WindowHeader793 WindowFooter794)795796// BorderColor returns the ColorPair used to draw borders for the given WindowType.797func BorderColor(wt WindowType) ColorPair {798 switch wt {799 case WindowList:800 return ColListBorder801 case WindowInput:802 return ColInputBorder803 case WindowHeader:804 return ColHeaderBorder805 case WindowFooter:806 return ColFooterBorder807 case WindowPreview:808 return ColPreviewBorder809 }810 return ColBorder811}812813// SectionEdge selects which outer edge of the frame an inline section814// should claim when PaintSectionFrame overpaints its adjacent border.815// SectionEdgeNone paints only the inner verticals (for sections that816// don't touch the outer top or bottom).817type SectionEdge int818819const (820 SectionEdgeNone SectionEdge = iota821 SectionEdgeTop822 SectionEdgeBottom823)824825type Renderer interface {826 DefaultTheme() *ColorTheme827 Init() error828 Resize(maxHeightFunc func(int) int)
29 unmodified lines
858 Height() int859860 DrawBorder()861 DrawHBorder()862 // DrawHSeparator draws an inline horizontal separator at `row` (relative to the863 // window's top) using the color for `windowType`. The separator is conceptually864 // the section's inner edge (e.g. the bottom border of an inline header), so the865 // whole row including junctions carries the section's fg + bg. When useBottom is866 // true the `bottom` horizontal char is used instead of `top`; for thinblock/block867 // styles this keeps the thin line bonded to the list content on the opposite side.868 DrawHSeparator(row int, windowType WindowType, useBottom bool)869 // PaintSectionFrame overpaints the border cells around the rows [topContent,870 // bottomContent] (inclusive, relative to the window's top) with the color for871 // `windowType`. When edge is SectionEdgeTop / SectionEdgeBottom, the872 // corresponding outer horizontal (+ corners) is also painted, letting the873 // inline section claim that edge of the outer frame.874 PaintSectionFrame(topContent, bottomContent int, windowType WindowType, edge SectionEdge)875 Refresh()876 FinishFill()877878 X() int
347 unmodified lines
1226 Nomatch: undefined,1227 }1228}12291169func InitTheme(theme *ColorTheme, baseTheme *ColorTheme, boldify bool, forceBlack bool, hasInputWindow bool, hasHeaderWindow bool) {1230func InitTheme(theme *ColorTheme, baseTheme *ColorTheme, boldify bool, forceBlack bool, hasInputWindow bool, hasHeaderWindow bool, headerInline bool, footerInline bool) {1231 if forceBlack {1232 theme.Bg = ColorAttr{colBlack, AttrUndefined}1233 }1234
125 unmodified lines
1360 theme.HeaderBg = o(theme.Bg, theme.HeaderBg)1361 } else {1362 theme.HeaderBg = o(theme.Bg, theme.ListBg)1363 }1364 // Inline header/footer borders sit inside the list frame, so default their color1365 // to the list-border color when the user has not explicitly set it. The inline1366 // separator then matches the surrounding frame.1367 headerBorderFallback := theme.Border1368 if headerInline {1369 headerBorderFallback = theme.ListBorder1370 }1303 theme.HeaderBorder = o(theme.Border, theme.HeaderBorder)1371 theme.HeaderBorder = o(headerBorderFallback, theme.HeaderBorder)1372 theme.HeaderLabel = o(theme.BorderLabel, theme.HeaderLabel)13731374 theme.FooterBg = o(theme.Bg, theme.FooterBg)1375 footerBorderFallback := theme.Border1376 if footerInline {1377 footerBorderFallback = theme.ListBorder1378 }1307 theme.FooterBorder = o(theme.Border, theme.FooterBorder)1379 theme.FooterBorder = o(footerBorderFallback, theme.FooterBorder)1380 theme.FooterLabel = o(theme.BorderLabel, theme.FooterLabel)13811382 if theme.Nomatch.IsUndefined() {1383 theme.Nomatch.Attr = Dim
109 unmodified lines
modified:src/options.go+22 added-3 removed
176 unmodified lines
177 --header-lines=N The first N lines of the input are treated as header178 --header-first Print header before the prompt line179 --header-border[=STYLE] Draw border around the header section180 [rounded|sharp|bold|block|thinblock|double|horizontal|vertical|181 top|bottom|left|right|line|none] (default: rounded)181 top|bottom|left|right|line|inline|none] (default: rounded)182 --header-lines-border[=STYLE]183 Display header from --header-lines with a separate border.184 Pass 'none' to still separate it but without a border.185 Pass 'inline' to embed it inside the list frame.186 --header-label=LABEL Label to print on the header border187 --header-label-pos=COL Position of the header label188 [POSITIVE_INTEGER: columns from left|189 NEGATIVE_INTEGER: columns from right][:bottom]
2 unmodified lines
192 FOOTER193 --footer=STR String to print as footer194 --footer-border[=STYLE] Draw border around the footer section195 [rounded|sharp|bold|block|thinblock|double|horizontal|vertical|195 top|bottom|left|right|line|none] (default: line)196 top|bottom|left|right|line|inline|none] (default: line)197 --footer-label=LABEL Label to print on the footer border198 --footer-label-pos=COL Position of the footer label199 [POSITIVE_INTEGER: columns from left|200 NEGATIVE_INTEGER: columns from right][:bottom]
752 unmodified lines
953func parseBorder(str string, optional bool) (tui.BorderShape, error) {954 switch str {955 case "line":956 return tui.BorderLine, nil957 case "inline":958 return tui.BorderInline, nil959 case "rounded":960 return tui.BorderRounded, nil961 case "sharp":962 return tui.BorderSharp, nil
22 unmodified lines
985 }986 if optional && str == "" {987 return defaultBorderShape, nil988 }986 return tui.BorderNone, errors.New("invalid border style (expected: rounded|sharp|bold|block|thinblock|double|horizontal|vertical|top|bottom|left|right|none)")989 return tui.BorderNone, errors.New("invalid border style (expected: rounded|sharp|bold|block|thinblock|double|horizontal|vertical|top|bottom|left|right|line|inline|none)")990}991992func parseKeyChords(str string, message string) (map[tui.Event]string, []tui.Event, error) {993 if len(str) == 0 {
2618 unmodified lines
3612 if opts.Theme.Nth.IsColorDefined() {3613 return errors.New("only ANSI attributes are allowed for 'nth' (regular, bold, underline, reverse, dim, italic, strikethrough)")3614 }36153616 if opts.BorderShape == tui.BorderInline ||3617 opts.ListBorderShape == tui.BorderInline ||3618 opts.InputBorderShape == tui.BorderInline ||3619 opts.Preview.border == tui.BorderInline {3620 return errors.New("inline border is only supported for --header-border, --header-lines-border, and --footer-border")3621 }3622 if opts.HeaderFirst && (opts.HeaderBorderShape == tui.BorderInline || opts.HeaderLinesShape == tui.BorderInline) {3623 return errors.New("--header-first is not compatible with --header-border=inline or --header-lines-border=inline")3624 }3625 if opts.HeaderBorderShape == tui.BorderInline &&3626 opts.HeaderLinesShape != tui.BorderInline &&3627 opts.HeaderLinesShape != tui.BorderUndefined &&3628 opts.HeaderLinesShape != tui.BorderNone {3629 return errors.New("--header-border=inline requires --header-lines-border to be inline or unset")3630 }36313632 return nil3633}36343635func noSeparatorLine(style infoStyle, separator bool) bool {
317 unmodified lines
modified:src/terminal.go+300 added-64 removed
1166 unmodified lines
1167 if baseTheme == nil {1168 baseTheme = renderer.DefaultTheme()1169 }1170 // This should be called before accessing tui.Color*1171 headerInline := opts.HeaderBorderShape == tui.BorderInline || opts.HeaderLinesShape == tui.BorderInline1172 footerInline := opts.FooterBorderShape == tui.BorderInline1173 hasHeader := opts.HeaderBorderShape.Visible() || opts.HeaderLinesShape.Visible()1171 tui.InitTheme(opts.Theme, baseTheme, opts.Bold, opts.Black, opts.InputBorderShape.Visible(), opts.HeaderBorderShape.Visible())1174 tui.InitTheme(opts.Theme, baseTheme, opts.Bold, opts.Black, opts.InputBorderShape.Visible(), hasHeader, headerInline, footerInline)11751176 // Gutter character1177 var gutterChar, gutterRawChar string1178 if opts.Gutter != nil {
50 unmodified lines
1229 t.inputBorderShape = tui.BorderTop1230 }1231 }12321233 // Inline borders are embedded between the list's top and bottom horizontals.1234 // Shapes missing either one (none/phantom/line/single-sided) fall back to a plain1235 // horizontal separator (same as BorderLine).1236 inlineSupported := t.listBorderShape.HasTop() && t.listBorderShape.HasBottom()1237 if !inlineSupported {1238 if t.headerBorderShape == tui.BorderInline {1239 t.headerBorderShape = tui.BorderLine1240 }1241 if t.headerLinesShape == tui.BorderInline {1242 t.headerLinesShape = tui.BorderLine1243 }1244 if t.footerBorderShape == tui.BorderInline {1245 t.footerBorderShape = tui.BorderLine1246 }1247 }12481249 // Determine header border shape1250 if t.headerBorderShape == tui.BorderLine {1251 if t.layout == layoutReverse {1252 t.headerBorderShape = tui.BorderBottom
1002 unmodified lines
22552256 return false, tui.BorderNone2257}22582259// Inline sections live inside wborder rather than consuming shift/shrink/availableLines.2260type inlineRole int22612262const (2263 inlineRoleHeader inlineRole = iota2264 inlineRoleHeaderLines2265 inlineRoleFooter2266)22672268type inlineSlot struct {2269 role inlineRole2270 windowType tui.WindowType2271 contentLines int // 0 when out of budget: a ghost placeholder is created so2272 // t.headerWindow / t.footerWindow stay non-nil but no frame is painted.2273 label labelPrinter2274 labelOpts labelOpts2275 labelLen int2276}22772278// inlineMetaFor returns (onTop: top stack vs bottom; windowType; isInner:2279// adjacent to list content) for the given inline role, derived from the layout.2280// Header is outer when paired with header-lines; header-lines is always inner;2281// footer is inner except in reverseList where it sits outside header-lines.2282func (t *Terminal) inlineMetaFor(role inlineRole) (onTop bool, windowType tui.WindowType, isInner bool) {2283 switch role {2284 case inlineRoleHeader:2285 return t.layout == layoutReverse, tui.WindowHeader, false2286 case inlineRoleHeaderLines:2287 return t.layout != layoutDefault, tui.WindowHeader, true2288 case inlineRoleFooter:2289 return t.layout != layoutReverse, tui.WindowFooter, t.layout != layoutReverseList2290 }2291 return false, tui.WindowBase, false2292}22932294func (t *Terminal) placeInlineSection(win tui.Window, role inlineRole) {2295 switch role {2296 case inlineRoleHeader:2297 t.headerWindow = win2298 case inlineRoleHeaderLines:2299 t.headerLinesWindow = win2300 case inlineRoleFooter:2301 t.footerWindow = win2302 }2303}23042305// placeInlineStack walks `slots` in outer-to-inner order. Only the outermost2306// slot (index 0) claims the adjacent wborder edge; later slots paint side-only2307// frames so the T-junction separator lands between sections.2308func (t *Terminal) placeInlineStack(slots []inlineSlot, startRow int, onTop bool) {2309 firstEdge := tui.SectionEdgeTop2310 if !onTop {2311 firstEdge = tui.SectionEdgeBottom2312 }2313 noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode)2314 subLeft := t.window.Left()2315 subWidth := t.window.Width()2316 cursor := startRow2317 for i, s := range slots {2318 var windowTop, sepRow int2319 if onTop {2320 windowTop = cursor2321 sepRow = cursor + s.contentLines - t.wborder.Top()2322 } else {2323 windowTop = cursor - s.contentLines + 12324 sepRow = windowTop - 1 - t.wborder.Top()2325 }2326 // 0-height placeholder keeps t.headerWindow / t.footerWindow non-nil.2327 win := t.tui.NewWindow(windowTop, subLeft, subWidth, s.contentLines, s.windowType, noBorder, true)2328 t.placeInlineSection(win, s.role)2329 if s.contentLines == 0 {2330 continue2331 }2332 secTop := windowTop - t.wborder.Top()2333 secBottom := secTop + s.contentLines - 12334 edge := tui.SectionEdgeNone2335 if i == 0 {2336 edge = firstEdge2337 }2338 t.wborder.PaintSectionFrame(secTop, secBottom, s.windowType, edge)2339 // useBottom=onTop so the separator always hugs the list (inner side).2340 // Matters for thinblock/block where top != bottom char.2341 t.wborder.DrawHSeparator(sepRow, s.windowType, onTop)2342 t.printLabelAt(t.wborder, s.label, s.labelOpts, s.labelLen, sepRow)2343 if onTop {2344 cursor += s.contentLines + 12345 } else {2346 cursor -= s.contentLines + 12347 }2348 }2349}23502351func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {2352 t.clearNumLinesCache()2353 t.forcePreview = forcePreview2354 screenWidth, screenHeight, marginInt, paddingInt := t.adjustMarginAndPadding()
108 unmodified lines
2463 availableLines -= minPreviewHeight2464 }2465 }24662467 // Slices are ordered outer-to-inner: index 0 touches wborder's edge.2468 var inlineTop []inlineSlot2469 var inlineBottom []inlineSlot24702471 // Caps contentLines against remaining wborder space. Oversized requests (e.g. a2472 // huge --header-lines) become 0-height placeholders rather than pushing the list2473 // window to negative height.2474 addInline := func(contentLines int, role inlineRole) {2475 onTop, windowType, isInner := t.inlineMetaFor(role)2476 used := 02477 for _, s := range inlineTop {2478 if s.contentLines > 0 {2479 used += s.contentLines + 12480 }2481 }2482 for _, s := range inlineBottom {2483 if s.contentLines > 0 {2484 used += s.contentLines + 12485 }2486 }2487 remaining := availableLines - borderLines(t.listBorderShape) - used - 12488 if remaining < 2 {2489 contentLines = 02490 } else {2491 contentLines = util.Constrain(contentLines, 1, remaining-1)2492 }2493 slot := inlineSlot{role: role, windowType: windowType, contentLines: contentLines}2494 switch role {2495 case inlineRoleHeader:2496 slot.label, slot.labelOpts, slot.labelLen = t.headerLabel, t.headerLabelOpts, t.headerLabelLen2497 case inlineRoleFooter:2498 slot.label, slot.labelOpts, slot.labelLen = t.footerLabel, t.footerLabelOpts, t.footerLabelLen2499 }2500 target := &inlineTop2501 if !onTop {2502 target = &inlineBottom2503 }2504 if isInner {2505 *target = append(*target, slot)2506 } else {2507 *target = append([]inlineSlot{slot}, *target...)2508 }2509 }25102511 // Adjust position and size of the list window if header border is set2512 headerBorderHeight := 02513 if hasHeaderWindow {2514 headerWindowHeight := t.visibleHeaderLines()2515 if hasHeaderLinesWindow {2516 headerWindowHeight -= t.headerLines2517 }2363 headerBorderHeight = util.Constrain(borderLines(t.headerBorderShape)+headerWindowHeight, 0, availableLines)2364 if t.layout == layoutReverse {2365 shift += headerBorderHeight2366 shrink += headerBorderHeight2518 if t.headerBorderShape == tui.BorderInline {2519 addInline(headerWindowHeight, inlineRoleHeader)2520 } else {2521 headerBorderHeight = util.Constrain(borderLines(t.headerBorderShape)+headerWindowHeight, 0, availableLines)2522 if t.layout == layoutReverse {2523 shift += headerBorderHeight2368 shrink += headerBorderHeight2524 shrink += headerBorderHeight2525 } else {2526 shrink += headerBorderHeight2527 }2528 availableLines -= headerBorderHeight2529 }2370 availableLines -= headerBorderHeight2530 }25312532 headerLinesHeight := 02533 if hasHeaderLinesWindow {2375 headerLinesHeight = util.Constrain(borderLines(headerLinesShape)+t.headerLines, 0, availableLines)2376 if t.layout != layoutDefault {2377 shift += headerLinesHeight2378 shrink += headerLinesHeight2534 if headerLinesShape == tui.BorderInline {2535 addInline(t.headerLines, inlineRoleHeaderLines)2536 } else {2537 headerLinesHeight = util.Constrain(borderLines(headerLinesShape)+t.headerLines, 0, availableLines)2538 if t.layout != layoutDefault {2539 shift += headerLinesHeight2380 shrink += headerLinesHeight2540 shrink += headerLinesHeight2541 } else {2542 shrink += headerLinesHeight2543 }2544 availableLines -= headerLinesHeight2545 }2382 availableLines -= headerLinesHeight2546 }25472548 footerBorderHeight := 02549 if hasFooterWindow {2550 if t.footerBorderShape == tui.BorderInline {2551 addInline(len(t.footer), inlineRoleFooter)2552 } else {2387 // Footer lines should not take all available lines2388 footerBorderHeight = util.Constrain(borderLines(t.footerBorderShape)+len(t.footer), 0, availableLines)2389 shrink += footerBorderHeight2390 if t.layout != layoutReverse {2391 shift += footerBorderHeight2553 // Footer lines should not take all available lines2554 footerBorderHeight = util.Constrain(borderLines(t.footerBorderShape)+len(t.footer), 0, availableLines)2555 shrink += footerBorderHeight2556 if t.layout != layoutReverse {2557 shift += footerBorderHeight2558 }2559 availableLines -= footerBorderHeight2560 }2393 availableLines -= footerBorderHeight2561 }25622563 inlineTopLines := 02564 for _, s := range inlineTop {2565 if s.contentLines > 0 {2566 inlineTopLines += s.contentLines + 12567 }2568 }2569 inlineBottomLines := 02570 for _, s := range inlineBottom {2571 if s.contentLines > 0 {2572 inlineBottomLines += s.contentLines + 12573 }2574 }25752576 // Set up list border2577 hasListBorder := t.listBorderShape.Visible()2578 innerWidth := width2579 innerHeight := height
100 unmodified lines
26802681 if previewOpts.position == posUp {2682 innerBorderFn(marginInt[0]+pheight, marginInt[3], width, height-pheight)2683 t.window = t.tui.NewWindow(2504 innerMarginInt[0]+pheight+shift, innerMarginInt[3], innerWidth, innerHeight-pheight-shrink, tui.WindowList, noBorder, true)2684 innerMarginInt[0]+pheight+shift+inlineTopLines, innerMarginInt[3], innerWidth, innerHeight-pheight-shrink-inlineTopLines-inlineBottomLines, tui.WindowList, noBorder, true)2685 createPreviewWindow(marginInt[0], marginInt[3], width, pheight)2686 } else {2687 innerBorderFn(marginInt[0], marginInt[3], width, height-pheight)2688 t.window = t.tui.NewWindow(2509 innerMarginInt[0]+shift, innerMarginInt[3], innerWidth, innerHeight-pheight-shrink, tui.WindowList, noBorder, true)2689 innerMarginInt[0]+shift+inlineTopLines, innerMarginInt[3], innerWidth, innerHeight-pheight-shrink-inlineTopLines-inlineBottomLines, tui.WindowList, noBorder, true)2690 createPreviewWindow(marginInt[0]+height-pheight, marginInt[3], width, pheight)2691 }2692 case posLeft, posRight:2693 minListWidth := minWidth
30 unmodified lines
2724 if !hasListBorder {2725 m = 12726 }2727 t.window = t.tui.NewWindow(2548 innerMarginInt[0]+shift, innerMarginInt[3]+pwidth+m, innerWidth-pwidth-m, innerHeight-shrink, tui.WindowList, noBorder, true)2728 innerMarginInt[0]+shift+inlineTopLines, innerMarginInt[3]+pwidth+m, innerWidth-pwidth-m, innerHeight-shrink-inlineTopLines-inlineBottomLines, tui.WindowList, noBorder, true)27292730 // Clear characters on the margin2731 // fzf --bind 'space:toggle-preview' --preview ':' --preview-window left,12732 if !hasListBorder {
23 unmodified lines
2756 width++2757 }2758 innerBorderFn(marginInt[0], marginInt[3], width-pwidth, height)2759 t.window = t.tui.NewWindow(2580 innerMarginInt[0]+shift, innerMarginInt[3], innerWidth-pwidth, innerHeight-shrink, tui.WindowList, noBorder, true)2760 innerMarginInt[0]+shift+inlineTopLines, innerMarginInt[3], innerWidth-pwidth, innerHeight-shrink-inlineTopLines-inlineBottomLines, tui.WindowList, noBorder, true)2761 x := marginInt[3] + width - pwidth2762 createPreviewWindow(marginInt[0], x, pwidth, height)2763 }2764 }
29 unmodified lines
2794 width++2795 }2796 innerBorderFn(marginInt[0], marginInt[3], width, height)2797 t.window = t.tui.NewWindow(2618 innerMarginInt[0]+shift,2798 innerMarginInt[0]+shift+inlineTopLines,2799 innerMarginInt[3],2800 innerWidth,2621 innerHeight-shrink, tui.WindowList, noBorder, true)2801 innerHeight-shrink-inlineTopLines-inlineBottomLines, tui.WindowList, noBorder, true)2802 }28032804 if len(inlineTop)+len(inlineBottom) > 0 && t.wborder != nil {2805 t.placeInlineStack(inlineTop, t.window.Top()-inlineTopLines, true)2806 t.placeInlineStack(inlineBottom, t.window.Top()+t.window.Height()+inlineBottomLines-1, false)2807 }28082809 if len(t.scrollbar) == 0 {2810 for y := 0; y < t.window.Height(); y++ {2811 t.window.Move(y, t.window.Width()-1)2812 t.window.Print(" ")
71 unmodified lines
2884 t.inputWindow = createInnerWindow(t.inputBorder, t.inputBorderShape, tui.WindowInput, shift)2885 }28862887 // Set up header border2703 if hasHeaderWindow {2888 if hasHeaderWindow && t.headerBorderShape != tui.BorderInline {2889 var btop int2890 if hasInputWindow && t.headerFirst {2891 if t.layout == layoutReverse {2892 btop = w.Top() - shrink + footerBorderHeight
19 unmodified lines
2912 t.headerWindow = createInnerWindow(t.headerBorder, t.headerBorderShape, tui.WindowHeader, 0)2913 }29142915 // Set up header lines border2731 if hasHeaderLinesWindow {2916 if hasHeaderLinesWindow && headerLinesShape != tui.BorderInline {2917 var btop int2918 // NOTE: We still have to handle --header-first here in case2919 // --header-lines-border is set. Can't we just use header window instead2920 // with the style? So we can display header label.
24 unmodified lines
2945 t.headerLinesWindow = createInnerWindow(t.headerLinesBorder, headerLinesShape, tui.WindowHeader, 0)2946 }29472948 // Set up footer2764 if hasFooterWindow {2949 if hasFooterWindow && t.footerBorderShape != tui.BorderInline {2950 var btop int2951 if t.layout == layoutReverse {2952 btop = w.Top() + w.Height()2953 } else if t.layout == layoutReverseList {
8 unmodified lines
2962 footerBorderHeight, tui.WindowFooter, tui.MakeBorderStyle(t.footerBorderShape, t.unicode), true)2963 t.footerWindow = createInnerWindow(t.footerBorder, t.footerBorderShape, tui.WindowFooter, 0)2964 }29652781 // Print border label2782 t.printLabel(t.wborder, t.listLabel, t.listLabelOpts, t.listLabelLen, t.listBorderShape, false)2966 // When the list label lands on an edge owned by an inline section, swap its bg2967 // so the label reads as part of that section's frame. Fg stays at list-label.2968 listLabel, listLabelLen := t.listLabel, t.listLabelLen2969 var adjacentSection *inlineSlot2970 if t.listLabelOpts.bottom && len(inlineBottom) > 0 {2971 adjacentSection = &inlineBottom[0]2972 } else if !t.listLabelOpts.bottom && len(inlineTop) > 0 {2973 adjacentSection = &inlineTop[0]2974 }2975 if adjacentSection != nil {2976 bg := tui.BorderColor(adjacentSection.windowType).Bg()2977 custom := tui.ColListLabel.WithBg(tui.ColorAttr{Color: bg, Attr: tui.AttrUndefined})2978 listLabel, listLabelLen = t.ansiLabelPrinter(t.listLabelOpts.label, &custom, false)2979 }2980 t.printLabel(t.wborder, listLabel, t.listLabelOpts, listLabelLen, t.listBorderShape, false)2981 t.printLabel(t.border, t.borderLabel, t.borderLabelOpts, t.borderLabelLen, t.borderShape, false)2982 t.printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.activePreviewOpts.Border(), false)2983 t.printLabel(t.inputBorder, t.inputLabel, t.inputLabelOpts, t.inputLabelLen, t.inputBorderShape, false)2984 t.printLabel(t.headerBorder, t.headerLabel, t.headerLabelOpts, t.headerLabelLen, t.headerBorderShape, false)2985 t.printLabel(t.footerBorder, t.footerLabel, t.footerLabelOpts, t.footerLabelLen, t.footerBorderShape, false)2986}29872790func (t *Terminal) printLabel(window tui.Window, render labelPrinter, opts labelOpts, length int, borderShape tui.BorderShape, redrawBorder bool) {2791 if window == nil {2988// printLabelAt positions and renders a label at the given row of `window`. Shared by2989// printLabel (which computes row from the border shape) and the inline-section label2990// code (which uses an explicit separator row).2991func (t *Terminal) printLabelAt(window tui.Window, render labelPrinter, opts labelOpts, length int, row int) {2992 if window == nil || render == nil || window.Height() == 0 {2993 return2994 }2995 var col int2996 if opts.column == 0 {2997 col = max(0, (window.Width()-length)/2)2998 } else if opts.column < 0 {2999 col = max(0, window.Width()+opts.column+1-length)3000 } else {3001 col = min(opts.column-1, window.Width()-length)3002 }3003 window.Move(row, col)3004 render(window, window.Width())3005}30063007func (t *Terminal) printLabel(window tui.Window, render labelPrinter, opts labelOpts, length int, borderShape tui.BorderShape, redrawBorder bool) {2795 if window.Height() == 0 {3008 if window == nil || window.Height() == 0 {3009 return3010 }27983011 switch borderShape {3012 case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderBlock, tui.BorderThinBlock, tui.BorderDouble:3013 if redrawBorder {3014 window.DrawHBorder()3015 }2804 if render == nil {2805 return2806 }2807 var col int2808 if opts.column == 0 {2809 col = max(0, (window.Width()-length)/2)2810 } else if opts.column < 0 {2811 col = max(0, window.Width()+opts.column+1-length)2812 } else {2813 col = min(opts.column-1, window.Width()-length)2814 }3016 row := 03017 if borderShape == tui.BorderBottom || opts.bottom {3018 row = window.Height() - 13019 }2819 window.Move(row, col)2820 render(window, window.Width())3020 t.printLabelAt(window, render, opts, length, row)3021 }3022}30233024func (t *Terminal) move(y int, x int, clear bool) {
359 unmodified lines
3384 t.printAll()3385 return true3386 }33873388 // Inline sections are budget-capped inside wborder, so window.Height() may be3389 // smaller than the requested content length. Treat "capped" (height < want) as3390 // a no-op to avoid triggering a full redraw on every info/header/footer event3391 // when the user has requested more content than fits.3392 mismatch := func(shape tui.BorderShape, height, want int) bool {3393 if shape == tui.BorderInline && height < want {3394 return false3395 }3396 return height != want3397 }33983399 // Check footer window3189 if len(t.footer) > 0 && (t.footerWindow == nil || t.footerWindow.Height() != len(t.footer)) ||3400 if len(t.footer) > 0 && (t.footerWindow == nil || mismatch(t.footerBorderShape, t.footerWindow.Height(), len(t.footer))) ||3401 len(t.footer) == 0 && t.footerWindow != nil {3402 t.printAll()3403 return true3404 }
5 unmodified lines
3410 needHeaderLinesWindow := t.hasHeaderLinesWindow()3411 if needHeaderLinesWindow {3412 primaryHeaderLines -= t.headerLines3413 }3203 // FIXME: Full redraw is triggered if there are too many lines in the header3204 // so that the header window cannot display all of them.3414 if (needHeaderWindow && t.headerWindow == nil) ||3415 (!needHeaderWindow && t.headerWindow != nil) ||3207 (needHeaderWindow && t.headerWindow != nil && primaryHeaderLines != t.headerWindow.Height()) ||3416 (needHeaderWindow && t.headerWindow != nil && mismatch(t.headerBorderShape, t.headerWindow.Height(), primaryHeaderLines)) ||3417 (needHeaderLinesWindow && t.headerLinesWindow == nil) ||3418 (!needHeaderLinesWindow && t.headerLinesWindow != nil) ||3210 (needHeaderLinesWindow && t.headerLinesWindow != nil && t.headerLines != t.headerLinesWindow.Height()) {3419 (needHeaderLinesWindow && t.headerLinesWindow != nil && mismatch(t.headerLinesShape, t.headerLinesWindow.Height(), t.headerLines)) {3420 t.printAll()3421 return true3422 }3423 return false
3 unmodified lines
3427 if !t.headerVisible {3428 return3429 }34303431 // When an inline section was requested but addInline had no budget, its window is3432 // nil. Don't fall through to withWindow — that would leak header content into the3433 // list window. A nil window is only legitimate when the shape is NOT inline (e.g.3434 // header combined with the list when --no-list-border is in effect).3435 if !(t.headerBorderShape == tui.BorderInline && t.headerWindow == nil) {3222 t.withWindow(t.headerWindow, func() {3223 var headerItems []Item3224 if !t.hasHeaderLinesWindow() {3225 headerItems = t.header3226 }3227 t.printHeaderImpl(t.headerWindow, t.headerBorderShape, t.header0, headerItems)3228 })3229 if w, shape := t.determineHeaderLinesShape(); w {3436 t.withWindow(t.headerWindow, func() {3437 var headerItems []Item3438 if !t.hasHeaderLinesWindow() {3439 headerItems = t.header3440 }3441 t.printHeaderImpl(t.headerWindow, t.headerBorderShape, t.header0, headerItems)3442 })3443 }3444 if w, shape := t.determineHeaderLinesShape(); w &&3445 !(shape == tui.BorderInline && t.headerLinesWindow == nil) {3446 t.withWindow(t.headerLinesWindow, func() {3447 t.printHeaderImpl(t.headerLinesWindow, shape, nil, t.header)3448 })3449 }
42 unmodified lines
3492 indentSize := base3493 if t.listBorderShape.HasLeft() {3494 indentSize += 1 + t.borderWidth3495 }3280 if borderShape.HasLeft() {3496 // Section borders with their own left side skip past the list border's left column.3497 // Inline sections also skip it, but only when the list border actually has a left,3498 // since otherwise the inline window starts flush with the list window.3499 if borderShape.HasLeft() || (borderShape == tui.BorderInline && t.listBorderShape.HasLeft()) {3500 indentSize -= 1 + t.borderWidth3501 if indentSize < 0 {3502 indentSize = 03503 }
2666 unmodified lines
6170 }6171 case reqRedrawInputLabel:6172 t.printLabel(t.inputBorder, t.inputLabel, t.inputLabelOpts, t.inputLabelLen, t.inputBorderShape, true)6173 case reqRedrawHeaderLabel:6174 if t.headerBorderShape == tui.BorderInline {6175 // Inline labels sit on the separator inside wborder; re-run the6176 // full layout to repaint the separator + label together.6177 t.printAll()6178 } else {5955 t.printLabel(t.headerBorder, t.headerLabel, t.headerLabelOpts, t.headerLabelLen, t.headerBorderShape, true)6179 t.printLabel(t.headerBorder, t.headerLabel, t.headerLabelOpts, t.headerLabelLen, t.headerBorderShape, true)6180 }6181 case reqRedrawFooterLabel:6182 if t.footerBorderShape == tui.BorderInline {6183 t.printAll()6184 } else {5957 t.printLabel(t.footerBorder, t.footerLabel, t.footerLabelOpts, t.footerLabelLen, t.footerBorderShape, true)6185 t.printLabel(t.footerBorder, t.footerLabel, t.footerLabelOpts, t.footerLabelLen, t.footerBorderShape, true)6186 }6187 case reqRedrawListLabel:6188 // When inline sections are active, the label's bg depends on which6189 // section owns the adjacent edge. Rerun the layout to reuse that6190 // logic rather than duplicating it here.6191 if t.headerBorderShape == tui.BorderInline || t.headerLinesShape == tui.BorderInline || t.footerBorderShape == tui.BorderInline {6192 t.printAll()6193 } else {5959 t.printLabel(t.wborder, t.listLabel, t.listLabelOpts, t.listLabelLen, t.listBorderShape, true)6194 t.printLabel(t.wborder, t.listLabel, t.listLabelOpts, t.listLabelLen, t.listBorderShape, true)6195 }6196 case reqRedrawBorderLabel:6197 t.printLabel(t.border, t.borderLabel, t.borderLabelOpts, t.borderLabelLen, t.borderShape, true)6198 case reqRedrawPreviewLabel:6199 t.printLabel(t.pborder, t.previewLabel, t.previewLabelOpts, t.previewLabelLen, t.activePreviewOpts.Border(), true)
1982 unmodified lines
modified:test/lib/common.rb+60 added
128 unmodified lines
129 def capture130 go(%W[capture-pane -p -J -t #{win}]).map(&:rstrip).reverse.drop_while(&:empty?).reverse131 end132133 # 3-bit ANSI bg code (40..47) -> color name used in --color options.134 BG_NAMES = %w[black red green yellow blue magenta cyan white].freeze135136 # Parse `tmux capture-pane -e` output into per-row bg ranges. Each row is an137 # array of [col_start, col_end, bg] tuples where bg is one of:138 # 'default'139 # 'red' / 'green' / 'blue' / ... (3-bit names)140 # 'bright-red' / ... (bright variants)141 # '256:<n>' (256-color fallback)142 # ANSI state persists across rows, matching real terminal behavior.143 def bg_ranges144 raw = go(%W[capture-pane -p -J -e -t #{win}])145 bg = 'default'146 raw.map do |row|147 cells = []148 i = 0149 len = row.length150 while i < len151 c = row[i]152 if c == "\e" && row[i + 1] == '['153 j = i + 2154 j += 1 while j < len && row[j] != 'm'155 parts = row[i + 2...j].split(';')156 k = 0157 while k < parts.length158 p = parts[k].to_i159 case p160 when 0, 49 then bg = 'default'161 when 40..47 then bg = BG_NAMES[p - 40]162 when 100..107 then bg = "bright-#{BG_NAMES[p - 100]}"163 when 48164 if parts[k + 1] == '5'165 bg = "256:#{parts[k + 2]}"166 k += 2167 elsif parts[k + 1] == '2'168 bg = "rgb:#{parts[k + 2]}:#{parts[k + 3]}:#{parts[k + 4]}"169 k += 4170 end171 end172 k += 1173 end174 i = j + 1175 else176 cells << bg177 i += 1178 end179 end180 ranges = []181 start = 0182 cells.each_with_index do |b, idx|183 if idx.positive? && b != cells[idx - 1]184 ranges << [start, idx - 1, cells[idx - 1]]185 start = idx186 end187 end188 ranges << [start, cells.length - 1, cells.last] unless cells.empty?189 ranges190 end191 end192193 def until(refresh = false, timeout: DEFAULT_TIMEOUT)194 lines = nil195 begin196 wait(timeout) do
132 unmodified lines
modified:test/test_layout.rb+154 added
1390 unmodified lines
1391 opts: %(--layout=#{layout} --header $'Aaa\\nBbb\\nCcc' --header-lines 3),1392 input: "(printf 'Xaa\\nYbb\\nZcc\\n'; seq 5)",1393 clicks: clicks)1394 end13951396 # Inline header inside a rounded list border.1397 define_method(:"test_click_header_border_inline_#{slug}") do1398 opts = %(--layout=#{layout} --style full --header $'Aaa\\nBbb\\nCcc' --header-border=inline)1399 verify_clicks(kind: :header, opts: opts, input: 'seq 5', clicks: HEADER_CLICKS)1400 end14011402 # Inline header inside a horizontal list border (top+bottom only, no T-junctions).1403 define_method(:"test_click_header_border_inline_horizontal_list_#{slug}") do1404 opts = %(--layout=#{layout} --style full --list-border=horizontal --header $'Aaa\\nBbb\\nCcc' --header-border=inline)1405 verify_clicks(kind: :header, opts: opts, input: 'seq 5', clicks: HEADER_CLICKS)1406 end14071408 # Inline header-lines inside a rounded list border.1409 define_method(:"test_click_header_lines_border_inline_#{slug}") do1410 clicks_hl = if layout == 'default'1411 [%w[Xaa 3], %w[Ybb 2], %w[Zcc 1]]1412 else1413 [%w[Xaa 1], %w[Ybb 2], %w[Zcc 3]]1414 end1415 opts = %(--layout=#{layout} --style full --header-lines 3 --header-lines-border=inline)1416 verify_clicks(kind: :header, opts: opts,1417 input: "(printf 'Xaa\\nYbb\\nZcc\\n'; seq 5)",1418 clicks: clicks_hl)1419 end14201421 # Inline footer inside a rounded list border.1422 define_method(:"test_click_footer_border_inline_#{slug}") do1423 opts = %(--layout=#{layout} --style full --footer $'Foo\\nBar\\nBaz' --footer-border=inline)1424 verify_clicks(kind: :footer, opts: opts, input: 'seq 5',1425 clicks: [%w[Foo 1], %w[Bar 2], %w[Baz 3]])1426 end1427 end14281429 # An inline section requesting far more rows than the terminal can fit must not1430 # break the layout. The list frame must still render inside the pane with both1431 # corners visible and the prompt line present.1432 def test_inline_header_lines_oversized1433 tmux.send_keys %(seq 10000 | #{FZF} --style full --header-border inline --header-lines 9999), :Enter1434 tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+}) }1435 lines = tmux.capture1436 # Rounded (light) and sharp (tcell) default border glyphs.1437 top_corners = /[╭┌]/1438 bottom_corners = /[╰└]/1439 assert(lines.any? { |l| l.match?(top_corners) }, "list frame top missing: #{lines.inspect}")1440 assert(lines.any? { |l| l.match?(bottom_corners) }, "list frame bottom missing: #{lines.inspect}")1441 assert(lines.any? { |l| l.include?('>') }, "prompt missing: #{lines.inspect}")1442 tmux.send_keys 'Escape'1443 end14441445 # A non-inline section that consumes all available rows must still render without1446 # crashing when another section is inline but has no budget. The inline section's1447 # content is clipped to 0 but the layout proceeds.1448 def test_inline_footer_starved_by_non_inline_header1449 tmux.send_keys %(seq 10000 | #{FZF} --style full --footer-border inline --footer "$(seq 1000)" --header "$(seq 1000)"), :Enter1450 tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+}) }1451 lines = tmux.capture1452 assert(lines.any? { |l| l.include?('>') }, "prompt missing: #{lines.inspect}")1453 tmux.send_keys 'Escape'1454 end14551456 # Without a line-drawing --list-border, --header-border=inline must silently1457 # fall back to the `line` style (documented behavior).1458 def test_inline_falls_back_without_list_border1459 tmux.send_keys %(seq 5 | #{FZF} --list-border=none --header HEADER --header-border=inline), :Enter1460 tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+}) }1461 lines = tmux.capture1462 assert(lines.any? { |l| l.include?('HEADER') }, "header missing: #{lines.inspect}")1463 # Neither list frame corners (rounded/sharp) nor T-junction runes appear,1464 # since we've fallen back to a plain line separator.1465 assert(lines.none? { |l| l.match?(/[╭╮╰╯┌┐└┘├┤]/) }, "unexpected frame glyphs: #{lines.inspect}")1466 tmux.send_keys 'Escape'1467 end14681469 # Invalid inline combinations must be rejected at startup.1470 def test_inline_rejected_on_unsupported_options1471 [1472 ['--border=inline', 'inline border is only supported'],1473 ['--list-border=inline', 'inline border is only supported'],1474 ['--input-border=inline', 'inline border is only supported'],1475 ['--preview-window=border-inline --preview :', 'invalid preview window option: border-inline'],1476 ['--header-first --header-border=inline', '--header-first is not compatible'],1477 ['--header-first --header-lines-border=inline --header-lines=1', '--header-first is not compatible'],1478 ['--header-border=inline --header-lines-border=sharp --header-lines=1',1479 '--header-border=inline requires --header-lines-border to be inline or unset']1480 ].each do |args, expected|1481 output = `#{FZF} #{args} < /dev/null 2>&1`1482 refute_equal 0, $CHILD_STATUS.exitstatus, "expected non-zero exit for: #{args}"1483 assert_includes output, expected, "wrong error for: #{args}"1484 end1485 end14861487 private14881489 # Count rows whose entire width is a single `color` range.1490 def count_full_rows(ranges_by_row, color)1491 ranges_by_row.count { |r| r.length == 1 && r[0][2] == color }1492 end14931494 # Wait until `tmux.bg_ranges` has at least `count` fully-`color` rows; return them.1495 def wait_for_full_rows(color, count)1496 ranges = nil1497 tmux.until do |_|1498 ranges = tmux.bg_ranges1499 count_full_rows(ranges, color) >= count1500 end1501 ranges1502 end15031504 public15051506 # Inline header's entire section (outer edge + content-row verticals + separator)1507 # carries the header-bg color; list rows below carry list-bg.1508 def test_inline_header_bg_color1509 tmux.send_keys %(seq 5 | #{FZF} --list-border --reverse --header HEADER --header-border=inline --color=bg:-1,header-border:white,list-border:white,header-bg:red,list-bg:green), :Enter1510 tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+}) }1511 # 3 fully-red rows: top edge, header content, separator.1512 ranges = wait_for_full_rows('red', 3)1513 assert_equal_org(3, count_full_rows(ranges, 'red'))1514 # List rows below (>=5) are fully green.1515 assert_operator count_full_rows(ranges, 'green'), :>=, 51516 tmux.send_keys 'Escape'1517 end15181519 # Regression: when --header-lines-border=inline is the only inline section1520 # (no --header-border), the section must still use header-bg, not list-bg.1521 def test_inline_header_lines_bg_without_main_header1522 tmux.send_keys %(seq 5 | #{FZF} --list-border --reverse --header-lines 2 --header-lines-border=inline --color=bg:-1,header-border:white,list-border:white,header-bg:red,list-bg:green), :Enter1523 tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+}) }1524 # Top edge + 2 content rows + separator = 4 fully-red rows.1525 ranges = wait_for_full_rows('red', 4)1526 assert_equal_org(4, count_full_rows(ranges, 'red'))1527 tmux.send_keys 'Escape'1528 end15291530 # Inline footer's entire section carries footer-bg; list rows above carry list-bg.1531 def test_inline_footer_bg_color1532 tmux.send_keys %(seq 5 | #{FZF} --list-border --footer FOOTER --footer-border=inline --color=bg:-1,footer-border:white,list-border:white,footer-bg:blue,list-bg:green), :Enter1533 tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+}) }1534 ranges = wait_for_full_rows('blue', 3)1535 assert_equal_org(3, count_full_rows(ranges, 'blue'))1536 tmux.send_keys 'Escape'1537 end15381539 # The list-label's bg is swapped to match the adjacent inline section so it reads as1540 # part of the section frame rather than a list-colored island on a section-colored edge.1541 def test_list_label_bg_on_inline_section_edge1542 tmux.send_keys %(seq 5 | #{FZF} --list-border --reverse --header HEADER --header-border=inline --list-label=LL --color=bg:-1,header-border:white,list-border:white,header-bg:red,list-bg:green,list-label:yellow:bold), :Enter1543 tmux.until { |lines| lines.any_include?(%r{ [0-9]+/[0-9]+}) }1544 # The label sits on the header-owned top edge, so the entire row must be a1545 # single red run (no green breaks where the label cells are).1546 ranges = wait_for_full_rows('red', 3)1547 assert_operator count_full_rows(ranges, 'red'), :>=, 31548 tmux.send_keys 'Escape'1549 end1550end
modified:CHANGELOG.md+16 added
1CHANGELOG2=========340.72.05------6- `--header-border`, `--header-lines-border`, and `--footer-border` now accept a new `inline` style that embeds the section inside the list frame, separated from the list content by a horizontal line whose endpoints join the surrounding list border as T-junctions.7 - Requires `--list-border` with a line-drawing shape (rounded / sharp / bold / double / horizontal); falls back to `line` otherwise.8 - Sections stack. Example combining all three:9 ```sh10 ps -ef | fzf --reverse --style full:double \11 --header 'Select a process' --header-lines 1 \12 --bind 'load:transform-footer:echo $FZF_TOTAL_COUNT processes' \13 --header-border=inline --header-lines-border=inline \14 --footer-border=inline15 ```16 - `--header-label` and `--footer-label` render on their respective separator row.17 - The separator inherits `--color list-border` when the section's own border color is not explicitly set.18 - `--header-first` is not compatible with `--header-border=inline` or `--header-lines-border=inline`; `--header-border=inline` requires `--header-lines-border` to be `inline` or unset.19200.71.021------22_Release highlights: https://junegunn.github.io/fzf/releases/0.71.0/_23
3253 unmodified lines