diff --git a/table/table_test.go b/table/table_test.go index 80dcc69b..8b856bb0 100644 --- a/table/table_test.go +++ b/table/table_test.go @@ -209,6 +209,7 @@ func TestSetStyleFunc(t *testing.T) { func TestWithStyleFunc(t *testing.T) { t.Run("single cell styling", func(t *testing.T) { + // #502 s := DefaultStyles() s.BorderHeader = false biscuits := New( @@ -237,6 +238,7 @@ func TestWithStyleFunc(t *testing.T) { golden.RequireEqual(t, []byte(biscuits.View())) }) t.Run("cell styling by content", func(t *testing.T) { + // #502 rows := []Row{ {"Chocolate Digestives", "UK", "Yes"}, {"Tim Tams", "Australia", "No"}, @@ -268,4 +270,30 @@ func TestWithStyleFunc(t *testing.T) { })) golden.RequireEqual(t, []byte(biscuits.View())) }) + t.Run("change column text alignment", func(t *testing.T) { + // #399 + s := DefaultStyles() + s.BorderHeader = false + biscuits := New( + WithColumns([]Column{ + {Title: "Name", Width: 25}, + {Title: "Country of Origin", Width: 16}, + {Title: "Dunk-able", Width: 12}, + }), + WithRows([]Row{ + {"Chocolate Digestives", "UK", "Yes"}, + {"Tim Tams", "Australia", "No"}, + {"Hobnobs", "UK", "Yes"}, + }), + WithStyleFunc(func(row, col int) lipgloss.Style { + if row == table.HeaderRow { + return s.Header + } + if col == 1 { + return s.Cell.Align(lipgloss.Right) + } + return s.Cell + })) + golden.RequireEqual(t, []byte(biscuits.View())) + }) } diff --git a/table/testdata/TestWithStyleFunc/change_column_text_alignment.golden b/table/testdata/TestWithStyleFunc/change_column_text_alignment.golden new file mode 100644 index 00000000..2bbba1e9 --- /dev/null +++ b/table/testdata/TestWithStyleFunc/change_column_text_alignment.golden @@ -0,0 +1,7 @@ +╭──────────────────────┬───────────────────┬───────────╮ +│ Name │ Country of Origin │ Dunk-able │ +├──────────────────────┼───────────────────┼───────────┤ +│ Chocolate Digestives │ UK│ Yes │ +│ Tim Tams │ Australia│ No │ +│ Hobnobs │ UK│ Yes │ +╰──────────────────────┴───────────────────┴───────────╯