Skip to content

Commit

Permalink
fix: prevents table from throwing with negative numbers in .repeat() (
Browse files Browse the repository at this point in the history
  • Loading branch information
leifssm authored Jan 29, 2024
1 parent cad3c03 commit b773573
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,16 @@ export class Table extends Component {
let string = "";
let prevData = "";
for (const [j, dataCell] of dataRow.entries()) {
if (j !== 0) string += " ".repeat(headers[j - 1].width - textWidth(prevData) + 1);
if (j !== 0) {
const padding = Math.max(0, headers[j - 1].width - textWidth(prevData) + 1);
string += " ".repeat(padding);
}
string += dataCell;
prevData = dataCell;
}

string += " ".repeat(this.rectangle.value.width - textWidth(string) - 2);
const endPadding = Math.max(0, this.rectangle.value.width - textWidth(string) - 2);
string += " ".repeat(endPadding);
return string;
}),
rectangle: new Computed(() => {
Expand Down

0 comments on commit b773573

Please sign in to comment.