Skip to content

Commit 64d4c58

Browse files
committed
Force color when generating example for progress bar
1 parent 4812a4e commit 64d4c58

File tree

2 files changed

+53
-32
lines changed

2 files changed

+53
-32
lines changed

packages/cli-kit/bin/documentation/examples.ts

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -565,43 +565,64 @@ export const examples: {[key in string]: Example} = {
565565
renderTasks: {
566566
type: 'async',
567567
basic: async () => {
568-
const stdout = new Stdout({columns: TERMINAL_WIDTH})
568+
// Force colors for deterministic output (solid blocks vs animated wave)
569+
const originalForceColor = process.env.FORCE_COLOR
570+
process.env.FORCE_COLOR = '1'
571+
try {
572+
const stdout = new Stdout({columns: TERMINAL_WIDTH})
569573

570-
const tasks = [
571-
{
572-
title: 'Installing dependencies',
573-
task: async () => {
574-
await new Promise((resolve) => setTimeout(resolve, 2000))
574+
const tasks = [
575+
{
576+
title: 'Installing dependencies',
577+
task: async () => {
578+
await new Promise((resolve) => setTimeout(resolve, 2000))
579+
},
575580
},
576-
},
577-
]
578-
579-
renderTasks(tasks, {renderOptions: {stdout: stdout as any, debug: true}})
580-
581-
await waitFor(
582-
() => {},
583-
() => Boolean(stdout.lastFrame()?.includes('Installing dependencies')),
584-
)
585-
586-
// Return first frame with the title for deterministic output
587-
return stdout.frames.find((frame) => frame.includes('Installing dependencies'))!
581+
]
582+
583+
renderTasks(tasks, {renderOptions: {stdout: stdout as any, debug: true}})
584+
585+
await waitFor(
586+
() => {},
587+
() => Boolean(stdout.lastFrame()?.includes('Installing dependencies')),
588+
)
589+
590+
return stdout.lastFrame()!
591+
} finally {
592+
if (originalForceColor === undefined) {
593+
delete process.env.FORCE_COLOR
594+
} else {
595+
process.env.FORCE_COLOR = originalForceColor
596+
}
597+
}
588598
},
589599
},
590600
renderSingleTask: {
591601
type: 'async',
592602
basic: async () => {
593-
const stdout = new Stdout({columns: TERMINAL_WIDTH})
594-
595-
await renderSingleTask({
596-
title: outputContent`Loading app`,
597-
task: async () => {
598-
await sleep(1)
599-
},
600-
renderOptions: {stdout: stdout as any, debug: true},
601-
})
602-
603-
// Return first frame with the title for deterministic output
604-
return stdout.frames.find((frame) => frame.includes('Loading'))!
603+
// Force colors for deterministic output (solid blocks vs animated wave)
604+
const originalForceColor = process.env.FORCE_COLOR
605+
process.env.FORCE_COLOR = '1'
606+
try {
607+
const stdout = new Stdout({columns: TERMINAL_WIDTH})
608+
609+
await renderSingleTask({
610+
title: outputContent`Loading app`,
611+
task: async () => {
612+
await sleep(1)
613+
},
614+
renderOptions: {stdout: stdout as any, debug: true},
615+
})
616+
617+
// Return first frame with the title for deterministic output
618+
return stdout.frames.find((frame) => frame.includes('Loading'))!
619+
} finally {
620+
if (originalForceColor === undefined) {
621+
delete process.env.FORCE_COLOR
622+
} else {
623+
process.env.FORCE_COLOR = originalForceColor
624+
}
625+
}
605626
},
606627
},
607628
renderTextPrompt: {

packages/cli-kit/src/public/node/ui.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ interface RenderTasksOptions {
468468
/**
469469
* Runs async tasks and displays their progress to the console.
470470
* @example
471-
* ▁▁▂▂▃▃▄▄▅▅▆▆▇▇██▇▇▆▆▅▅▄▄▃▃▂▂▁▁▁▁▂▂▃▃▄▄▅▅▆▆▇▇██▇▇▆▆▅▅▄▄▃▃▂▂▁▁
471+
* ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
472472
* Installing dependencies ...
473473
*/
474474
// eslint-disable-next-line max-params
@@ -502,7 +502,7 @@ export interface RenderSingleTaskOptions<T> {
502502
* @param options.renderOptions - Optional render configuration
503503
* @returns The result of the task
504504
* @example
505-
* ▁▁▂▂▃▃▄▄▅▅▆▆▇▇██▇▇▆▆▅▅▄▄▃▃▂▂▁▁▁▁▂▂▃▃▄▄▅▅▆▆▇▇██▇▇▆▆▅▅▄▄▃▃▂▂▁▁
505+
* ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
506506
* Loading app ...
507507
*/
508508
export async function renderSingleTask<T>({

0 commit comments

Comments
 (0)