Skip to content

Commit ba7defb

Browse files
authored
adopt picocolors (#1769)
1 parent 031ac6d commit ba7defb

File tree

4 files changed

+24
-31
lines changed

4 files changed

+24
-31
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"mime": "^4.0.0",
8484
"minisearch": "^6.3.0",
8585
"open": "^10.1.0",
86+
"picocolors": "^1.1.1",
8687
"pkg-dir": "^8.0.0",
8788
"resolve.exports": "^2.0.2",
8889
"rollup": "^4.6.0",

src/commandInstruction.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import {getObservableUiOrigin} from "./observableApiClient.js";
2-
import type {TtyColor} from "./tty.js";
32
import {bold, magenta} from "./tty.js";
43

54
export function commandInstruction(
65
command: string,
76
{
87
color = (s) => magenta(bold(s)),
98
env = process.env
10-
}: {color?: TtyColor | null; env?: Record<string, string | undefined>} = {}
9+
}: {
10+
color?: ((s: string) => string) | null;
11+
env?: Record<string, string | undefined>;
12+
} = {}
1113
): string {
12-
if (!color) color = (s) => s;
14+
color ??= (s) => s;
1315

1416
const prefix = env["npm_config_user_agent"]?.includes("yarn/")
1517
? "yarn observable"

src/tty.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
import {isatty} from "node:tty";
22
import * as clack from "@clack/prompts";
3+
import pc from "picocolors";
34
import type {ClackEffects} from "./clack.js";
45
import type {Logger} from "./logger.js";
56

6-
export const reset = color(0, 0);
7-
export const bold = color(1, 22);
8-
export const faint = color(2, 22);
9-
export const italic = color(3, 23);
10-
export const underline = color(4, 24);
11-
export const inverse = color(7, 27);
12-
export const strikethrough = color(9, 29);
13-
export const red = color(31, 39);
14-
export const green = color(32, 39);
15-
export const yellow = color(33, 39);
16-
export const blue = color(34, 39);
17-
export const magenta = color(35, 39);
18-
export const cyan = color(36, 39);
19-
20-
export type TtyColor = (text: string) => string;
21-
22-
function color(code: number, reset: number): TtyColor {
23-
return process.stdout.isTTY ? (text: string) => `\x1b[${code}m${text}\x1b[${reset}m` : String;
24-
}
7+
export const reset = pc.reset;
8+
export const bold = pc.bold;
9+
export const faint = pc.gray;
10+
export const italic = pc.italic;
11+
export const underline = pc.underline;
12+
export const inverse = pc.inverse;
13+
export const strikethrough = pc.strikethrough;
14+
export const red = pc.red;
15+
export const green = pc.green;
16+
export const yellow = pc.yellow;
17+
export const blue = pc.blue;
18+
export const magenta = pc.magenta;
19+
export const cyan = pc.cyan;
2520

2621
export interface TtyEffects {
2722
clack: ClackEffects;

yarn.lock

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,11 +2548,6 @@ is-unicode-supported@^0.1.0:
25482548
resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7"
25492549
integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==
25502550

2551-
is-unicode-supported@^1.3.0:
2552-
version "1.3.0"
2553-
resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz#d824984b616c292a2e198207d4a609983842f714"
2554-
integrity sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==
2555-
25562551
is-weakref@^1.0.2:
25572552
version "1.0.2"
25582553
resolved "https://registry.yarnpkg.com/is-weakref/-/is-weakref-1.0.2.tgz#9529f383a9338205e89765e0392efc2f100f06f2"
@@ -3133,10 +3128,10 @@ pathval@^1.1.1:
31333128
resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.1.tgz#8534e77a77ce7ac5a2512ea21e0fdb8fcf6c3d8d"
31343129
integrity sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==
31353130

3136-
picocolors@^1.0.0:
3137-
version "1.1.0"
3138-
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.0.tgz#5358b76a78cde483ba5cef6a9dc9671440b27d59"
3139-
integrity sha512-TQ92mBOW0l3LeMeyLV6mzy/kWr8lkd/hp3mTg7wYK7zJhuBStmGMBG0BdeDZS/dZx1IukaX6Bk11zcln25o1Aw==
3131+
picocolors@^1.0.0, picocolors@^1.1.1:
3132+
version "1.1.1"
3133+
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.1.tgz#3d321af3eab939b083c8f929a1d12cda81c26b6b"
3134+
integrity sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==
31403135

31413136
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1:
31423137
version "2.3.1"

0 commit comments

Comments
 (0)