Skip to content

feat: add taskLog prompt #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 15, 2025
5 changes: 5 additions & 0 deletions .changeset/famous-turkeys-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clack/prompts": minor
---

Added new `taskLog` prompt for log output which is cleared on success
22 changes: 22 additions & 0 deletions packages/prompts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,26 @@ stream.error((function *() { yield 'Error!'; })());
stream.message((function *() { yield 'Hello'; yield ", World" })(), { symbol: color.cyan('~') });
```

### Task Log

When executing a sub-process or a similar sub-task, `taskLog` can be used to render the output continuously and clear it at the end if it was successful.

```js
import { taskLog } from '@clack/prompts';

const log = taskLog({
message: 'Running npm install'
});

for await (const line of npmInstall()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for await (const line of npmInstall()) {
for await (const line of npmInstall()) {

Not sure if the npmInstall makes it clear enough for the people, but I don't have any better idea

log.message(line);
}

if (success) {
log.success('Done!');
} else {
log.error('Failed!');
}
```

![clack-log-prompts](https://github.com/bombshell-dev/clack/blob/main/.github/assets/clack-logs.png)
Loading