feat(terminal): add optional live timers and spinners to terminal tasks
This commit is contained in:
@@ -75,7 +75,7 @@ demo help
|
||||
|
||||
## Terminal Task Rendering
|
||||
|
||||
Use `SmartcliTerminal` for long-running jobs that should render cleanly in both interactive and non-interactive environments. In a TTY, active tasks render below each other with a fixed row count, colored status symbols, and elapsed time. In CI, pipes, Docker logs, or `TERM=dumb`, the same calls become throttled append-only lifecycle logs.
|
||||
Use `SmartcliTerminal` for long-running jobs that should render cleanly in both interactive and non-interactive environments. In a TTY, active tasks render below each other with a fixed row count, colored status symbols, and optional live timers/spinners. In CI, pipes, Docker logs, or `TERM=dumb`, the same calls become throttled append-only lifecycle logs where every message line is prefixed with its task name.
|
||||
|
||||
```ts
|
||||
import { SmartcliTerminal } from '@push.rocks/smartcli';
|
||||
@@ -84,6 +84,8 @@ const terminal = new SmartcliTerminal();
|
||||
|
||||
const buildTask = terminal.task('Build package', {
|
||||
rows: 3,
|
||||
showTimer: true,
|
||||
showSpinner: true,
|
||||
});
|
||||
|
||||
buildTask.update('Installing dependencies');
|
||||
@@ -105,6 +107,8 @@ try {
|
||||
|
||||
Completed tasks collapse into one permanent success line. Failed tasks collapse into one permanent failure line with error details. If an error should remain visible inside the live task area, use `attachError(error, { keepOpen: true })`.
|
||||
|
||||
`showTimer` renders a second-precision live counter using `@push.rocks/smarttime`, for example `4s` or `1m 30s`. `showSpinner` animates the running indicator in interactive terminals and is ignored for append-only output. The shorter aliases `timer` and `spinner` are also accepted.
|
||||
|
||||
For scoped work, `task.run()` completes or fails automatically:
|
||||
|
||||
```ts
|
||||
|
||||
Reference in New Issue
Block a user