Repository navigation
Expand file tree
/
Copy pathexample-persist-output.js
More file actions
executable file
·70 lines (51 loc) · 2.29 KB
/
Copy pathexample-persist-output.js
File metadata and controls
executable file
·70 lines (51 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
import {setTimeout as delay} from 'node:timers/promises';
import chalk from 'chalk';
import logUpdate from './index.js';
console.log(chalk.magenta('\n✨ Welcome to the magical log-update demo! ✨\n'));
const rainbowColors = ['red', 'yellow', 'green', 'cyan', 'blue', 'magenta'];
const sparkles = ['✨', '💫', '⭐', '🌟', '✨', '💖'];
const unicorns = ['🦄', '🦄', '🦄'];
console.log(chalk.cyan('🌈 Phase 1: Rainbow spinner that updates in place!\n'));
let frame = 0;
for (const step of Array.from({length: 20}).keys()) {
const color = rainbowColors[frame % rainbowColors.length];
const sparkle = sparkles[frame % sparkles.length];
logUpdate(chalk[color](` ${sparkle} Making rainbow magic ${'.'.repeat((frame % 3) + 1)}\n`)
+ chalk.gray(` ${'█'.repeat(step + 1)}${'░'.repeat(20 - step)}\n`)
+ chalk.yellow(` ${unicorns[frame % 3]} Unicorn power: ${((step + 1) * 5)}%`));
frame++;
// eslint-disable-next-line no-await-in-loop
await delay(150);
}
logUpdate.persist(chalk.green('\n 🎉 Rainbow magic complete!\n'));
console.log(chalk.cyan('🦄 Phase 2: Collecting unicorns!\n'));
const unicornNames = ['Sparkle', 'Rainbow', 'Stardust', 'Moonbeam', 'Glitter'];
for (const [index, name] of unicornNames.entries()) {
// Update the search animation
for (const animationFrame of Array.from({length: 8}).keys()) {
const dots = '.'.repeat((animationFrame % 4));
const spaces = ' '.repeat(3 - (animationFrame % 4));
logUpdate(chalk.magenta(` 🔮 Searching for ${name}${dots}${spaces}`));
// eslint-disable-next-line no-await-in-loop
await delay(100);
}
const color = rainbowColors[index % rainbowColors.length];
logUpdate.persist(chalk[color](` 🦄 Found ${name}!`)
+ ' '
+ chalk.dim('✨'.repeat(3)));
// eslint-disable-next-line no-await-in-loop
await delay(200);
}
logUpdate.clear();
const finalMessage = `
${chalk.magenta(' 🌈✨🦄✨🌈')}
${chalk.cyan(' All unicorns found!')}
${chalk.yellow(' Your rainbow is complete!')}
${chalk.gray(' The magic of log.persist():')}
${chalk.gray(' • Regular log() updates in place')}
${chalk.gray(' • log.persist() keeps messages in scrollback')}
${chalk.gray(' • Perfect for progress + permanent logs!')}
${chalk.magenta(' ✨ Thanks for watching! ✨')}
`;
logUpdate.persist(finalMessage);