|
| 1 | +import chalk from 'chalk'; |
| 2 | +import ora from './index.js'; |
| 3 | + |
| 4 | +console.log(chalk.bold('\n🦄 Unicorn Console Integration Demo\n')); |
| 5 | +console.log(chalk.dim('This example shows how ora seamlessly handles console.error/warn')); |
| 6 | +console.log(chalk.dim('while the spinner is running. These write to stderr where ora hooks!\n')); |
| 7 | + |
| 8 | +// Simulate collecting unicorns with status updates |
| 9 | +const collectUnicorns = ora({ |
| 10 | + text: 'Searching for unicorns in the enchanted forest...', |
| 11 | + color: 'magenta', |
| 12 | +}).start(); |
| 13 | + |
| 14 | +setTimeout(() => { |
| 15 | + console.error(chalk.cyan('✨ Found a baby unicorn near the crystal stream!')); |
| 16 | +}, 500); |
| 17 | + |
| 18 | +setTimeout(() => { |
| 19 | + console.error(chalk.yellow('✨ Spotted a golden unicorn on the rainbow bridge!')); |
| 20 | +}, 1000); |
| 21 | + |
| 22 | +setTimeout(() => { |
| 23 | + console.warn(chalk.hex('#FFA500')('⚠️ A wild unicorn is shy and hiding behind clouds')); |
| 24 | +}, 1500); |
| 25 | + |
| 26 | +setTimeout(() => { |
| 27 | + console.error(chalk.magenta('✨ Discovered a unicorn herd in the meadow!')); |
| 28 | +}, 2000); |
| 29 | + |
| 30 | +setTimeout(() => { |
| 31 | + console.error(chalk.red('❌ Dark forest area is too dangerous to explore')); |
| 32 | +}, 2500); |
| 33 | + |
| 34 | +setTimeout(() => { |
| 35 | + collectUnicorns.succeed(chalk.green('Collected 3 magical unicorns! 🦄🦄🦄')); |
| 36 | + |
| 37 | + // Start processing unicorn magic |
| 38 | + const processSpinner = ora({ |
| 39 | + text: 'Processing unicorn magic...', |
| 40 | + color: 'cyan', |
| 41 | + }).start(); |
| 42 | + |
| 43 | + setTimeout(() => { |
| 44 | + console.error(chalk.blue('🌟 Converting stardust to rainbow essence')); |
| 45 | + }, 500); |
| 46 | + |
| 47 | + setTimeout(() => { |
| 48 | + console.error(chalk.magenta('🌈 Brewing magical unicorn potion')); |
| 49 | + }, 1000); |
| 50 | + |
| 51 | + setTimeout(() => { |
| 52 | + console.error(chalk.yellow('✨ Enchanting unicorn horn fragments')); |
| 53 | + }, 1500); |
| 54 | + |
| 55 | + setTimeout(() => { |
| 56 | + processSpinner.succeed(chalk.green('Unicorn magic processed successfully!')); |
| 57 | + |
| 58 | + // Deploy unicorn powers |
| 59 | + const deploySpinner = ora({ |
| 60 | + text: 'Deploying unicorn powers to the world...', |
| 61 | + color: 'magenta', |
| 62 | + spinner: 'dots12', |
| 63 | + }).start(); |
| 64 | + |
| 65 | + setTimeout(() => { |
| 66 | + console.error(chalk.hex('#FF1493')('💫 Spreading joy and sparkles')); |
| 67 | + }, 400); |
| 68 | + |
| 69 | + setTimeout(() => { |
| 70 | + console.error(chalk.hex('#9370DB')('🎨 Painting rainbows across the sky')); |
| 71 | + }, 800); |
| 72 | + |
| 73 | + setTimeout(() => { |
| 74 | + console.error(chalk.hex('#FFD700')('⭐ Granting wishes to believers')); |
| 75 | + }, 1200); |
| 76 | + |
| 77 | + setTimeout(() => { |
| 78 | + deploySpinner.succeed(chalk.bold.green('🦄 Unicorn powers deployed! The world is more magical now! ✨')); |
| 79 | + |
| 80 | + // Summary (using console.log is fine here since spinner is stopped) |
| 81 | + console.log(chalk.dim('\n' + '─'.repeat(60))); |
| 82 | + console.log(chalk.bold.cyan('\n📊 Mission Summary:')); |
| 83 | + console.log(chalk.white(' • Unicorns collected: ') + chalk.bold('3')); |
| 84 | + console.log(chalk.white(' • Magic spells cast: ') + chalk.bold('6')); |
| 85 | + console.log(chalk.white(' • Rainbows created: ') + chalk.bold('∞')); |
| 86 | + console.log(chalk.white(' • World happiness: ') + chalk.bold.green('+1000%')); |
| 87 | + console.log(chalk.dim('\n' + '─'.repeat(60))); |
| 88 | + |
| 89 | + console.log(chalk.bold.magenta('\n✨ Notice how all console.error/warn appeared cleanly above the spinner!')); |
| 90 | + console.log(chalk.dim('The spinner automatically clears, shows your message, then re-renders below.')); |
| 91 | + console.log(chalk.dim('Both console.log() and console.error/warn() work seamlessly while spinning! 🎉\n')); |
| 92 | + }, 1600); |
| 93 | + }, 2000); |
| 94 | +}, 3000); |
0 commit comments