Skip to content

Commit 9500f10

Browse files
committed
fix(table): ensure we're passing the right row index to styleFunc
1 parent 7b191c5 commit 9500f10

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

table/resizing.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ import (
4545
//
4646
// The biggest difference is 15 - 2, so we can shrink the 2nd column by 13.
4747
func (t *Table) resize() {
48+
hasHeaders := len(t.headers) > 0
4849
rows := dataToMatrix(t.data)
4950
r := newResizer(t.width, t.height, t.headers, rows)
5051
r.wrap = t.wrap
5152
r.borderColumn = t.borderColumn
5253
r.yPaddings = make([][]int, len(r.allRows))
5354

5455
var allRows [][]string
55-
if len(t.headers) > 0 {
56+
if hasHeaders {
5657
allRows = append([][]string{t.headers}, rows...)
5758
} else {
5859
allRows = rows
@@ -65,7 +66,14 @@ func (t *Table) resize() {
6566

6667
for j := range row {
6768
column := &r.columns[j]
68-
style := t.styleFunc(i, j)
69+
70+
// Making sure we're passing the right index to `styleFunc`. The header row should be `-1` and
71+
// the others should start from `0`.
72+
rowIndex := i
73+
if hasHeaders {
74+
rowIndex--
75+
}
76+
style := t.styleFunc(rowIndex, j)
6977

7078
topMargin, rightMargin, bottomMargin, leftMargin := style.GetMargin()
7179
topPadding, rightPadding, bottomPadding, leftPadding := style.GetPadding()

0 commit comments

Comments
 (0)