diff --git a/tests/output-narrow-columns.test.mjs b/tests/output-narrow-columns.test.mjs new file mode 100644 index 0000000000..637b4b7eb6 --- /dev/null +++ b/tests/output-narrow-columns.test.mjs @@ -0,0 +1,11 @@ +import { test } from 'vitest'; +import assert from 'node:assert/strict'; +import { OutputFormatter } from '../v3/@claude-flow/cli-core/src/output.ts'; +test('one to three character columns never overflow their border', () => { + const f = new OutputFormatter({ color: false }); + for (const width of [1, 2, 3, 4]) { + const lines = f.table({ columns: [{ key: 'value', header: 'Header', width }], data: [{ value: 'Longer content' }] }).split('\n'); + for (const line of lines) assert.equal(line.length, lines[0].length); + assert.equal(lines[0].length, width + 4); + } +}); diff --git a/v3/@claude-flow/cli-core/src/output.ts b/v3/@claude-flow/cli-core/src/output.ts index 1c93031f63..f60bf62f7b 100644 --- a/v3/@claude-flow/cli-core/src/output.ts +++ b/v3/@claude-flow/cli-core/src/output.ts @@ -371,6 +371,7 @@ export class OutputFormatter { private truncate(text: string, maxLength: number): string { const stripped = this.stripAnsi(text); if (stripped.length <= maxLength) return text; + if (maxLength <= 3) return '.'.repeat(Math.max(0, maxLength)); return stripped.slice(0, maxLength - 3) + '...'; }