1
0
mirror of https://github.com/mum4k/termdash.git synced 2025-05-08 19:29:25 +08:00

BugFix: getWrapMode called before hierarchical options had links to parents.

This commit is contained in:
Jakub Sobon 2019-03-18 22:21:36 -04:00
parent bfbdede5a8
commit 609a731487
No known key found for this signature in database
GPG Key ID: F2451A77FB05D3B7
3 changed files with 25 additions and 4 deletions

View File

@ -283,6 +283,7 @@ func (c *Content) addRow(row *Row) error {
row.hierarchical.parent = c.opts.hierarchical
for _, tableCell := range row.cells {
tableCell.hierarchical.parent = row.hierarchical
tableCell.trimmable = tableCell.hierarchical.getWrapMode() == wrap.Never
for _, tableData := range tableCell.data {
for _, dataCell := range tableData.cells {
if !dataCell.Opts.IsDefault() {

View File

@ -187,9 +187,6 @@ func NewCellWithOpts(data []*Data, opts ...CellOption) *Cell {
for _, opt := range opts {
opt.set(c)
}
// We trim when we don't wrap.
c.trimmable = c.hierarchical.getWrapMode() == wrap.Never
return c
}

View File

@ -169,7 +169,7 @@ func TestColumnWidths(t *testing.T) {
want: []columnWidth{1, 3},
},
{
desc: "cells that wrap aren't accounted for",
desc: "cells that wrap aren't accounted for, wrap configured at cell level",
columns: Columns(2),
rows: []*Row{
NewRow(
@ -203,6 +203,29 @@ func TestColumnWidths(t *testing.T) {
cvsWidth: 4,
want: []columnWidth{2, 2},
},
{
desc: "cells that wrap aren't accounted for, wrap configured at content level",
columns: Columns(2),
rows: []*Row{
NewRow(
NewCell("ab"),
NewCell("cde"),
),
NewRow(
NewCell("a"),
NewCell("cde"),
),
NewRow(
NewCell(""),
NewCell("cde"),
),
},
opts: []ContentOption{
WrapAtWords(),
},
cvsWidth: 4,
want: []columnWidth{2, 2},
},
{
desc: "two columns, canvas not wide enough, optimal to trim second",
columns: Columns(2),