Evertras / bubble-table

A customizable, interactive table component for the Bubble Tea framework
MIT License
451 stars 27 forks source link

Render missing data for columns with format string #155

Closed robertjli closed 1 year ago

robertjli commented 1 year ago

If a column has a format string, and a row is missing data in that column, an unexpected error is shown.

table.New([]table.Column{
    table.NewColumn(columnKeyName, "Name", 13),
    table.NewColumn(columnKeyElement, "Element", 10),
    table.NewColumn(columnKeyHeight, "Height", 16).WithFormatString("%.2f m"),
}).WithRows([]table.Row{
    table.NewRow(table.RowData{
        columnKeyName:    "Pikachu",
        columnKeyElement: "Electric",
        // height is missing
    }),
    table.NewRow(table.RowData{
        columnKeyName:    "Charmander",
        columnKeyElement: "Fire",
        columnKeyHeight:  0.6,
    }),
})
┏━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
┃         Name┃   Element┃          Height┃
┣━━━━━━━━━━━━━╋━━━━━━━━━━╋━━━━━━━━━━━━━━━━┫
┃      Pikachu┃  Electric┃  %!f(string=) m┃
┃   Charmander┃      Fire┃          0.60 m┃
┗━━━━━━━━━━━━━┻━━━━━━━━━━┻━━━━━━━━━━━━━━━━┛

This PR fixes the bug by only setting the format string if data exists.