You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add streamPreview API for live streaming output preview
## Problem
`streamPreview` only handled `\n`-terminated lines. Programs like `curl`
that use `\r` (carriage return) to update progress in-place were not
displayed — the data stayed buffered and invisible.
## Changes
- Handle `\r` in both completed lines and partial lines — keep content
after last `\r`
- Flush partial lines to display so `\r`-only updates render immediately
- Include partial line content in flush output
- Updated example to use `curl` and `ping` (real commands)
- Added test: `handles carriage return for in-place updates`
- Also includes sort-order fix (stacked on #33)
Stacks on: pvtnbr/tasuku#33
Copy file name to clipboardExpand all lines: README.md
+31-1Lines changed: 31 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -257,6 +257,7 @@ type TaskFunction = (taskInnerApi: {
257
257
setOutput(output:string| { message:string }):void
258
258
setWarning(warning:Error|string):void
259
259
setError(error:Error|string):void
260
+
streamPreview:Writable
260
261
startTime():void
261
262
stopTime():number
262
263
}) =>Promise<unknown>
@@ -281,6 +282,28 @@ Call with a string to set the output of the task.
281
282
282
283
<img src=".github/media/task-output.png">
283
284
285
+
#### streamPreview
286
+
A `Writable` stream for displaying live output below the task. Pipe a child process or any readable stream into it to show a scrolling preview of the output.
287
+
288
+
Handles both `\n` (newline) and `\r` (carriage return) — programs like `curl` that use `\r` for in-place progress bars work out of the box.
By default, shows the last 5 lines. Use the `previewLines` option to change this. When there are more lines than the limit, a `(+ N lines)` indicator is shown.
303
+
304
+
> [!NOTE]
305
+
> `setOutput()` and `streamPreview` render independently. If both are used, static output appears above the stream preview.
306
+
284
307
#### setWarning()
285
308
Call with a string or Error instance to put the task in a warning state.
Type: `{ showTime?: boolean, previewLines?: number }`
315
338
316
339
Optional task options.
317
340
341
+
##### previewLines
342
+
Type: `number`
343
+
344
+
Default: `5`
345
+
346
+
Maximum number of lines to display in the `streamPreview` output (minimum 1). When the stream produces more lines, older lines scroll off and a `(+ N lines)` indicator shows the total.
347
+
318
348
##### showTime
319
349
When `true`, automatically starts the elapsed time counter when the task begins. Equivalent to calling `startTime()` at the start of the task function.
0 commit comments