-
Notifications
You must be signed in to change notification settings - Fork 14
Description
[Feature request] Add column width limits for table formatting
Problem
When a table column contains long content, the formatter wraps the text across multiple lines, which makes the table output ugly and hard to read. This is particularly noticeable when displaying tables in terminals or narrow viewports.
Context
The opencode-md-table-formatter plugin is used to format Markdown tables. In real-world usage, tables often contain varying content lengths - some columns may have short values (like IDs or names) while others have longer text (like descriptions or paths). Currently, there's no way to control how wide a column can be, leading to suboptimal formatting when content exceeds reasonable display limits.
Request
Add support for limiting column widths in table formatting. Two possible approaches:
-
Configurable max column width: Allow users to set a maximum width (in characters) for table columns. Content exceeding this limit should wrap within the cell (using Markdown line breaks
<br>) instead of causing the entire table row to break across multiple lines due to terminal width constraints. -
Terminal width detection: Automatically detect the terminal width and adjust table formatting accordingly, ensuring tables fit within the available screen space.
Example
Current Behavior (Problem)
When a column has long content, the terminal forces a line break that breaks the table structure:
| ID | Name | Description |
|----|-------------|--------------------------------------------------------------|
| 1 | ShortName | This is a very long description that gets wrapped by the ter|
minal and makes the table look broken and ugly |
| 2 | AnotherName | Short desc |
Expected Behavior
With maxColumnWidth set, content wraps within the cell using <br>:
| ID | Name | Description |
|----|-------------|--------------------------------------------------------------|
| 1 | ShortName | This is a very long description that<br>gets wrapped within the cell neatly |
| 2 | AnotherName | Short desc |Rendered result in terminal:
| ID | Name | Description |
|----|-------------|------------------------------------------|
| 1 | ShortName | This is a very long description that |
| | | gets wrapped within the cell neatly |
| 2 | AnotherName | Short desc |
Proposed Solution
Consider implementing both options:
Option 1: Configuration-based approach
Add a configuration option such as:
{
"maxColumnWidth": 50
}When content exceeds maxColumnWidth, insert <br> tags to wrap text within the cell, keeping the table structure intact and preventing terminal-forced line breaks.
Option 2: Terminal-aware approach
Detect terminal width using process.stdout.columns (Node.js) or equivalent, and:
- Calculate optimal column widths based on available space
- Proportionally distribute width across columns
- Wrap content within cells using
<br>as needed
A combination approach would be ideal - default to terminal width detection, but allow manual override via configuration.
Additional Notes
- Many terminal table libraries (like
cli-table,console.table) already implement similar functionality - This would significantly improve the user experience when working with tables containing heterogeneous data
- Consider adding column-specific width overrides for fine-grained control