toolcraft-openapi 0.0.1
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 +64 -0
- package/dist/api-command.d.ts +7 -0
- package/dist/api-command.js +4 -0
- package/dist/auth/bearer-token-auth.d.ts +8 -0
- package/dist/auth/bearer-token-auth.js +216 -0
- package/dist/auth/types.d.ts +9 -0
- package/dist/auth/types.js +1 -0
- package/dist/bin/generate.d.ts +40 -0
- package/dist/bin/generate.js +248 -0
- package/dist/define-client.d.ts +20 -0
- package/dist/define-client.js +148 -0
- package/dist/generate.d.ts +210 -0
- package/dist/generate.js +1131 -0
- package/dist/group-by-noun.d.ts +6 -0
- package/dist/group-by-noun.js +17 -0
- package/dist/http.d.ts +26 -0
- package/dist/http.js +123 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +6 -0
- package/dist/interpreter.d.ts +6 -0
- package/dist/interpreter.js +289 -0
- package/dist/lock.d.ts +14 -0
- package/dist/lock.js +48 -0
- package/dist/naming.d.ts +24 -0
- package/dist/naming.js +218 -0
- package/dist/request-shape.d.ts +15 -0
- package/dist/request-shape.js +5 -0
- package/dist/runtime.d.ts +13 -0
- package/dist/runtime.js +94 -0
- package/dist/spec-source.d.ts +11 -0
- package/dist/spec-source.js +63 -0
- package/node_modules/@poe-code/design-system/dist/acp/components.d.ts +11 -0
- package/node_modules/@poe-code/design-system/dist/acp/components.js +121 -0
- package/node_modules/@poe-code/design-system/dist/acp/index.d.ts +3 -0
- package/node_modules/@poe-code/design-system/dist/acp/index.js +2 -0
- package/node_modules/@poe-code/design-system/dist/acp/writer.d.ts +13 -0
- package/node_modules/@poe-code/design-system/dist/acp/writer.js +21 -0
- package/node_modules/@poe-code/design-system/dist/components/command-errors.d.ts +16 -0
- package/node_modules/@poe-code/design-system/dist/components/command-errors.js +22 -0
- package/node_modules/@poe-code/design-system/dist/components/help-formatter.d.ts +20 -0
- package/node_modules/@poe-code/design-system/dist/components/help-formatter.js +27 -0
- package/node_modules/@poe-code/design-system/dist/components/index.d.ts +10 -0
- package/node_modules/@poe-code/design-system/dist/components/index.js +7 -0
- package/node_modules/@poe-code/design-system/dist/components/logger.d.ts +11 -0
- package/node_modules/@poe-code/design-system/dist/components/logger.js +60 -0
- package/node_modules/@poe-code/design-system/dist/components/symbols.d.ts +12 -0
- package/node_modules/@poe-code/design-system/dist/components/symbols.js +71 -0
- package/node_modules/@poe-code/design-system/dist/components/table.d.ts +13 -0
- package/node_modules/@poe-code/design-system/dist/components/table.js +74 -0
- package/node_modules/@poe-code/design-system/dist/components/text.d.ts +14 -0
- package/node_modules/@poe-code/design-system/dist/components/text.js +104 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/ansi.d.ts +18 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/ansi.js +298 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/buffer.d.ts +25 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/buffer.js +189 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/border.d.ts +9 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/border.js +123 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/footer.d.ts +8 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/footer.js +57 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/output-pane.d.ts +12 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/output-pane.js +254 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/stats-pane.d.ts +7 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/components/stats-pane.js +121 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/dashboard.d.ts +20 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/dashboard.js +167 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/demo.d.ts +13 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/demo.js +145 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/index.d.ts +8 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/index.js +4 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/keymap.d.ts +3 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/keymap.js +99 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/layout.d.ts +25 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/layout.js +79 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/should-use-dashboard.d.ts +10 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/should-use-dashboard.js +7 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/snapshot.d.ts +10 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/snapshot.js +68 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/store.d.ts +8 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/store.js +51 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/terminal.d.ts +37 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/terminal.js +233 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/types.d.ts +36 -0
- package/node_modules/@poe-code/design-system/dist/dashboard/types.js +1 -0
- package/node_modules/@poe-code/design-system/dist/index.d.ts +33 -0
- package/node_modules/@poe-code/design-system/dist/index.js +31 -0
- package/node_modules/@poe-code/design-system/dist/internal/output-format.d.ts +6 -0
- package/node_modules/@poe-code/design-system/dist/internal/output-format.js +22 -0
- package/node_modules/@poe-code/design-system/dist/internal/strip-ansi.d.ts +1 -0
- package/node_modules/@poe-code/design-system/dist/internal/strip-ansi.js +3 -0
- package/node_modules/@poe-code/design-system/dist/internal/theme-detect.d.ts +11 -0
- package/node_modules/@poe-code/design-system/dist/internal/theme-detect.js +49 -0
- package/node_modules/@poe-code/design-system/dist/prompts/index.d.ts +66 -0
- package/node_modules/@poe-code/design-system/dist/prompts/index.js +132 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/cancel.d.ts +2 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/cancel.js +9 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/intro.d.ts +1 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/intro.js +15 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/log.d.ts +18 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/log.js +101 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/note.d.ts +1 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/note.js +39 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/outro.d.ts +1 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/outro.js +16 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/spinner.d.ts +6 -0
- package/node_modules/@poe-code/design-system/dist/prompts/primitives/spinner.js +74 -0
- package/node_modules/@poe-code/design-system/dist/prompts/theme.d.ts +11 -0
- package/node_modules/@poe-code/design-system/dist/prompts/theme.js +12 -0
- package/node_modules/@poe-code/design-system/dist/static/index.d.ts +4 -0
- package/node_modules/@poe-code/design-system/dist/static/index.js +2 -0
- package/node_modules/@poe-code/design-system/dist/static/menu.d.ts +11 -0
- package/node_modules/@poe-code/design-system/dist/static/menu.js +36 -0
- package/node_modules/@poe-code/design-system/dist/static/spinner.d.ts +14 -0
- package/node_modules/@poe-code/design-system/dist/static/spinner.js +46 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/ast.d.ts +92 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/ast.js +1 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/demo-content.d.ts +2 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/demo-content.js +139 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/index.d.ts +6 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/index.js +8 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/block.d.ts +7 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/block.js +1495 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/frontmatter.d.ts +8 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/frontmatter.js +412 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/inline.d.ts +10 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/inline.js +1166 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser.d.ts +5 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser.js +42 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/renderer.d.ts +6 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/renderer.js +572 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/testing/theme-render-fixture.d.ts +1 -0
- package/node_modules/@poe-code/design-system/dist/terminal-markdown/testing/theme-render-fixture.js +27 -0
- package/node_modules/@poe-code/design-system/dist/tokens/colors.d.ts +35 -0
- package/node_modules/@poe-code/design-system/dist/tokens/colors.js +34 -0
- package/node_modules/@poe-code/design-system/dist/tokens/index.d.ts +4 -0
- package/node_modules/@poe-code/design-system/dist/tokens/index.js +4 -0
- package/node_modules/@poe-code/design-system/dist/tokens/spacing.d.ts +6 -0
- package/node_modules/@poe-code/design-system/dist/tokens/spacing.js +6 -0
- package/node_modules/@poe-code/design-system/dist/tokens/typography.d.ts +7 -0
- package/node_modules/@poe-code/design-system/dist/tokens/typography.js +8 -0
- package/node_modules/@poe-code/design-system/dist/tokens/widths.d.ts +5 -0
- package/node_modules/@poe-code/design-system/dist/tokens/widths.js +5 -0
- package/node_modules/@poe-code/design-system/package.json +25 -0
- package/node_modules/auth-store/README.md +47 -0
- package/node_modules/auth-store/dist/create-secret-store.d.ts +2 -0
- package/node_modules/auth-store/dist/create-secret-store.js +35 -0
- package/node_modules/auth-store/dist/encrypted-file-store.d.ts +39 -0
- package/node_modules/auth-store/dist/encrypted-file-store.js +156 -0
- package/node_modules/auth-store/dist/index.d.ts +7 -0
- package/node_modules/auth-store/dist/index.js +4 -0
- package/node_modules/auth-store/dist/keychain-store.d.ts +22 -0
- package/node_modules/auth-store/dist/keychain-store.js +111 -0
- package/node_modules/auth-store/dist/provider-store.d.ts +10 -0
- package/node_modules/auth-store/dist/provider-store.js +28 -0
- package/node_modules/auth-store/dist/types.d.ts +20 -0
- package/node_modules/auth-store/dist/types.js +1 -0
- package/node_modules/auth-store/package.json +25 -0
- package/package.json +48 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
const ESC = "\u001b";
|
|
2
|
+
export function hasAnsi(text) {
|
|
3
|
+
return text.includes(ESC);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Parse a block of text that may contain ANSI SGR escape codes into a sequence of
|
|
7
|
+
* logical lines split on "\n". Each line is a list of styled segments: contiguous
|
|
8
|
+
* printable runs of characters sharing the same style.
|
|
9
|
+
*
|
|
10
|
+
* Non-SGR CSI sequences and other control characters are discarded. `baseStyle` is
|
|
11
|
+
* used as the initial style and as the restore target for SGR reset / default color.
|
|
12
|
+
*/
|
|
13
|
+
export function parseAnsi(text, baseStyle) {
|
|
14
|
+
const base = normalizeStyle(baseStyle);
|
|
15
|
+
let style = { ...base };
|
|
16
|
+
const lines = [];
|
|
17
|
+
let segments = [];
|
|
18
|
+
let pending = "";
|
|
19
|
+
const flushSegment = () => {
|
|
20
|
+
if (pending.length === 0) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const last = segments[segments.length - 1];
|
|
24
|
+
if (last && stylesEqual(last.style, style)) {
|
|
25
|
+
last.text += pending;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
segments.push({ text: pending, style: { ...style } });
|
|
29
|
+
}
|
|
30
|
+
pending = "";
|
|
31
|
+
};
|
|
32
|
+
const finishLine = () => {
|
|
33
|
+
flushSegment();
|
|
34
|
+
lines.push({ segments });
|
|
35
|
+
segments = [];
|
|
36
|
+
};
|
|
37
|
+
let index = 0;
|
|
38
|
+
while (index < text.length) {
|
|
39
|
+
const ch = text[index];
|
|
40
|
+
if (ch === ESC && text[index + 1] === "[") {
|
|
41
|
+
flushSegment();
|
|
42
|
+
const paramsStart = index + 2;
|
|
43
|
+
let cursor = paramsStart;
|
|
44
|
+
while (cursor < text.length && !isCsiFinalByte(text[cursor])) {
|
|
45
|
+
cursor += 1;
|
|
46
|
+
}
|
|
47
|
+
if (cursor >= text.length) {
|
|
48
|
+
index = text.length;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
const params = text.slice(paramsStart, cursor);
|
|
52
|
+
const finalByte = text[cursor];
|
|
53
|
+
if (finalByte === "m") {
|
|
54
|
+
style = applySgr(style, parseParams(params), base);
|
|
55
|
+
}
|
|
56
|
+
index = cursor + 1;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (ch === ESC) {
|
|
60
|
+
flushSegment();
|
|
61
|
+
const next = text[index + 1];
|
|
62
|
+
if (next === "]" || next === "P" || next === "X" || next === "^" || next === "_") {
|
|
63
|
+
index = skipStringTerminated(text, index + 2);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
index += 2;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (ch === "\r") {
|
|
70
|
+
index += 1;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (ch === "\n") {
|
|
74
|
+
finishLine();
|
|
75
|
+
index += 1;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const code = ch.charCodeAt(0);
|
|
79
|
+
if (code < 0x20 && ch !== "\t") {
|
|
80
|
+
index += 1;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
pending += ch;
|
|
84
|
+
index += 1;
|
|
85
|
+
}
|
|
86
|
+
finishLine();
|
|
87
|
+
return lines;
|
|
88
|
+
}
|
|
89
|
+
function isCsiFinalByte(ch) {
|
|
90
|
+
const code = ch.charCodeAt(0);
|
|
91
|
+
return code >= 0x40 && code <= 0x7e;
|
|
92
|
+
}
|
|
93
|
+
function skipStringTerminated(text, start) {
|
|
94
|
+
let index = start;
|
|
95
|
+
while (index < text.length) {
|
|
96
|
+
const ch = text[index];
|
|
97
|
+
if (ch === "\u0007") {
|
|
98
|
+
return index + 1;
|
|
99
|
+
}
|
|
100
|
+
if (ch === ESC && text[index + 1] === "\\") {
|
|
101
|
+
return index + 2;
|
|
102
|
+
}
|
|
103
|
+
index += 1;
|
|
104
|
+
}
|
|
105
|
+
return index;
|
|
106
|
+
}
|
|
107
|
+
function parseParams(params) {
|
|
108
|
+
if (params.length === 0) {
|
|
109
|
+
return [0];
|
|
110
|
+
}
|
|
111
|
+
return params.split(";").map((part) => {
|
|
112
|
+
if (part.length === 0) {
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
const parsed = Number.parseInt(part, 10);
|
|
116
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const BASIC_COLORS = [
|
|
120
|
+
"black",
|
|
121
|
+
"red",
|
|
122
|
+
"green",
|
|
123
|
+
"yellow",
|
|
124
|
+
"blue",
|
|
125
|
+
"magenta",
|
|
126
|
+
"cyan",
|
|
127
|
+
"white"
|
|
128
|
+
];
|
|
129
|
+
const BRIGHT_COLORS = [
|
|
130
|
+
"gray",
|
|
131
|
+
"redBright",
|
|
132
|
+
"greenBright",
|
|
133
|
+
"yellowBright",
|
|
134
|
+
"blueBright",
|
|
135
|
+
"magentaBright",
|
|
136
|
+
"cyanBright",
|
|
137
|
+
"whiteBright"
|
|
138
|
+
];
|
|
139
|
+
function applySgr(style, params, base) {
|
|
140
|
+
let next = { ...style };
|
|
141
|
+
let index = 0;
|
|
142
|
+
while (index < params.length) {
|
|
143
|
+
const code = params[index];
|
|
144
|
+
if (code === 0) {
|
|
145
|
+
next = { ...base };
|
|
146
|
+
index += 1;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (code === 1) {
|
|
150
|
+
next.bold = true;
|
|
151
|
+
index += 1;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (code === 2) {
|
|
155
|
+
next.dim = true;
|
|
156
|
+
index += 1;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (code === 22) {
|
|
160
|
+
delete next.bold;
|
|
161
|
+
delete next.dim;
|
|
162
|
+
index += 1;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (code >= 30 && code <= 37) {
|
|
166
|
+
next.fg = BASIC_COLORS[code - 30];
|
|
167
|
+
index += 1;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (code === 38) {
|
|
171
|
+
const mode = params[index + 1];
|
|
172
|
+
if (mode === 5) {
|
|
173
|
+
const palette = params[index + 2] ?? 0;
|
|
174
|
+
next.fg = convert256(palette);
|
|
175
|
+
index += 3;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (mode === 2) {
|
|
179
|
+
const r = params[index + 2] ?? 0;
|
|
180
|
+
const g = params[index + 3] ?? 0;
|
|
181
|
+
const b = params[index + 4] ?? 0;
|
|
182
|
+
next.fg = rgbToHex(r, g, b);
|
|
183
|
+
index += 5;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
index += 1;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (code === 39) {
|
|
190
|
+
if (base.fg !== undefined) {
|
|
191
|
+
next.fg = base.fg;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
delete next.fg;
|
|
195
|
+
}
|
|
196
|
+
index += 1;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (code >= 40 && code <= 47) {
|
|
200
|
+
next.bg = BASIC_COLORS[code - 40];
|
|
201
|
+
index += 1;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (code === 48) {
|
|
205
|
+
const mode = params[index + 1];
|
|
206
|
+
if (mode === 5) {
|
|
207
|
+
const palette = params[index + 2] ?? 0;
|
|
208
|
+
next.bg = convert256(palette);
|
|
209
|
+
index += 3;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (mode === 2) {
|
|
213
|
+
const r = params[index + 2] ?? 0;
|
|
214
|
+
const g = params[index + 3] ?? 0;
|
|
215
|
+
const b = params[index + 4] ?? 0;
|
|
216
|
+
next.bg = rgbToHex(r, g, b);
|
|
217
|
+
index += 5;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
index += 1;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (code === 49) {
|
|
224
|
+
if (base.bg !== undefined) {
|
|
225
|
+
next.bg = base.bg;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
delete next.bg;
|
|
229
|
+
}
|
|
230
|
+
index += 1;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (code >= 90 && code <= 97) {
|
|
234
|
+
next.fg = BRIGHT_COLORS[code - 90];
|
|
235
|
+
index += 1;
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
if (code >= 100 && code <= 107) {
|
|
239
|
+
next.bg = BRIGHT_COLORS[code - 100];
|
|
240
|
+
index += 1;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
index += 1;
|
|
244
|
+
}
|
|
245
|
+
return next;
|
|
246
|
+
}
|
|
247
|
+
function convert256(palette) {
|
|
248
|
+
if (palette < 0 || palette > 255) {
|
|
249
|
+
return "#000000";
|
|
250
|
+
}
|
|
251
|
+
if (palette < 8) {
|
|
252
|
+
return BASIC_COLORS[palette];
|
|
253
|
+
}
|
|
254
|
+
if (palette < 16) {
|
|
255
|
+
return BRIGHT_COLORS[palette - 8];
|
|
256
|
+
}
|
|
257
|
+
if (palette >= 232) {
|
|
258
|
+
const level = 8 + (palette - 232) * 10;
|
|
259
|
+
return rgbToHex(level, level, level);
|
|
260
|
+
}
|
|
261
|
+
const offset = palette - 16;
|
|
262
|
+
const r = Math.floor(offset / 36);
|
|
263
|
+
const g = Math.floor((offset % 36) / 6);
|
|
264
|
+
const b = offset % 6;
|
|
265
|
+
return rgbToHex(cubeLevel(r), cubeLevel(g), cubeLevel(b));
|
|
266
|
+
}
|
|
267
|
+
function cubeLevel(value) {
|
|
268
|
+
return value === 0 ? 0 : 55 + value * 40;
|
|
269
|
+
}
|
|
270
|
+
function rgbToHex(r, g, b) {
|
|
271
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
272
|
+
}
|
|
273
|
+
function toHex(value) {
|
|
274
|
+
const clamped = Math.max(0, Math.min(255, Math.floor(value)));
|
|
275
|
+
return clamped.toString(16).padStart(2, "0");
|
|
276
|
+
}
|
|
277
|
+
function stylesEqual(left, right) {
|
|
278
|
+
return left.fg === right.fg
|
|
279
|
+
&& left.bg === right.bg
|
|
280
|
+
&& left.bold === right.bold
|
|
281
|
+
&& left.dim === right.dim;
|
|
282
|
+
}
|
|
283
|
+
function normalizeStyle(style) {
|
|
284
|
+
const next = {};
|
|
285
|
+
if (style?.fg !== undefined) {
|
|
286
|
+
next.fg = style.fg;
|
|
287
|
+
}
|
|
288
|
+
if (style?.bg !== undefined) {
|
|
289
|
+
next.bg = style.bg;
|
|
290
|
+
}
|
|
291
|
+
if (style?.bold !== undefined) {
|
|
292
|
+
next.bold = style.bold;
|
|
293
|
+
}
|
|
294
|
+
if (style?.dim !== undefined) {
|
|
295
|
+
next.dim = style.dim;
|
|
296
|
+
}
|
|
297
|
+
return next;
|
|
298
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Cell, CellStyle, Rect } from "./types.js";
|
|
2
|
+
export declare class ScreenBuffer {
|
|
3
|
+
private _width;
|
|
4
|
+
private _height;
|
|
5
|
+
private _cells;
|
|
6
|
+
constructor(width: number, height: number);
|
|
7
|
+
get width(): number;
|
|
8
|
+
get height(): number;
|
|
9
|
+
put(x: number, y: number, text: string, style?: CellStyle): void;
|
|
10
|
+
get(x: number, y: number): Cell;
|
|
11
|
+
clear(style?: CellStyle): void;
|
|
12
|
+
clearRect(rect: Rect, style?: CellStyle): void;
|
|
13
|
+
resize(width: number, height: number): void;
|
|
14
|
+
putInRect(rect: Rect, row: number, text: string, style?: CellStyle): void;
|
|
15
|
+
private index;
|
|
16
|
+
private isInBounds;
|
|
17
|
+
private isInBoundsX;
|
|
18
|
+
private isInBoundsY;
|
|
19
|
+
}
|
|
20
|
+
export declare function diff(prev: ScreenBuffer, next: ScreenBuffer): Array<{
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
cell: Cell;
|
|
24
|
+
}>;
|
|
25
|
+
export declare function cellToAnsi(cell: Cell): string;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
const EMPTY_CELL = { ch: " ", style: {} };
|
|
3
|
+
export class ScreenBuffer {
|
|
4
|
+
_width;
|
|
5
|
+
_height;
|
|
6
|
+
_cells;
|
|
7
|
+
constructor(width, height) {
|
|
8
|
+
this._width = normalizeSize(width);
|
|
9
|
+
this._height = normalizeSize(height);
|
|
10
|
+
this._cells = createCells(this._width, this._height);
|
|
11
|
+
}
|
|
12
|
+
get width() {
|
|
13
|
+
return this._width;
|
|
14
|
+
}
|
|
15
|
+
get height() {
|
|
16
|
+
return this._height;
|
|
17
|
+
}
|
|
18
|
+
put(x, y, text, style) {
|
|
19
|
+
if (!this.isInBoundsY(y) || text.length === 0) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const normalizedStyle = normalizeStyle(style);
|
|
23
|
+
let offset = 0;
|
|
24
|
+
for (const ch of text) {
|
|
25
|
+
const targetX = x + offset;
|
|
26
|
+
offset += 1;
|
|
27
|
+
if (!this.isInBoundsX(targetX)) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
this._cells[this.index(targetX, y)] = { ch, style: normalizedStyle };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
get(x, y) {
|
|
34
|
+
if (!this.isInBounds(x, y)) {
|
|
35
|
+
return cloneCell(EMPTY_CELL);
|
|
36
|
+
}
|
|
37
|
+
return cloneCell(this._cells[this.index(x, y)] ?? EMPTY_CELL);
|
|
38
|
+
}
|
|
39
|
+
clear(style) {
|
|
40
|
+
this._cells = createCells(this._width, this._height, style);
|
|
41
|
+
}
|
|
42
|
+
clearRect(rect, style) {
|
|
43
|
+
const startX = Math.max(0, rect.x);
|
|
44
|
+
const startY = Math.max(0, rect.y);
|
|
45
|
+
const endX = Math.min(this._width, rect.x + Math.max(0, rect.width));
|
|
46
|
+
const endY = Math.min(this._height, rect.y + Math.max(0, rect.height));
|
|
47
|
+
const normalizedStyle = normalizeStyle(style);
|
|
48
|
+
for (let y = startY; y < endY; y += 1) {
|
|
49
|
+
for (let x = startX; x < endX; x += 1) {
|
|
50
|
+
this._cells[this.index(x, y)] = { ch: " ", style: normalizedStyle };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
resize(width, height) {
|
|
55
|
+
const nextWidth = normalizeSize(width);
|
|
56
|
+
const nextHeight = normalizeSize(height);
|
|
57
|
+
const nextCells = createCells(nextWidth, nextHeight);
|
|
58
|
+
const copyWidth = Math.min(this._width, nextWidth);
|
|
59
|
+
const copyHeight = Math.min(this._height, nextHeight);
|
|
60
|
+
for (let y = 0; y < copyHeight; y += 1) {
|
|
61
|
+
for (let x = 0; x < copyWidth; x += 1) {
|
|
62
|
+
nextCells[(y * nextWidth) + x] = cloneCell(this._cells[this.index(x, y)] ?? EMPTY_CELL);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
this._width = nextWidth;
|
|
66
|
+
this._height = nextHeight;
|
|
67
|
+
this._cells = nextCells;
|
|
68
|
+
}
|
|
69
|
+
putInRect(rect, row, text, style) {
|
|
70
|
+
if (row < 0 || row >= rect.height || text.length === 0 || rect.width <= 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const y = rect.y + row;
|
|
74
|
+
if (!this.isInBoundsY(y)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const normalizedStyle = normalizeStyle(style);
|
|
78
|
+
const rectEndX = rect.x + rect.width;
|
|
79
|
+
let offset = 0;
|
|
80
|
+
for (const ch of text) {
|
|
81
|
+
const targetX = rect.x + offset;
|
|
82
|
+
offset += 1;
|
|
83
|
+
if (targetX >= rectEndX) {
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
if (!this.isInBoundsX(targetX)) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
this._cells[this.index(targetX, y)] = { ch, style: normalizedStyle };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
index(x, y) {
|
|
93
|
+
return (y * this._width) + x;
|
|
94
|
+
}
|
|
95
|
+
isInBounds(x, y) {
|
|
96
|
+
return this.isInBoundsX(x) && this.isInBoundsY(y);
|
|
97
|
+
}
|
|
98
|
+
isInBoundsX(x) {
|
|
99
|
+
return x >= 0 && x < this._width;
|
|
100
|
+
}
|
|
101
|
+
isInBoundsY(y) {
|
|
102
|
+
return y >= 0 && y < this._height;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function diff(prev, next) {
|
|
106
|
+
const changes = [];
|
|
107
|
+
const width = Math.max(prev.width, next.width);
|
|
108
|
+
const height = Math.max(prev.height, next.height);
|
|
109
|
+
for (let y = 0; y < height; y += 1) {
|
|
110
|
+
for (let x = 0; x < width; x += 1) {
|
|
111
|
+
const previousCell = prev.get(x, y);
|
|
112
|
+
const nextCell = next.get(x, y);
|
|
113
|
+
if (!cellsEqual(previousCell, nextCell)) {
|
|
114
|
+
changes.push({ x, y, cell: nextCell });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return changes;
|
|
119
|
+
}
|
|
120
|
+
export function cellToAnsi(cell) {
|
|
121
|
+
const style = cell.style ?? {};
|
|
122
|
+
let painter = chalk;
|
|
123
|
+
if (style.bold) {
|
|
124
|
+
painter = painter.bold;
|
|
125
|
+
}
|
|
126
|
+
if (style.dim) {
|
|
127
|
+
painter = painter.dim;
|
|
128
|
+
}
|
|
129
|
+
if (style.fg) {
|
|
130
|
+
painter = applyForegroundColor(painter, style.fg);
|
|
131
|
+
}
|
|
132
|
+
if (style.bg) {
|
|
133
|
+
painter = applyBackgroundColor(painter, style.bg);
|
|
134
|
+
}
|
|
135
|
+
return painter(cell.ch);
|
|
136
|
+
}
|
|
137
|
+
function createCells(width, height, style) {
|
|
138
|
+
const normalizedStyle = normalizeStyle(style);
|
|
139
|
+
return Array.from({ length: width * height }, () => ({ ch: " ", style: normalizedStyle }));
|
|
140
|
+
}
|
|
141
|
+
function cloneCell(cell) {
|
|
142
|
+
return {
|
|
143
|
+
ch: cell.ch,
|
|
144
|
+
style: normalizeStyle(cell.style)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function normalizeStyle(style) {
|
|
148
|
+
const next = {};
|
|
149
|
+
if (style?.fg !== undefined) {
|
|
150
|
+
next.fg = style.fg;
|
|
151
|
+
}
|
|
152
|
+
if (style?.bg !== undefined) {
|
|
153
|
+
next.bg = style.bg;
|
|
154
|
+
}
|
|
155
|
+
if (style?.bold !== undefined) {
|
|
156
|
+
next.bold = style.bold;
|
|
157
|
+
}
|
|
158
|
+
if (style?.dim !== undefined) {
|
|
159
|
+
next.dim = style.dim;
|
|
160
|
+
}
|
|
161
|
+
return next;
|
|
162
|
+
}
|
|
163
|
+
function normalizeSize(value) {
|
|
164
|
+
return Math.max(0, Math.floor(value));
|
|
165
|
+
}
|
|
166
|
+
function cellsEqual(left, right) {
|
|
167
|
+
return left.ch === right.ch
|
|
168
|
+
&& left.style.fg === right.style.fg
|
|
169
|
+
&& left.style.bg === right.style.bg
|
|
170
|
+
&& left.style.bold === right.style.bold
|
|
171
|
+
&& left.style.dim === right.style.dim;
|
|
172
|
+
}
|
|
173
|
+
function applyForegroundColor(instance, color) {
|
|
174
|
+
if (color.startsWith("#")) {
|
|
175
|
+
return instance.hex(color);
|
|
176
|
+
}
|
|
177
|
+
const painter = instance[color];
|
|
178
|
+
return typeof painter === "function" ? painter : instance;
|
|
179
|
+
}
|
|
180
|
+
function applyBackgroundColor(instance, color) {
|
|
181
|
+
if (color.startsWith("#")) {
|
|
182
|
+
return instance.bgHex(color);
|
|
183
|
+
}
|
|
184
|
+
const methodName = color.startsWith("bg")
|
|
185
|
+
? color
|
|
186
|
+
: `bg${color.charAt(0).toUpperCase()}${color.slice(1)}`;
|
|
187
|
+
const painter = instance[methodName];
|
|
188
|
+
return typeof painter === "function" ? painter : instance;
|
|
189
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ScreenBuffer } from "../buffer.js";
|
|
2
|
+
import type { DashboardLayout } from "../layout.js";
|
|
3
|
+
import type { CellStyle } from "../types.js";
|
|
4
|
+
export type BorderOptions = {
|
|
5
|
+
leftTitle?: string;
|
|
6
|
+
rightTitle?: string;
|
|
7
|
+
style: CellStyle;
|
|
8
|
+
};
|
|
9
|
+
export declare function renderBorder(buffer: ScreenBuffer, layout: DashboardLayout, opts: BorderOptions): void;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export function renderBorder(buffer, layout, opts) {
|
|
2
|
+
const outer = layout.outerBorder;
|
|
3
|
+
if (outer.width <= 0 || outer.height <= 0) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
const left = outer.x;
|
|
7
|
+
const top = outer.y;
|
|
8
|
+
const right = outer.x + outer.width - 1;
|
|
9
|
+
const bottom = outer.y + outer.height - 1;
|
|
10
|
+
renderTopBorder(buffer, left, top, right, layout, opts);
|
|
11
|
+
renderSideBorders(buffer, left, right, top, bottom, opts.style);
|
|
12
|
+
renderBottomBorder(buffer, left, top, right, bottom, layout, opts.style);
|
|
13
|
+
renderVerticalDivider(buffer, layout, opts.style);
|
|
14
|
+
renderFooterDivider(buffer, left, right, bottom, layout, opts.style);
|
|
15
|
+
}
|
|
16
|
+
function renderTopBorder(buffer, left, top, right, layout, opts) {
|
|
17
|
+
if (left === right) {
|
|
18
|
+
buffer.put(left, top, "┌", opts.style);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const hasTopJunction = hasInteriorRows(top, layout.outerBorder.y + layout.outerBorder.height - 1)
|
|
22
|
+
&& hasPaneDivider(layout, left, right)
|
|
23
|
+
&& layout.divider.top <= top + 1
|
|
24
|
+
&& layout.divider.bottom >= top + 1;
|
|
25
|
+
if (!hasTopJunction) {
|
|
26
|
+
buffer.put(left, top, `┌${renderTopSegment(right - left - 1, opts.leftTitle)}┐`, opts.style);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const leftWidth = layout.divider.x - left - 1;
|
|
30
|
+
const rightWidth = right - layout.divider.x - 1;
|
|
31
|
+
const row = [
|
|
32
|
+
"┌",
|
|
33
|
+
renderTopSegment(leftWidth, opts.leftTitle),
|
|
34
|
+
"┬",
|
|
35
|
+
renderTopSegment(rightWidth, opts.rightTitle),
|
|
36
|
+
"┐"
|
|
37
|
+
].join("");
|
|
38
|
+
buffer.put(left, top, row, opts.style);
|
|
39
|
+
}
|
|
40
|
+
function renderSideBorders(buffer, left, right, top, bottom, style) {
|
|
41
|
+
for (let y = top + 1; y < bottom; y += 1) {
|
|
42
|
+
buffer.put(left, y, "│", style);
|
|
43
|
+
buffer.put(right, y, "│", style);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function renderBottomBorder(buffer, left, top, right, bottom, layout, style) {
|
|
47
|
+
if (bottom <= top) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (left === right) {
|
|
51
|
+
buffer.put(left, bottom, "└", style);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
buffer.put(left, bottom, "└", style);
|
|
55
|
+
buffer.put(left + 1, bottom, "─".repeat(Math.max(0, right - left - 1)), style);
|
|
56
|
+
buffer.put(right, bottom, "┘", style);
|
|
57
|
+
if (hasInteriorRows(top, bottom)
|
|
58
|
+
&& hasPaneDivider(layout, left, right)
|
|
59
|
+
&& layout.divider.top <= bottom - 1
|
|
60
|
+
&& layout.divider.bottom >= bottom - 1) {
|
|
61
|
+
buffer.put(layout.divider.x, bottom, "┴", style);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function renderVerticalDivider(buffer, layout, style) {
|
|
65
|
+
const left = layout.outerBorder.x;
|
|
66
|
+
const right = layout.outerBorder.x + layout.outerBorder.width - 1;
|
|
67
|
+
if (!hasPaneDivider(layout, left, right)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const startY = Math.max(layout.divider.top, layout.outerBorder.y + 1);
|
|
71
|
+
const endY = Math.min(layout.divider.bottom, layout.outerBorder.y + layout.outerBorder.height - 2);
|
|
72
|
+
for (let y = startY; y <= endY; y += 1) {
|
|
73
|
+
buffer.put(layout.divider.x, y, "│", style);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function renderFooterDivider(buffer, left, right, bottom, layout, style) {
|
|
77
|
+
const y = layout.footerDivider.y;
|
|
78
|
+
if (y <= layout.outerBorder.y || y >= bottom) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const width = layout.footerDivider.right - layout.footerDivider.left + 1;
|
|
82
|
+
if (width > 0) {
|
|
83
|
+
buffer.put(layout.footerDivider.left, y, "─".repeat(width), style);
|
|
84
|
+
}
|
|
85
|
+
buffer.put(left, y, "├", style);
|
|
86
|
+
buffer.put(right, y, "┤", style);
|
|
87
|
+
if (!hasPaneDivider(layout, left, right)
|
|
88
|
+
|| layout.divider.x < layout.footerDivider.left
|
|
89
|
+
|| layout.divider.x > layout.footerDivider.right) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const connectsAbove = layout.divider.bottom >= y - 1 && layout.divider.top <= y;
|
|
93
|
+
const connectsBelow = layout.divider.bottom > y;
|
|
94
|
+
if (connectsAbove && connectsBelow) {
|
|
95
|
+
buffer.put(layout.divider.x, y, "┼", style);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (connectsAbove) {
|
|
99
|
+
buffer.put(layout.divider.x, y, "┴", style);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function renderTopSegment(width, title) {
|
|
103
|
+
if (width <= 0) {
|
|
104
|
+
return "";
|
|
105
|
+
}
|
|
106
|
+
if (!title) {
|
|
107
|
+
return "─".repeat(width);
|
|
108
|
+
}
|
|
109
|
+
const content = `─ ${title} `;
|
|
110
|
+
if (content.length >= width) {
|
|
111
|
+
return content.slice(0, width);
|
|
112
|
+
}
|
|
113
|
+
return `${content}${"─".repeat(width - content.length)}`;
|
|
114
|
+
}
|
|
115
|
+
function hasInteriorRows(top, bottom) {
|
|
116
|
+
return (bottom - top) > 1;
|
|
117
|
+
}
|
|
118
|
+
function hasPaneDivider(layout, left, right) {
|
|
119
|
+
return layout.leftPane.width > 0
|
|
120
|
+
&& layout.rightPane.width > 0
|
|
121
|
+
&& layout.divider.x > left
|
|
122
|
+
&& layout.divider.x < right;
|
|
123
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ScreenBuffer } from "../buffer.js";
|
|
2
|
+
import type { Rect } from "../types.js";
|
|
3
|
+
export type FooterHint = {
|
|
4
|
+
key: string;
|
|
5
|
+
label: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function renderFooter(buffer: ScreenBuffer, rect: Rect, hints: FooterHint[]): void;
|
|
8
|
+
export declare function defaultHints(): FooterHint[];
|