esp32tool 1.2.0 → 1.3.0

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.
@@ -0,0 +1,290 @@
1
+ interface ConsoleState {
2
+ bold: boolean;
3
+ italic: boolean;
4
+ underline: boolean;
5
+ strikethrough: boolean;
6
+ foregroundColor: string | null;
7
+ backgroundColor: string | null;
8
+ carriageReturn: boolean;
9
+ secret: boolean;
10
+ }
11
+
12
+ export class ColoredConsole {
13
+ public state: ConsoleState = {
14
+ bold: false,
15
+ italic: false,
16
+ underline: false,
17
+ strikethrough: false,
18
+ foregroundColor: null,
19
+ backgroundColor: null,
20
+ carriageReturn: false,
21
+ secret: false,
22
+ };
23
+
24
+ constructor(public targetElement: HTMLElement) {}
25
+
26
+ logs(): string {
27
+ return this.targetElement.innerText;
28
+ }
29
+
30
+ addLine(line: string) {
31
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: ANSI escape sequences
32
+ const re = /(?:\x1B|\\x1B)(?:\[(.*?)[@-~]|\].*?(?:\x07|\x1B\\))/g;
33
+ let i = 0;
34
+
35
+ if (this.state.carriageReturn) {
36
+ if (line !== "\n") {
37
+ // don't remove if \r\n
38
+ if (this.targetElement.lastChild) {
39
+ this.targetElement.removeChild(this.targetElement.lastChild);
40
+ }
41
+ }
42
+ this.state.carriageReturn = false;
43
+ }
44
+
45
+ const hasBareCR = line.endsWith("\r") && !line.endsWith("\r\n");
46
+ if (hasBareCR) {
47
+ this.state.carriageReturn = true;
48
+ }
49
+
50
+ const lineSpan = document.createElement("span");
51
+ lineSpan.classList.add("line");
52
+ this.targetElement.appendChild(lineSpan);
53
+
54
+ const addSpan = (content: string) => {
55
+ if (content === "") return;
56
+
57
+ const span = document.createElement("span");
58
+ if (this.state.bold) span.classList.add("log-bold");
59
+ if (this.state.italic) span.classList.add("log-italic");
60
+ if (this.state.underline) span.classList.add("log-underline");
61
+ if (this.state.strikethrough) span.classList.add("log-strikethrough");
62
+ if (this.state.secret) span.classList.add("log-secret");
63
+ if (this.state.foregroundColor !== null)
64
+ span.classList.add(`log-fg-${this.state.foregroundColor}`);
65
+ if (this.state.backgroundColor !== null)
66
+ span.classList.add(`log-bg-${this.state.backgroundColor}`);
67
+ span.appendChild(document.createTextNode(content));
68
+ lineSpan.appendChild(span);
69
+
70
+ if (this.state.secret) {
71
+ const redacted = document.createElement("span");
72
+ redacted.classList.add("log-secret-redacted");
73
+ redacted.appendChild(document.createTextNode("[redacted]"));
74
+ lineSpan.appendChild(redacted);
75
+ }
76
+ };
77
+
78
+ while (true) {
79
+ const match = re.exec(line);
80
+ if (match === null) break;
81
+
82
+ const j = match.index;
83
+ addSpan(line.substring(i, j));
84
+ i = j + match[0].length;
85
+
86
+ if (match[1] === undefined) continue;
87
+
88
+ for (const colorCode of match[1].split(";")) {
89
+ switch (parseInt(colorCode)) {
90
+ case 0:
91
+ // reset
92
+ this.state.bold = false;
93
+ this.state.italic = false;
94
+ this.state.underline = false;
95
+ this.state.strikethrough = false;
96
+ this.state.foregroundColor = null;
97
+ this.state.backgroundColor = null;
98
+ this.state.secret = false;
99
+ break;
100
+ case 1:
101
+ this.state.bold = true;
102
+ break;
103
+ case 3:
104
+ this.state.italic = true;
105
+ break;
106
+ case 4:
107
+ this.state.underline = true;
108
+ break;
109
+ case 5:
110
+ this.state.secret = true;
111
+ break;
112
+ case 6:
113
+ this.state.secret = false;
114
+ break;
115
+ case 9:
116
+ this.state.strikethrough = true;
117
+ break;
118
+ case 22:
119
+ this.state.bold = false;
120
+ break;
121
+ case 23:
122
+ this.state.italic = false;
123
+ break;
124
+ case 24:
125
+ this.state.underline = false;
126
+ break;
127
+ case 29:
128
+ this.state.strikethrough = false;
129
+ break;
130
+ case 30:
131
+ this.state.foregroundColor = "black";
132
+ break;
133
+ case 31:
134
+ this.state.foregroundColor = "red";
135
+ break;
136
+ case 32:
137
+ this.state.foregroundColor = "green";
138
+ break;
139
+ case 33:
140
+ this.state.foregroundColor = "yellow";
141
+ break;
142
+ case 34:
143
+ this.state.foregroundColor = "blue";
144
+ break;
145
+ case 35:
146
+ this.state.foregroundColor = "magenta";
147
+ break;
148
+ case 36:
149
+ this.state.foregroundColor = "cyan";
150
+ break;
151
+ case 37:
152
+ this.state.foregroundColor = "white";
153
+ break;
154
+ case 39:
155
+ this.state.foregroundColor = null;
156
+ break;
157
+ case 41:
158
+ this.state.backgroundColor = "red";
159
+ break;
160
+ case 42:
161
+ this.state.backgroundColor = "green";
162
+ break;
163
+ case 43:
164
+ this.state.backgroundColor = "yellow";
165
+ break;
166
+ case 44:
167
+ this.state.backgroundColor = "blue";
168
+ break;
169
+ case 45:
170
+ this.state.backgroundColor = "magenta";
171
+ break;
172
+ case 46:
173
+ this.state.backgroundColor = "cyan";
174
+ break;
175
+ case 47:
176
+ this.state.backgroundColor = "white";
177
+ break;
178
+ case 40:
179
+ this.state.backgroundColor = "black";
180
+ break;
181
+ case 49:
182
+ this.state.backgroundColor = null;
183
+ break;
184
+ }
185
+ }
186
+ }
187
+ const atBottom =
188
+ this.targetElement.scrollTop >
189
+ this.targetElement.scrollHeight - this.targetElement.offsetHeight - 50;
190
+
191
+ addSpan(line.substring(i));
192
+
193
+ // Keep scroll at bottom
194
+ if (atBottom) {
195
+ this.targetElement.scrollTop = this.targetElement.scrollHeight;
196
+ }
197
+ }
198
+ }
199
+
200
+ export const coloredConsoleStyles = `
201
+ .log {
202
+ flex: 1;
203
+ background-color: #1c1c1c;
204
+ font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier,
205
+ monospace;
206
+ font-size: 12px;
207
+ padding: 16px;
208
+ overflow: auto;
209
+ line-height: 1.45;
210
+ border-radius: 3px;
211
+ white-space: pre-wrap;
212
+ overflow-wrap: break-word;
213
+ color: #ddd;
214
+ }
215
+
216
+ .log-bold {
217
+ font-weight: bold;
218
+ }
219
+ .log-italic {
220
+ font-style: italic;
221
+ }
222
+ .log-underline {
223
+ text-decoration: underline;
224
+ }
225
+ .log-strikethrough {
226
+ text-decoration: line-through;
227
+ }
228
+ .log-underline.log-strikethrough {
229
+ text-decoration: underline line-through;
230
+ }
231
+ .log-secret {
232
+ -webkit-user-select: none;
233
+ -moz-user-select: none;
234
+ -ms-user-select: none;
235
+ user-select: none;
236
+ }
237
+ .log-secret-redacted {
238
+ opacity: 0;
239
+ width: 1px;
240
+ font-size: 1px;
241
+ }
242
+ .log-fg-black {
243
+ color: rgb(128, 128, 128);
244
+ }
245
+ .log-fg-red {
246
+ color: rgb(255, 0, 0);
247
+ }
248
+ .log-fg-green {
249
+ color: rgb(0, 255, 0);
250
+ }
251
+ .log-fg-yellow {
252
+ color: rgb(255, 255, 0);
253
+ }
254
+ .log-fg-blue {
255
+ color: rgb(0, 0, 255);
256
+ }
257
+ .log-fg-magenta {
258
+ color: rgb(255, 0, 255);
259
+ }
260
+ .log-fg-cyan {
261
+ color: rgb(0, 255, 255);
262
+ }
263
+ .log-fg-white {
264
+ color: rgb(187, 187, 187);
265
+ }
266
+ .log-bg-black {
267
+ background-color: rgb(0, 0, 0);
268
+ }
269
+ .log-bg-red {
270
+ background-color: rgb(255, 0, 0);
271
+ }
272
+ .log-bg-green {
273
+ background-color: rgb(0, 255, 0);
274
+ }
275
+ .log-bg-yellow {
276
+ background-color: rgb(255, 255, 0);
277
+ }
278
+ .log-bg-blue {
279
+ background-color: rgb(0, 0, 255);
280
+ }
281
+ .log-bg-magenta {
282
+ background-color: rgb(255, 0, 255);
283
+ }
284
+ .log-bg-cyan {
285
+ background-color: rgb(0, 255, 255);
286
+ }
287
+ .log-bg-white {
288
+ background-color: rgb(255, 255, 255);
289
+ }
290
+ `;
@@ -0,0 +1,20 @@
1
+ export class LineBreakTransformer implements Transformer<string, string> {
2
+ private chunks = "";
3
+
4
+ transform(
5
+ chunk: string,
6
+ controller: TransformStreamDefaultController<string>,
7
+ ) {
8
+ // Append new chunks to existing chunks.
9
+ this.chunks += chunk;
10
+ // For each line breaks in chunks, send the parsed lines out.
11
+ const lines = this.chunks.split("\r\n");
12
+ this.chunks = lines.pop()!;
13
+ lines.forEach((line) => controller.enqueue(line + "\r\n"));
14
+ }
15
+
16
+ flush(controller: TransformStreamDefaultController<string>) {
17
+ // When the stream is closed, flush any remaining chunks out.
18
+ controller.enqueue(this.chunks);
19
+ }
20
+ }