Skip to content

Commit

Permalink
fix: handle no data
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Oct 23, 2024
1 parent 7bcb545 commit 90257fe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function determineConfiguredWidth(
* This allows us to use the minimum width required to display the table if the configured width is too small.
*/
function determineWidthToUse<T>(columns: Column<T>[], configuredWidth: number): number {
const tableWidth = columns.map((c) => c.width).reduce((a, b) => a + b) + columns.length + 1
const tableWidth = columns.map((c) => c.width).reduce((a, b) => a + b, 0) + columns.length + 1
return tableWidth < configuredWidth ? configuredWidth : tableWidth
}

Expand Down Expand Up @@ -458,7 +458,7 @@ const createStdout = (): FakeStdout => {
const stripped = stripAnsi(f)
return stripped !== '' && stripped !== '\n'
})
.at(-1)
.at(-1) ?? ''

return stdout
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function getColumns<T extends Record<string, unknown>>(config: Config<T>,
const numberOfBorders = widths.length + 1

const calculateTableWidth = (widths: Column<T>[]) =>
widths.map((w) => w.width + w.padding * 2).reduce((a, b) => a + b) + numberOfBorders
widths.map((w) => w.width + w.padding * 2).reduce((a, b) => a + b, 0) + numberOfBorders

// If the table is too wide, reduce the width of the largest column as little as possible to fit the table.
// At most, it will reduce the width to the length of the column's header plus padding.
Expand Down

0 comments on commit 90257fe

Please sign in to comment.