|
| 1 | +import * as clack from "@clack/prompts"; |
| 2 | +import pc from "picocolors"; |
| 3 | + |
| 4 | +export async function execute(args) { |
| 5 | + clack.intro("picocolors"); |
| 6 | + clack.note( |
| 7 | + "This is a simple flow for testing output with colorized and formatted output" |
| 8 | + ); |
| 9 | + |
| 10 | + const name = await clack.text({ |
| 11 | + message: "What is your name?", |
| 12 | + placeholder: "Enter your name", |
| 13 | + }); |
| 14 | + |
| 15 | + if (clack.isCancel(name)) { |
| 16 | + clack.cancel("Goodbye"); |
| 17 | + } |
| 18 | + |
| 19 | + // clack prints some extra characters, let's just make sure these don't mess up output expectations |
| 20 | + clack.log.success(`Hello ${pc.green(name)} (clack.log.success)`); |
| 21 | + clack.log.info(`Hello ${pc.blue(name)} (clack.log.info)`); |
| 22 | + clack.log.error(`Hello ${pc.red(name)} (clack.log.error)`); |
| 23 | + clack.log.warn(`Hello ${pc.yellow(name)} (clack.log.warn)`); |
| 24 | + clack.log.step(`Hello ${pc.cyan(name)} (clack.log.step)`); |
| 25 | + |
| 26 | + console.log(pc.red(`\nHello ${name} (red)`)); |
| 27 | + console.log( |
| 28 | + pc.green(`Hello ${pc.underline(name)} ${pc.dim(pc.bgRed("(red + bg)"))}`) |
| 29 | + ); |
| 30 | + |
| 31 | + console.log( |
| 32 | + pc.italic(pc.bgWhite(`Hello ${pc.cyanBright(name)} (italic + bg)`)) |
| 33 | + ); |
| 34 | + |
| 35 | + const spinner = clack.spinner({ indicator: "timer" }); |
| 36 | + |
| 37 | + spinner.start(`greeting ${pc.cyanBright(name)} in progress`); |
| 38 | + |
| 39 | + await new Promise((resolve) => setTimeout(resolve, 1000)); |
| 40 | + |
| 41 | + spinner.message(`greeting ${pc.cyanBright(name)} in progress 50%`); |
| 42 | + |
| 43 | + await new Promise((resolve) => setTimeout(resolve, 1000)); |
| 44 | + |
| 45 | + spinner.stop(`Greeted ${pc.cyanBright(name)}`); |
| 46 | + |
| 47 | + clack.outro("Goodbye"); |
| 48 | +} |
0 commit comments