Repository navigation
Conversation
Use the supplied stream for both writes and the terminal width. Keep stdout as the default destination. Signed-off-by: Sakana <15715093608@163.com>
| const chunkLen = strip(chunk).length; | ||
| if (lineWidth + chunkLen < process.stdout.columns) { | ||
| const columns = | ||
| 'columns' in output && typeof output.columns === 'number' ? output.columns : 0; |
There was a problem hiding this comment.
[P2] Use a usable width when the selected output has no columns
A plain Node.js Writable, or process.stderr redirected to a file or pipe, has no columns property. Falling back to 0 makes lineWidth + chunkLen < columns always false, so every chunk gets a leading newline and indentation, and trimStart() removes its leading whitespace. For example, stream.message(['hel', 'lo', ' world'], { output, symbol: '!' }) writes "! \n hel\n lo\n world\n" instead of "! hello world\n". This splits words at arbitrary chunk boundaries on the newly supported output destinations.
Please use getColumns(output) from @clack/core, as the other renderers do, or disable wrapping when width is unavailable. Add a regression case with a plain Writable that does not define columns; the new capture(10) test does not cover this case.
The default stdout path already had a similar issue without a terminal width; this finding concerns the incomplete support for custom outputs added here.
A plain Writable and a redirected standard stream have no column count. Skip width-based wrapping on these destinations so chunk boundaries preserve words and leading whitespace. Signed-off-by: Sakana <15715093608@163.com>
Signed-off-by: Sakana <15715093608@163.com>
Summary
A CLI can send logs to stderr and write a JSON result to stdout. When it passes stderr to
stream.message, the message still goes to stdout, so a downstream command cannot parse the result.The renderer uses the selected output's width to wrap text. If the output has no column count, it writes consecutive chunks without adding line breaks between them. This also keeps words together when the caller uses the default stdout and redirects it to a file or pipe.
Evidence
! hello worldto redirected stderr and only{"ok":true}to stdout.['some', 'thing', ' else']to a plain Node.jsWritable. It reproduced the split word before the repair and now receives one line. A separate test checks wrapping at 10 columns and detects stray writes to stdout.Merge Danger
Door: Two-way.
Blast Radius: Streamed prompt messages with an explicit output or a redirected stdout.