Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/charmbracelet/harmonica v0.2.0
github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1
github.com/charmbracelet/x/ansi v0.8.0
github.com/charmbracelet/x/exp/golden v0.0.0-20250207160936-21c02780d27a
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f
github.com/dustin/go-humanize v1.0.1
github.com/lucasb-eyer/go-colorful v1.2.0
github.com/mattn/go-runewidth v0.0.16
Expand All @@ -18,7 +18,7 @@ require (
)

require (
github.com/aymanbagabas/go-udiff v0.2.0 // indirect
github.com/aymanbagabas/go-udiff v0.3.1 // indirect
github.com/charmbracelet/colorprofile v0.3.0 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
github.com/charmbracelet/x/input v0.3.4 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
github.com/aymanbagabas/go-udiff v0.3.1 h1:LV+qyBQ2pqe0u42ZsUEtPiCaUoqgA9gYRDs3vj1nolY=
github.com/aymanbagabas/go-udiff v0.3.1/go.mod h1:G0fsKmG+P6ylD0r6N/KgQD/nWzgfnl8ZBcNLgcbrw8E=
github.com/charmbracelet/bubbletea/v2 v2.0.0-beta.1 h1:RvpXiXuPAuaKCHPCsE/lK5+zztnNDTSCa0CpeeIKdDU=
github.com/charmbracelet/bubbletea/v2 v2.0.0-beta.1/go.mod h1:qbcZLI5z8R49v9xBdU5V5Dh5D2uccx8wSwBqxQyErqc=
github.com/charmbracelet/colorprofile v0.3.0 h1:KtLh9uuu1RCt+Hml4s6Hz+kB1PfV3wi++1h5ia65yKQ=
Expand All @@ -18,6 +20,8 @@ github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ
github.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/exp/golden v0.0.0-20250207160936-21c02780d27a h1:FsHEJ52OC4VuTzU8t+n5frMjLvpYWEznSr/u8tnkCYw=
github.com/charmbracelet/x/exp/golden v0.0.0-20250207160936-21c02780d27a/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6gmGpCE7F3FcjaOEKYriCvpmIN4+6OS/RD0vm4uIA=
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f/go.mod h1:IfZAMTHB6XkZSeXUqriemErjAWCCzT0LwjKFYCZyw0I=
github.com/charmbracelet/x/input v0.3.4 h1:Mujmnv/4DaitU0p+kIsrlfZl/UlmeLKw1wAP3e1fMN0=
github.com/charmbracelet/x/input v0.3.4/go.mod h1:JI8RcvdZWQIhn09VzeK3hdp4lTz7+yhiEdpEQtZN+2c=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
Expand Down
34 changes: 27 additions & 7 deletions table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ func TestModel_RenderRow(t *testing.T) {
func TestTableAlignment(t *testing.T) {
t.Run("No border", func(t *testing.T) {
biscuits := New(
WithWidth(59),
WithHeight(5),
WithColumns([]Column{
{Title: "Name", Width: 25},
Expand Down Expand Up @@ -319,6 +320,7 @@ func TestTableAlignment(t *testing.T) {
Bold(false)

biscuits := New(
WithWidth(59),
WithHeight(5),
WithColumns([]Column{
{Title: "Name", Width: 25},
Expand Down Expand Up @@ -515,15 +517,19 @@ func TestModel_View(t *testing.T) {
modelFunc func() Model
skip bool
}{
// TODO(?): should the view/output of empty tables use the same default height? (this has height 21)
"Empty": {
modelFunc: func() Model {
return New()
return New(
WithWidth(60),
WithHeight(21),
)
},
},
"Single row and column": {
modelFunc: func() Model {
return New(
WithWidth(27),
WithHeight(21),
WithColumns([]Column{
{Title: "Name", Width: 25},
}),
Expand All @@ -536,6 +542,8 @@ func TestModel_View(t *testing.T) {
"Multiple rows and columns": {
modelFunc: func() Model {
return New(
WithWidth(59),
WithHeight(21),
WithColumns([]Column{
{Title: "Name", Width: 25},
{Title: "Country of Origin", Width: 16},
Expand All @@ -557,6 +565,7 @@ func TestModel_View(t *testing.T) {
s.Cell = lipgloss.NewStyle().Padding(2, 2)

return New(
WithWidth(60),
WithHeight(10),
WithColumns([]Column{
{Title: "Name", Width: 25},
Expand All @@ -579,6 +588,7 @@ func TestModel_View(t *testing.T) {
s.Cell = lipgloss.NewStyle()

return New(
WithWidth(53),
WithHeight(10),
WithColumns([]Column{
{Title: "Name", Width: 25},
Expand All @@ -594,10 +604,12 @@ func TestModel_View(t *testing.T) {
)
},
},
// TODO(?): the total height is modified with borderd headers, however not with bordered cells. Is this expected/desired?
// TODO(?): the total height is modified with bordered headers, however not with bordered cells. Is this expected/desired?
"Bordered headers": {
modelFunc: func() Model {
return New(
WithWidth(59),
WithHeight(23),
WithColumns([]Column{
{Title: "Name", Width: 25},
{Title: "Country of Origin", Width: 16},
Expand All @@ -618,6 +630,8 @@ func TestModel_View(t *testing.T) {
"Bordered cells": {
modelFunc: func() Model {
return New(
WithWidth(59),
WithHeight(21),
WithColumns([]Column{
{Title: "Name", Width: 25},
{Title: "Country of Origin", Width: 16},
Expand All @@ -634,9 +648,10 @@ func TestModel_View(t *testing.T) {
)
},
},
"Manual height greater than rows": {
"Height greater than rows": {
modelFunc: func() Model {
return New(
WithWidth(59),
WithHeight(6),
WithColumns([]Column{
{Title: "Name", Width: 25},
Expand All @@ -651,9 +666,10 @@ func TestModel_View(t *testing.T) {
)
},
},
"Manual height less than rows": {
"Height less than rows": {
modelFunc: func() Model {
return New(
WithWidth(59),
WithHeight(2),
WithColumns([]Column{
{Title: "Name", Width: 25},
Expand All @@ -669,10 +685,11 @@ func TestModel_View(t *testing.T) {
},
},
// TODO(fix): spaces are added to the right of the viewport to fill the width, but the headers end as though they are not aware of the width.
"Manual width greater than columns": {
"Width greater than columns": {
modelFunc: func() Model {
return New(
WithWidth(80),
WithHeight(21),
WithColumns([]Column{
{Title: "Name", Width: 25},
{Title: "Country of Origin", Width: 16},
Expand All @@ -688,10 +705,11 @@ func TestModel_View(t *testing.T) {
},
// TODO(fix): Setting the table width does not affect the total headers' width. Cells are wrapped.
// Headers are not affected. Truncation/resizing should match lipgloss.table functionality.
"Manual width less than columns": {
"Width less than columns": {
modelFunc: func() Model {
return New(
WithWidth(30),
WithHeight(15),
WithColumns([]Column{
{Title: "Name", Width: 25},
{Title: "Country of Origin", Width: 16},
Expand All @@ -709,6 +727,8 @@ func TestModel_View(t *testing.T) {
"Modified viewport height": {
modelFunc: func() Model {
m := New(
WithWidth(59),
WithHeight(15),
WithColumns([]Column{
{Title: "Name", Width: 25},
{Title: "Country of Origin", Width: 16},
Expand Down
42 changes: 22 additions & 20 deletions table/testdata/TestModel_View/Bordered_headers.golden
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
┌─────────────────────────┐┌────────────────┐┌────────────┐
│Name ││Country of Orig…││Dunk-able │
└─────────────────────────┘└────────────────┘└────────────┘
Chocolate Digestives UK Yes
Tim Tams Australia No
Hobnobs UK Yes

















Chocolate Digestives UK Yes
Tim Tams Australia No
Hobnobs UK Yes



















39 changes: 20 additions & 19 deletions table/testdata/TestModel_View/Empty.golden
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@








































18 changes: 9 additions & 9 deletions table/testdata/TestModel_View/Extra_padding.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
  Name     Country of Orig…    Dunk-able   


  Chocolate Digestives     UK     Yes   
  Tim Tams     Australia     No   


  Chocolate Digestives     UK     Yes




  Tim Tams     Australia     No

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
╭────────────────────────────────────────╮
│ll know how many foes you've defeated. │
╰────────────────────────────────────────╯
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
╭────────────────────────────────────────╮
│cter Zote from an awesome "Hollow knight│
╰────────────────────────────────────────╯
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
╭────────────────────────────────────────╮
│" game (https://store.steampowered.com/a│
╰────────────────────────────────────────╯
3 changes: 3 additions & 0 deletions viewport/testdata/TestSizing/view-40x1-softwrap.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
╭────────────────────────────────────────╮
│57 Precepts of narcissistic comedy chara│
╰────────────────────────────────────────╯
3 changes: 3 additions & 0 deletions viewport/testdata/TestSizing/view-40x1.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
╭────────────────────────────────────────╮
│57 Precepts of narcissistic comedy chara│
╰────────────────────────────────────────╯
19 changes: 19 additions & 0 deletions viewport/testdata/TestSizing/view-40x100percent.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
╭──────────────────────────────────────╮
│57 Precepts of narcissistic comedy cha│
│Precept One: 'Always Win Your Battles'│
│ │
│Precept Two: 'Never Let Them Laugh at │
│Precept Three: 'Always Be Rested'. Fig│
│Precept Four: 'Forget Your Past'. The │
│Precept Five: 'Strength Beats Strength│
│Precept Six: 'Choose Your Own Fate'. O│
│Precept Seven: 'Mourn Not the Dead'. W│
│Precept Eight: 'Travel Alone'. You can│
│Precept Nine: 'Keep Your Home Tidy'. Y│
│Precept Ten: 'Keep Your Weapon Sharp'.│
│Precept Eleven: 'Mothers Will Always B│
│Precept Twelve: 'Keep Your Cloak Dry'.│
│Precept Thirteen: 'Never Be Afraid'. F│
│Precept Fourteen: 'Respect Your Superi│
│Precept Fifteen: 'One Foe, One Blow'. │
╰──────────────────────────────────────╯
15 changes: 15 additions & 0 deletions viewport/testdata/TestSizing/view-50x15-content-lines.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
57 Precepts of narcissistic comedy character Zote
awesome "Hollow knight" game













Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
╭────────────────────────────────────────────────╮
│Precept Thirteen: 'Never Be Afraid'. Fear can on│
│ly hold you back. Facing your fears can be a tre│
│mendous effort. Therefore, you should just not b│
│e afraid in the first place. │
│Precept Fourteen: 'Respect Your Superiors'. If s│
│omeone is your superior in strength or intellect│
│ or both, you need to show them your respect. Do│
│n't ignore them or laugh at them. │
│Precept Fifteen: 'One Foe, One Blow'. You should│
│ only use a single blow to defeat an enemy. Any │
│more is a waste. Also, by counting your blows as│
│ you fight, you'll know how many foes you've def│
│eated. │
╰────────────────────────────────────────────────╯
15 changes: 15 additions & 0 deletions viewport/testdata/TestSizing/view-50x15-softwrap-at-top.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
╭────────────────────────────────────────────────╮
│57 Precepts of narcissistic comedy character Zot│
│e from an awesome "Hollow knight" game (https://│
│store.steampowered.com/app/367520/Hollow_Knight/│
│). │
│Precept One: 'Always Win Your Battles'. Losing a│
│ battle earns you nothing and teaches you nothin│
│g. Win your battles, or don't engage in them at │
│all! │
│ │
│Precept Two: 'Never Let Them Laugh at You'. Fool│
│s laugh at everything, even at their superiors. │
│But beware, laughter isn't harmless! Laughter sp│
│reads like a disease, and soon everyone is laugh│
╰────────────────────────────────────────────────╯
Loading
Loading