Merge branch 'pr-4024' into batch/rudycelekli-fixes

This commit is contained in:
r committed 2026-10-11 10:45:19 -04:00
commit 78cd445550
2 files changed
+11 -3

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
import { test } from 'vitest';
import assert from 'node:assert/strict';
import { OutputFormatter } from '../v3/@claude-flow/cli-core/src/output.ts';
test('maxWidth accounts for configured padding', () => {
const f = new OutputFormatter({ color: false });
for (const padding of [0, 1, 2, 3]) { const table = f.table({ columns: [{ key: 'a', header: 'A' }, { key: 'b', header: 'B' }], data: [{ a: 'a'.repeat(30), b: 'b'.repeat(30) }], padding, maxWidth: 40 }); for (const line of table.split('\n')) assert.ok(line.length <= 40, `padding=${padding} width=${line.length}`); }
});
+4 -3
View File
@@ -224,7 +224,7 @@ export class OutputFormatter {
const { columns, data, border = true, header = true, padding = 1, maxWidth } = options;
// Calculate column widths
const widths = this.calculateColumnWidths(columns, data, maxWidth);
const widths = this.calculateColumnWidths(columns, data, maxWidth, padding);
const lines: string[] = [];
const pad = ' '.repeat(padding);
@@ -294,7 +294,8 @@ export class OutputFormatter {
private calculateColumnWidths(
columns: TableColumn[],
data: Record<string, unknown>[],
maxWidth?: number
maxWidth?: number,
padding: number = 1
): number[] {
const widths = columns.map((col, i) => {
// Start with header width
@@ -320,7 +321,7 @@ export class OutputFormatter {
// Apply max width constraint
if (maxWidth) {
const totalWidth = widths.reduce((a, b) => a + b, 0) + (columns.length * 3) + 1;
const totalWidth = widths.reduce((a, b) => a + b, 0) + (columns.length * (2 * padding + 1)) + 1;
if (totalWidth > maxWidth) {
const reduction = (totalWidth - maxWidth) / columns.length;
return widths.map(w => Math.max(3, Math.floor(w - reduction)));