[READ-ONLY] Mirror of https://github.com/bombshell-dev/docs. bomb.sh/docs
0

Configure Feed

Select the types of activity you want to include in your feed.

docs(@clack/prompts): Add tasks and stream (#10)

authored by

MacFJA and committed by
GitHub
(Apr 16, 2025, 11:24 AM -0600) f07f79af e9c11b1e

+103
+103
src/content/docs/clack/packages/prompts.mdx
··· 232 232 <font color="#06989A">│</font> ▪▪▪▪▪▪▪▪▪▪▪▪<span style="background-color:#FFFFFF"><font color="#FFFFFF">_</font></span> 233 233 <font color="#06989A">└</font></pre> 234 234 235 + ### Tasks 236 + 237 + The `tasks` function provides a convenient API for sequencing several asynchronous actions one after the other. 238 + 239 + ```ts twoslash 240 + import { tasks } from "@clack/prompts"; 241 + 242 + await tasks([ 243 + { 244 + title: 'Downloading package', 245 + task: async () => { 246 + // Do a fetch 247 + return 'Download completed'; 248 + }, 249 + }, 250 + { 251 + title: "Un-archiving", 252 + task: async (message) => { 253 + const parts: Array<string> = [/* ... */]; 254 + for (let index = 0; index < parts.length; index++) { 255 + const type = parts[index]; 256 + // Update the message to indicate what is done 257 + message(`Un-archiving ${type} (${index + 1}/${parts.length})`); 258 + // Do the un-archiving task 259 + } 260 + return 'Un-archiving completed'; 261 + }, 262 + }, 263 + { 264 + title: 'Linking', 265 + task: async () => { 266 + // Do work 267 + return 'Package linked'; 268 + }, 269 + }, 270 + ]); 271 + ``` 272 + 273 + <pre class="cli-preview"><font color="#555753">│</font> 274 + <font color="#4E9A06">◇</font> Download completed 275 + <font color="#555753">│</font> 276 + <font color="#75507B">◐</font> Un-archiving lib (2/3)..</pre> 277 + 235 278 ## Support functions 236 279 237 280 ### Intro ··· 373 416 <font color="#4E9A06">◆</font> Installation complete 374 417 <font color="#555753">│</font> 375 418 <font color="#4E9A06">◇</font> Check files</pre> 419 + 420 + ### Stream 421 + 422 + The `stream` utilities allow you, like the `log` utilities, to add semantic contextual information during an interaction, 423 + expect that the message contains an unknown number of lines. 424 + Each function renders with specific styling to communicate status. 425 + 426 + <Aside type="tip">These utilities are useful to print content of [`node:stream`](https://nodejs.org/api/stream.html), 427 + like [file stream](https://nodejs.org/api/fs.html#fscreatereadstreampath-options)</Aside> 428 + 429 + ```ts twoslash 430 + import { stream } from "@clack/prompts"; 431 + import * as fs from "node:fs"; 432 + 433 + await stream.message(fs.createReadStream('./banner.txt', { encoding: 'utf-8' })); 434 + await stream.info((async function*() { 435 + yield 'Open file...'; 436 + // Open file 437 + yield ' \x1b[32mOK\x1b[39m\n'; 438 + 439 + yield 'Parsing file...'; 440 + // Parse data 441 + yield ' \x1b[32mOK\x1b[39m'; 442 + return; 443 + })()); 444 + await stream.step([ 445 + 'Job1...', 446 + ' \x1b[32mdone\x1b[39m\n', 447 + 'Job2...', 448 + ' \x1b[32mdone\x1b[39m\n', 449 + 'Job3...', 450 + ' \x1b[32mdone\x1b[39m', 451 + ]); 452 + ``` 453 + 454 + <pre class="cli-preview"><font color="#555753">│</font> 455 + <font color="#555753">│</font> 456 + <font color="#555753">│</font> ⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣶⣶⣿⣿⣿⣿⣿⣿⣶⣶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 457 + <font color="#555753">│</font> ⠀⠀⠀⠀⠀⣠⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 458 + <font color="#555753">│</font> ⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 459 + <font color="#555753">│</font> ⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 460 + <font color="#555753">│</font> ⠀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀ 461 + <font color="#555753">│</font> ⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⣀⠀⠀⠀⠀⣿⣿⣿⡿⠀⠀⠀⠀⣀⠀ 462 + <font color="#555753">│</font> ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⢠⣿⣿⣶⣤⣄⣻⣿⣿⣇⣠⣴⣶⣿⣿⡀ 463 + <font color="#555753">│</font> ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⢾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡧ 464 + <font color="#555753">│</font> ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⠀⠀⠀⠀⠀⠀⠉⢉⣿⣿⣿⣿⣿⣯⡉⠉⠀⠀⠀ 465 + <font color="#555753">│</font> ⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⠟⢻⣿⣿⣿⣦⠀⠀⠀ 466 + <font color="#555753">│</font> ⠀⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠀⠀⠀⠀⠐⠿⣿⣿⣿⠏⠀⠀⢻⣿⣿⣿⠷⠀⠀ 467 + <font color="#555753">│</font> ⠀⠀⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠏⠀⠀⠀⠀⠹⠋⠁⠀⠀⠀ 468 + <font color="#555753">│</font> ⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 469 + <font color="#555753">│</font> ⠀⠀⠀⠀⠀⠙⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 470 + <font color="#555753">│</font> ⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠻⠿⢿⣿⣿⣿⣿⡿⠿⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 471 + <font color="#555753">│</font> 472 + <font color="#555753">│</font> 473 + <font color="#3465A4">●</font> Open file{`...`} <font color="#4E9A06">OK</font> 474 + <font color="#555753">│</font> Parsing file{`...`} <font color="#4E9A06">OK</font> 475 + <font color="#555753">│</font> 476 + <font color="#4E9A06">◇</font> Job1{`...`} <font color="#4E9A06">done</font> 477 + <font color="#555753">│</font> Job2{`...`} <font color="#4E9A06">done</font> 478 + <font color="#555753">│</font> Job3{`...`} <font color="#4E9A06">done</font></pre> 376 479 377 480 ## Installation 378 481