| 352 | } |
| 353 | |
| 354 | export function formatTableEvent(event: TableRenderItem | TableTextBlock): string { |
| 355 | const lines: string[] = []; |
| 356 | const heading = |
| 357 | 'heading' in event ? (event.heading ?? ('name' in event ? event.name : undefined)) : undefined; |
| 358 | if (heading) { |
| 359 | lines.push(heading); |
| 360 | lines.push(''); |
| 361 | } |
| 362 | |
| 363 | if (event.columns.length === 0 || event.rows.length === 0) { |
| 364 | return lines.join('\n'); |
| 365 | } |
| 366 | |
| 367 | const colWidths = event.columns.map((col) => col.length); |
| 368 | for (const row of event.rows) { |
| 369 | for (let i = 0; i < event.columns.length; i++) { |
| 370 | const value = row[event.columns[i]] ?? ''; |
| 371 | colWidths[i] = Math.max(colWidths[i], value.length); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | const headerLine = event.columns.map((col, i) => col.padEnd(colWidths[i])).join(' '); |
| 376 | lines.push(headerLine); |
| 377 | lines.push(colWidths.map((w) => '-'.repeat(w)).join(' ')); |
| 378 | |
| 379 | for (const row of event.rows) { |
| 380 | const rowLine = event.columns.map((col, i) => (row[col] ?? '').padEnd(colWidths[i])).join(' '); |
| 381 | lines.push(rowLine); |
| 382 | } |
| 383 | |
| 384 | return lines.join('\n'); |
| 385 | } |
| 386 | |
| 387 | export function formatFileRefEvent( |
| 388 | event: ArtifactRenderItem | FileRefRenderItem | FileRefTextBlock, |