@alchemy.run/sigil 0.0.0-alpha.3 → 0.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -13
- package/THIRD_PARTY_NOTICES.md +70 -23
- package/dist/Text-D5HUf3Fj.d.ts +452 -0
- package/dist/ansi.d.ts +137 -143
- package/dist/ansi.js +87 -2
- package/dist/capabilities.d.ts +5 -0
- package/dist/capabilities.js +3 -0
- package/dist/cell-_ZVhbfl0.js +44 -0
- package/dist/color-CkbalRqK.js +2 -0
- package/dist/color-policy-BMzMwV7Q.d.ts +22 -0
- package/dist/color-policy-SVj1pYTA.js +560 -0
- package/dist/color-profile-DHhQHY55.js +36 -0
- package/dist/color-profile-u0Nhe9Nv.d.ts +97 -0
- package/dist/color.d.ts +21 -0
- package/dist/color.js +3 -0
- package/dist/cursor-position-D2LAkRG0.d.ts +7 -0
- package/dist/detect-Bh4yGP6w.d.ts +186 -0
- package/dist/detect-BuTXtY6e.js +373 -0
- package/dist/{devtools-BhYGjb7h.js → devtools-DbthxoD1.js} +22 -23
- package/dist/env-YVw64yZS.js +9 -0
- package/dist/escapes-CB_6CWOE.d.ts +72 -0
- package/dist/geometry-BxXOzJgo.d.ts +11 -0
- package/dist/index-Bmc2tRPk.d.ts +21 -0
- package/dist/index.d.ts +235 -754
- package/dist/index.js +1362 -3001
- package/dist/osc-CCH7xDoS.js +71 -0
- package/dist/osc-Cn0fw77g.d.ts +23 -0
- package/dist/paint-C19minOS.d.ts +81 -0
- package/dist/query-vaIeGOkH.d.ts +152 -0
- package/dist/router.d.ts +392 -0
- package/dist/router.js +709 -0
- package/dist/sample-Cqw1bjUL.js +445 -0
- package/dist/screen-BOh__-65.js +324 -0
- package/dist/screen-BReKIheE.d.ts +40 -0
- package/dist/screen.d.ts +5 -0
- package/dist/screen.js +5 -0
- package/dist/semantic-text-style-DIMzC7xt.js +91 -0
- package/dist/serialize-BTkAZgw1.js +79 -0
- package/dist/session-BJmzX2NJ.js +664 -0
- package/dist/sgr-BhwaWAJB.js +246 -0
- package/dist/store-CgrG9K4y.d.ts +72 -0
- package/dist/string-width-CijQwpIk.js +69 -0
- package/dist/strip-BvU4toXG.js +6 -0
- package/dist/terminal.d.ts +118 -0
- package/dist/terminal.js +2 -0
- package/dist/tokenize-AjqbvtiT.js +1242 -0
- package/dist/tokenize-Dx1y_l5H.d.ts +57 -0
- package/dist/truncate-D31fhU6i.js +562 -0
- package/dist/use-focus-C2sciZOo.js +1335 -0
- package/package.json +43 -17
- package/src/ansi/chalk.ts +12 -53
- package/src/ansi/cursor.ts +2 -4
- package/src/ansi/east-asian-width.ts +44 -0
- package/src/ansi/escapes.ts +18 -26
- package/src/ansi/graphemes.ts +8 -0
- package/src/ansi/hyperlink.ts +44 -0
- package/src/ansi/index.ts +14 -14
- package/src/ansi/osc.ts +77 -0
- package/src/ansi/sgr.ts +2 -5
- package/src/ansi/slice.ts +1 -1
- package/src/ansi/string-width.ts +91 -206
- package/src/ansi/strip.ts +13 -33
- package/src/ansi/tokenize.ts +96 -169
- package/src/ansi/truncate.ts +5 -3
- package/src/ansi/wrap.ts +13 -14
- package/src/ansi-tokenizer.ts +1 -1
- package/src/capabilities/color-policy.ts +34 -0
- package/src/capabilities/detect.ts +594 -0
- package/src/capabilities/index.ts +37 -0
- package/src/capabilities/query.ts +657 -0
- package/src/capabilities/store.ts +379 -0
- package/src/color/index.ts +3 -0
- package/src/color/paint.ts +169 -0
- package/src/color/palette.ts +48 -0
- package/src/color/sample.ts +323 -0
- package/src/color.ts +1 -0
- package/src/components/AnsiText.tsx +42 -0
- package/src/components/App.tsx +109 -22
- package/src/components/BackgroundContext.ts +2 -3
- package/src/components/Box.tsx +43 -60
- package/src/components/CursorContext.ts +1 -1
- package/src/components/ErrorBoundary.tsx +1 -1
- package/src/components/ErrorOverview.tsx +8 -7
- package/src/components/Hyperlink.tsx +56 -0
- package/src/components/Spacer.tsx +1 -1
- package/src/components/Static.tsx +1 -1
- package/src/components/StderrContext.ts +0 -2
- package/src/components/StdinContext.ts +0 -1
- package/src/components/StdoutContext.ts +1 -3
- package/src/components/TerminalOscContext.ts +25 -0
- package/src/components/Text.tsx +23 -46
- package/src/components/Transform.tsx +2 -2
- package/src/cursor-position.ts +1 -1
- package/src/devtools.ts +84 -24
- package/src/dom.ts +11 -8
- package/src/env.ts +12 -0
- package/src/get-max-width.ts +1 -1
- package/src/global.d.ts +6 -4
- package/src/{boxes.ts → glyphs.ts} +17 -18
- package/src/hooks/use-animation.ts +1 -1
- package/src/hooks/use-app.ts +1 -1
- package/src/hooks/use-box-metrics.ts +1 -1
- package/src/hooks/use-capabilities.ts +73 -0
- package/src/hooks/use-cursor.ts +3 -3
- package/src/hooks/use-focus-manager.ts +1 -1
- package/src/hooks/use-focus.ts +5 -6
- package/src/hooks/use-input.ts +4 -4
- package/src/hooks/use-is-screen-reader-enabled.ts +1 -1
- package/src/hooks/use-paste.ts +2 -2
- package/src/hooks/use-stderr.ts +1 -1
- package/src/hooks/use-stdin.ts +1 -1
- package/src/hooks/use-stdout.ts +1 -1
- package/src/hooks/use-terminal-osc.ts +59 -0
- package/src/hooks/use-window-size.ts +2 -2
- package/src/index.ts +88 -44
- package/src/ink.tsx +620 -745
- package/src/input-parser.ts +1 -1
- package/src/instances.ts +1 -1
- package/src/kitty-keyboard.ts +128 -0
- package/src/measure-element.ts +1 -1
- package/src/measure-text.ts +2 -2
- package/src/{render-node-to-output.ts → paint-tree.ts} +78 -53
- package/src/parse-keypress.ts +4 -5
- package/src/parse-stack-line.ts +0 -1
- package/src/patch-console.ts +44 -0
- package/src/reconciler.ts +36 -62
- package/src/render-background.ts +37 -16
- package/src/render-border.ts +97 -64
- package/src/render-frame.ts +83 -0
- package/src/render-to-string.ts +24 -9
- package/src/render.ts +24 -16
- package/src/router/components.tsx +343 -0
- package/src/router/context.ts +41 -0
- package/src/router/history.ts +194 -0
- package/src/router/hooks.tsx +391 -0
- package/src/router/index.ts +34 -0
- package/src/router/matcher.ts +571 -0
- package/src/sanitize-ansi.ts +1 -1
- package/src/screen/ansi.ts +184 -0
- package/src/screen/canvas.ts +137 -0
- package/src/screen/cell.ts +138 -0
- package/src/screen/color-profile.ts +47 -0
- package/src/screen/geometry.ts +9 -0
- package/src/screen/index.ts +6 -0
- package/src/screen/screen.ts +272 -0
- package/src/screen/serialize.ts +129 -0
- package/src/screen.ts +1 -0
- package/src/semantic-text-style.ts +118 -0
- package/src/signal-exit.ts +4 -5
- package/src/squash-text-nodes.ts +4 -7
- package/src/stream.ts +2 -4
- package/src/structured-text.ts +321 -0
- package/src/styles.ts +16 -17
- package/src/terminal/index.ts +2 -0
- package/src/terminal/inline-presenter.ts +120 -0
- package/src/terminal/input.ts +86 -0
- package/src/terminal/render-scheduler.ts +37 -0
- package/src/terminal/screen-presenter.ts +188 -0
- package/src/terminal/session.ts +407 -0
- package/src/terminal-size.ts +9 -8
- package/src/terminal.ts +1 -0
- package/src/testing/browser.ts +588 -0
- package/src/testing/emulators.ts +205 -0
- package/src/testing/explorer-app/index.html +12 -0
- package/src/testing/explorer-app/main.ts +381 -0
- package/src/testing/explorer-app/style.css +194 -0
- package/src/testing/explorer-app/tsconfig.json +15 -0
- package/src/testing/explorer-app/vite-env.d.ts +1 -0
- package/src/testing/index.ts +26 -0
- package/src/testing/keys.ts +56 -0
- package/src/testing/live.ts +85 -0
- package/src/testing/matchers.ts +70 -0
- package/src/testing/public.ts +94 -0
- package/src/testing/terminal.ts +349 -0
- package/src/testing/vitest.ts +157 -0
- package/src/transform-adapter.ts +14 -0
- package/src/types.ts +1 -6
- package/src/utils.ts +2 -2
- package/src/wrap-text.ts +4 -4
- package/src/yoga/config.ts +2 -2
- package/src/yoga/core/absoluteLayout.ts +15 -15
- package/src/yoga/core/baseline.ts +3 -3
- package/src/yoga/core/cache.ts +4 -4
- package/src/yoga/core/calculateLayout.ts +33 -27
- package/src/yoga/core/config.ts +1 -1
- package/src/yoga/core/flexLine.ts +3 -3
- package/src/yoga/core/helpers.ts +3 -3
- package/src/yoga/core/layoutResults.ts +4 -4
- package/src/yoga/core/node.ts +16 -16
- package/src/yoga/core/pixelGrid.ts +4 -4
- package/src/yoga/core/style.ts +11 -11
- package/src/yoga/core/types.ts +2 -2
- package/src/yoga/index.ts +6 -6
- package/src/yoga/node.ts +8 -8
- package/dist/sgr-CMfEpjSk.d.ts +0 -91
- package/dist/truncate-CBiyyZzw.js +0 -2156
- package/src/ansi/supports-color.ts +0 -213
- package/src/ansi/widest-line.ts +0 -12
- package/src/auto-bind.ts +0 -41
- package/src/colorize.ts +0 -60
- package/src/devtools-window-polyfill.ts +0 -73
- package/src/indent-string.ts +0 -16
- package/src/is-in-ci.ts +0 -7
- package/src/log-update.ts +0 -370
- package/src/output.ts +0 -308
- package/src/renderer.ts +0 -73
- package/src/write-synchronized.ts +0 -9
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
// Terminal color support detection.
|
|
2
|
-
// Ported from `supports-color` (MIT, Sindre Sorhus & Josh Junon).
|
|
3
|
-
import os from "node:os";
|
|
4
|
-
import process from "node:process";
|
|
5
|
-
import tty from "node:tty";
|
|
6
|
-
|
|
7
|
-
export type ColorSupportLevel = 0 | 1 | 2 | 3;
|
|
8
|
-
|
|
9
|
-
export type ColorSupport = {
|
|
10
|
-
readonly level: ColorSupportLevel;
|
|
11
|
-
readonly hasBasic: boolean;
|
|
12
|
-
readonly has256: boolean;
|
|
13
|
-
readonly has16m: boolean;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type ColorInfo = ColorSupport | false;
|
|
17
|
-
|
|
18
|
-
function hasFlag(flag: string, argv: readonly string[] = process.argv): boolean {
|
|
19
|
-
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
20
|
-
const position = argv.indexOf(prefix + flag);
|
|
21
|
-
const terminatorPosition = argv.indexOf("--");
|
|
22
|
-
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const { env } = process;
|
|
26
|
-
|
|
27
|
-
let flagForceColor: number | undefined;
|
|
28
|
-
if (
|
|
29
|
-
hasFlag("no-color") ||
|
|
30
|
-
hasFlag("no-colors") ||
|
|
31
|
-
hasFlag("color=false") ||
|
|
32
|
-
hasFlag("color=never")
|
|
33
|
-
) {
|
|
34
|
-
flagForceColor = 0;
|
|
35
|
-
} else if (
|
|
36
|
-
hasFlag("color") ||
|
|
37
|
-
hasFlag("colors") ||
|
|
38
|
-
hasFlag("color=true") ||
|
|
39
|
-
hasFlag("color=always")
|
|
40
|
-
) {
|
|
41
|
-
flagForceColor = 1;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function envForceColor(): number | undefined {
|
|
45
|
-
if (!("FORCE_COLOR" in env)) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (env["FORCE_COLOR"] === "true") {
|
|
50
|
-
return 1;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (env["FORCE_COLOR"] === "false") {
|
|
54
|
-
return 0;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return env["FORCE_COLOR"]!.length === 0
|
|
58
|
-
? 1
|
|
59
|
-
: Math.min(Number.parseInt(env["FORCE_COLOR"]!, 10), 3);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function translateLevel(level: number): ColorInfo {
|
|
63
|
-
if (level === 0) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
level: level as ColorSupportLevel,
|
|
69
|
-
hasBasic: true,
|
|
70
|
-
has256: level >= 2,
|
|
71
|
-
has16m: level >= 3,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
type Options = {
|
|
76
|
-
readonly streamIsTTY?: boolean;
|
|
77
|
-
readonly sniffFlags?: boolean;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
// eslint-disable-next-line complexity
|
|
81
|
-
function supportsColorLevel(
|
|
82
|
-
haveStream: boolean,
|
|
83
|
-
{ streamIsTTY, sniffFlags = true }: Options = {},
|
|
84
|
-
): number {
|
|
85
|
-
const noFlagForceColor = envForceColor();
|
|
86
|
-
if (noFlagForceColor !== undefined) {
|
|
87
|
-
flagForceColor = noFlagForceColor;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
91
|
-
|
|
92
|
-
if (forceColor === 0) {
|
|
93
|
-
return 0;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (sniffFlags) {
|
|
97
|
-
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
98
|
-
return 3;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (hasFlag("color=256")) {
|
|
102
|
-
return 2;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Check for Azure DevOps pipelines. Has to be above the `!streamIsTTY` check.
|
|
107
|
-
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
108
|
-
return 1;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
112
|
-
return 0;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const min = forceColor ?? 0;
|
|
116
|
-
|
|
117
|
-
if (env["TERM"] === "dumb") {
|
|
118
|
-
return min;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (process.platform === "win32") {
|
|
122
|
-
// Windows 10 build 10586 is the first Windows release that supports 256 colors.
|
|
123
|
-
// Windows 10 build 14931 is the first release that supports 16m/TrueColor.
|
|
124
|
-
const osRelease = os.release().split(".");
|
|
125
|
-
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10_586) {
|
|
126
|
-
return Number(osRelease[2]) >= 14_931 ? 3 : 2;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return 1;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if ("CI" in env) {
|
|
133
|
-
if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
|
|
134
|
-
return 3;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (
|
|
138
|
-
["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) ||
|
|
139
|
-
env["CI_NAME"] === "codeship"
|
|
140
|
-
) {
|
|
141
|
-
return 1;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return min;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if ("TEAMCITY_VERSION" in env) {
|
|
148
|
-
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env["TEAMCITY_VERSION"]!) ? 1 : 0;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (env["COLORTERM"] === "truecolor") {
|
|
152
|
-
return 3;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (env["TERM"] === "xterm-kitty") {
|
|
156
|
-
return 3;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (env["TERM"] === "xterm-ghostty") {
|
|
160
|
-
return 3;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (env["TERM"] === "wezterm") {
|
|
164
|
-
return 3;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if ("TERM_PROGRAM" in env) {
|
|
168
|
-
const version = Number.parseInt((env["TERM_PROGRAM_VERSION"] ?? "").split(".")[0]!, 10);
|
|
169
|
-
|
|
170
|
-
switch (env["TERM_PROGRAM"]) {
|
|
171
|
-
case "iTerm.app": {
|
|
172
|
-
return version >= 3 ? 3 : 2;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
case "Apple_Terminal": {
|
|
176
|
-
return 2;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
default:
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (/-256(color)?$/i.test(env["TERM"] ?? "")) {
|
|
184
|
-
return 2;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env["TERM"] ?? "")) {
|
|
188
|
-
return 1;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if ("COLORTERM" in env) {
|
|
192
|
-
return 1;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return min;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export function createSupportsColor(
|
|
199
|
-
stream: { isTTY?: boolean } | undefined,
|
|
200
|
-
options: Options = {},
|
|
201
|
-
): ColorInfo {
|
|
202
|
-
const level = supportsColorLevel(Boolean(stream), {
|
|
203
|
-
streamIsTTY: Boolean(stream?.isTTY),
|
|
204
|
-
...options,
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
return translateLevel(level);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export const supportsColor = {
|
|
211
|
-
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
|
212
|
-
stderr: createSupportsColor({ isTTY: tty.isatty(2) }),
|
|
213
|
-
};
|
package/src/ansi/widest-line.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// Derived from `widest-line` (MIT, Sindre Sorhus).
|
|
2
|
-
import { stringWidth } from "./string-width.ts";
|
|
3
|
-
|
|
4
|
-
export const widestLine = (string: string): number => {
|
|
5
|
-
let lineWidth = 0;
|
|
6
|
-
|
|
7
|
-
for (const line of string.split("\n")) {
|
|
8
|
-
lineWidth = Math.max(lineWidth, stringWidth(line));
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return lineWidth;
|
|
12
|
-
};
|
package/src/auto-bind.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// Derived from `auto-bind` (MIT, Sindre Sorhus), reduced to the surface Ink uses.
|
|
2
|
-
// Reflective prototype-walking code: the broad `object` type is the right one here.
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-restricted-types */
|
|
4
|
-
|
|
5
|
-
// Gets all non-builtin properties up the prototype chain.
|
|
6
|
-
const getAllProperties = (object: object): Array<[object, string | symbol]> => {
|
|
7
|
-
const properties: Array<[object, string | symbol]> = [];
|
|
8
|
-
let current: object | null = object;
|
|
9
|
-
|
|
10
|
-
do {
|
|
11
|
-
for (const key of Reflect.ownKeys(current)) {
|
|
12
|
-
properties.push([current, key]);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
current = Reflect.getPrototypeOf(current);
|
|
16
|
-
} while (current && current !== Object.prototype);
|
|
17
|
-
|
|
18
|
-
return properties;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const autoBind = <T extends object>(self: T): T => {
|
|
22
|
-
for (const [object, key] of getAllProperties(
|
|
23
|
-
(self.constructor as { prototype: object }).prototype,
|
|
24
|
-
)) {
|
|
25
|
-
if (key === "constructor") {
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
|
|
30
|
-
|
|
31
|
-
if (descriptor && typeof descriptor.value === "function") {
|
|
32
|
-
const value = (self as Record<string | symbol, unknown>)[key];
|
|
33
|
-
|
|
34
|
-
if (typeof value === "function") {
|
|
35
|
-
(self as Record<string | symbol, unknown>)[key] = value.bind(self);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return self;
|
|
41
|
-
};
|
package/src/colorize.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { chalk, type ForegroundColorName, type BackgroundColorName } from "./ansi/chalk.ts";
|
|
2
|
-
|
|
3
|
-
type ColorType = "foreground" | "background";
|
|
4
|
-
|
|
5
|
-
const rgbRegex = /^rgb\(\s?(\d+),\s?(\d+),\s?(\d+)\s?\)$/;
|
|
6
|
-
const ansiRegex = /^ansi256\(\s?(\d+)\s?\)$/;
|
|
7
|
-
|
|
8
|
-
const isNamedColor = (color: string): color is ForegroundColorName => {
|
|
9
|
-
return color in chalk;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const colorize = (str: string, color: string | undefined, type: ColorType): string => {
|
|
13
|
-
if (!color) {
|
|
14
|
-
return str;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (isNamedColor(color)) {
|
|
18
|
-
if (type === "foreground") {
|
|
19
|
-
return chalk[color](str);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const methodName = `bg${color[0]!.toUpperCase() + color.slice(1)}` as BackgroundColorName;
|
|
23
|
-
|
|
24
|
-
return chalk[methodName](str);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (color.startsWith("#")) {
|
|
28
|
-
return type === "foreground" ? chalk.hex(color)(str) : chalk.bgHex(color)(str);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (color.startsWith("ansi256")) {
|
|
32
|
-
const matches = ansiRegex.exec(color);
|
|
33
|
-
|
|
34
|
-
if (!matches) {
|
|
35
|
-
return str;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const value = Number(matches[1]);
|
|
39
|
-
|
|
40
|
-
return type === "foreground" ? chalk.ansi256(value)(str) : chalk.bgAnsi256(value)(str);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (color.startsWith("rgb")) {
|
|
44
|
-
const matches = rgbRegex.exec(color);
|
|
45
|
-
|
|
46
|
-
if (!matches) {
|
|
47
|
-
return str;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const firstValue = Number(matches[1]);
|
|
51
|
-
const secondValue = Number(matches[2]);
|
|
52
|
-
const thirdValue = Number(matches[3]);
|
|
53
|
-
|
|
54
|
-
return type === "foreground"
|
|
55
|
-
? chalk.rgb(firstValue, secondValue, thirdValue)(str)
|
|
56
|
-
: chalk.bgRgb(firstValue, secondValue, thirdValue)(str);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return str;
|
|
60
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// Ignoring missing types error to avoid adding another dependency for this hack to work
|
|
2
|
-
import ws from "ws";
|
|
3
|
-
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
5
|
-
const customGlobal = globalThis as any;
|
|
6
|
-
|
|
7
|
-
// These things must exist before importing `react-devtools-core`
|
|
8
|
-
// Using ||= intentionally to set falsy values, not just null/undefined
|
|
9
|
-
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
11
|
-
customGlobal.WebSocket ||= ws;
|
|
12
|
-
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
14
|
-
customGlobal.window ||= globalThis;
|
|
15
|
-
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
17
|
-
customGlobal.self ||= globalThis;
|
|
18
|
-
|
|
19
|
-
// Filter out Ink's internal components from devtools for a cleaner view.
|
|
20
|
-
// Also, ince `react-devtools-shared` package isn't published on npm, we can't
|
|
21
|
-
// use its types, that's why there are hard-coded values in `type` fields below.
|
|
22
|
-
// See https://github.com/facebook/react/blob/edf6eac8a181860fd8a2d076a43806f1237495a1/packages/react-devtools-shared/src/types.js#L24
|
|
23
|
-
customGlobal.window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ = [
|
|
24
|
-
{
|
|
25
|
-
// ComponentFilterElementType
|
|
26
|
-
type: 1,
|
|
27
|
-
// ElementTypeHostComponent
|
|
28
|
-
value: 7,
|
|
29
|
-
isEnabled: true,
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
// ComponentFilterDisplayName
|
|
33
|
-
type: 2,
|
|
34
|
-
value: "InternalApp",
|
|
35
|
-
isEnabled: true,
|
|
36
|
-
isValid: true,
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
// ComponentFilterDisplayName
|
|
40
|
-
type: 2,
|
|
41
|
-
value: "InternalAppContext",
|
|
42
|
-
isEnabled: true,
|
|
43
|
-
isValid: true,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
// ComponentFilterDisplayName
|
|
47
|
-
type: 2,
|
|
48
|
-
value: "InternalStdoutContext",
|
|
49
|
-
isEnabled: true,
|
|
50
|
-
isValid: true,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
// ComponentFilterDisplayName
|
|
54
|
-
type: 2,
|
|
55
|
-
value: "InternalStderrContext",
|
|
56
|
-
isEnabled: true,
|
|
57
|
-
isValid: true,
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
// ComponentFilterDisplayName
|
|
61
|
-
type: 2,
|
|
62
|
-
value: "InternalStdinContext",
|
|
63
|
-
isEnabled: true,
|
|
64
|
-
isValid: true,
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
// ComponentFilterDisplayName
|
|
68
|
-
type: 2,
|
|
69
|
-
value: "InternalFocusContext",
|
|
70
|
-
isEnabled: true,
|
|
71
|
-
isValid: true,
|
|
72
|
-
},
|
|
73
|
-
];
|
package/src/indent-string.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// Derived from `indent-string` (MIT, Sindre Sorhus), reduced to the surface Ink uses.
|
|
2
|
-
export const indentString = (
|
|
3
|
-
string: string,
|
|
4
|
-
count = 1,
|
|
5
|
-
options: { indent?: string; includeEmptyLines?: boolean } = {},
|
|
6
|
-
): string => {
|
|
7
|
-
const { indent = " ", includeEmptyLines = false } = options;
|
|
8
|
-
|
|
9
|
-
if (count === 0) {
|
|
10
|
-
return string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const regex = includeEmptyLines ? /^/gm : /^(?!\s*$)/gm;
|
|
14
|
-
|
|
15
|
-
return string.replace(regex, indent.repeat(count));
|
|
16
|
-
};
|
package/src/is-in-ci.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// Derived from `is-in-ci` (MIT, Sindre Sorhus).
|
|
2
|
-
import process from "node:process";
|
|
3
|
-
|
|
4
|
-
const check = (key: string): boolean =>
|
|
5
|
-
key in process.env && process.env[key] !== "0" && process.env[key] !== "false";
|
|
6
|
-
|
|
7
|
-
export const isInCi = check("CI") || check("CONTINUOUS_INTEGRATION");
|