Skip to content

Commit bb5ef54

Browse files
authored
fix(prompts): Fix styling of taskLog + fix README (#301)
1 parent 7a08f3d commit bb5ef54

File tree

7 files changed

+373
-342
lines changed

7 files changed

+373
-342
lines changed

examples/basic/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"progress": "jiti ./progress.ts",
1515
"spinner": "jiti ./spinner.ts",
1616
"spinner-ci": "npx cross-env CI=\"true\" jiti ./spinner-ci.ts",
17-
"spinner-timer": "jiti ./spinner-timer.ts"
17+
"spinner-timer": "jiti ./spinner-timer.ts",
18+
"task-log": "jiti ./task-log.ts"
1819
},
1920
"devDependencies": {
2021
"cross-env": "^7.0.3"

examples/basic/task-log.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { setTimeout } from 'node:timers/promises';
2+
import * as p from '@clack/prompts';
3+
4+
async function main() {
5+
p.intro('task log start...');
6+
7+
const log = p.taskLog({
8+
title: 'Running npm install',
9+
limit: 5,
10+
});
11+
12+
for await (const line of fakeCommand()) {
13+
log.message(line);
14+
}
15+
16+
log.success('Done!');
17+
18+
p.outro('task log stop...');
19+
}
20+
21+
async function* fakeCommand() {
22+
for (let i = 0; i < 100; i++) {
23+
yield `line \x1b[32m${i}\x1b[39m...`;
24+
await setTimeout(80);
25+
}
26+
}
27+
28+
main();

packages/prompts/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ When executing a sub-process or a similar sub-task, `taskLog` can be used to ren
253253
import { taskLog } from '@clack/prompts';
254254

255255
const log = taskLog({
256-
message: 'Running npm install'
256+
title: 'Running npm install'
257257
});
258258

259259
for await (const line of npmInstall()) {

packages/prompts/src/common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import isUnicodeSupported from 'is-unicode-supported';
44
import color from 'picocolors';
55

66
export const unicode = isUnicodeSupported();
7+
export const isCI = (): boolean => process.env.CI === 'true';
78
export const unicodeOr = (c: string, fallback: string) => (unicode ? c : fallback);
89
export const S_STEP_ACTIVE = unicodeOr('◆', '*');
910
export const S_STEP_CANCEL = unicodeOr('■', 'x');

packages/prompts/src/spinner.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
S_STEP_CANCEL,
88
S_STEP_ERROR,
99
S_STEP_SUBMIT,
10+
isCI as isCIFn,
1011
unicode,
1112
} from './common.js';
1213

@@ -33,7 +34,7 @@ export const spinner = ({
3334
}: SpinnerOptions = {}): SpinnerResult => {
3435
const frames = unicode ? ['◒', '◐', '◓', '◑'] : ['•', 'o', 'O', '0'];
3536
const delay = unicode ? 80 : 120;
36-
const isCI = process.env.CI === 'true';
37+
const isCI = isCIFn();
3738

3839
let unblock: () => void;
3940
let loop: NodeJS.Timeout;

packages/prompts/src/task-log.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Writable } from 'node:stream';
22
import { getColumns } from '@clack/core';
33
import * as color from 'picocolors';
44
import { erase } from 'sisteransi';
5-
import { type CommonOptions, S_BAR, S_STEP_SUBMIT } from './common.js';
5+
import { type CommonOptions, S_BAR, S_STEP_SUBMIT, isCI as isCIFn } from './common.js';
66
import { log } from './log.js';
77

88
export interface TaskLogOptions extends CommonOptions {
@@ -26,11 +26,11 @@ export interface TaskLogCompletionOptions {
2626
export const taskLog = (opts: TaskLogOptions) => {
2727
const output: Writable = opts.output ?? process.stdout;
2828
const columns = getColumns(output);
29-
const secondarySymbol = color.dim(S_BAR);
29+
const secondarySymbol = color.gray(S_BAR);
3030
const spacing = opts.spacing ?? 1;
3131
const barSize = 3;
3232
const retainLog = opts.retainLog === true;
33-
const isCI = process.env.CI === 'true';
33+
const isCI = isCIFn();
3434

3535
output.write(`${secondarySymbol}\n`);
3636
output.write(`${color.green(S_STEP_SUBMIT)} ${opts.title}\n`);

0 commit comments

Comments
 (0)