@ansi-tools/parser 0.0.1 → 1.0.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.
- package/README.md +5 -2
- package/dist/escaped.js +22 -27
- package/dist/index.js +1 -1
- package/dist/{parse-BE4NnMTj.js → parse-DX-Po36R.js} +103 -87
- package/package.json +16 -8
package/README.md
CHANGED
|
@@ -20,6 +20,8 @@ Parser for ANSI escape sequences.
|
|
|
20
20
|
- ✅ Zero dependencies
|
|
21
21
|
- ✅ Separate optimized modules for raw and escaped input
|
|
22
22
|
|
|
23
|
+
Used by [ansi.tools](https://ansi.tools).
|
|
24
|
+
|
|
23
25
|
## Installation
|
|
24
26
|
|
|
25
27
|
```bash
|
|
@@ -145,10 +147,11 @@ for (const code of codes) {
|
|
|
145
147
|
## Type Definitions
|
|
146
148
|
|
|
147
149
|
```ts
|
|
148
|
-
function parse(input: string): CODE[];
|
|
149
150
|
function tokenize(input: string): TOKEN[];
|
|
150
|
-
function
|
|
151
|
+
function parse(input: string): CODE[];
|
|
152
|
+
|
|
151
153
|
function* tokenizer(input: string): Generator<TOKEN>;
|
|
154
|
+
function* parser(tokens: Generator<TOKEN>): Generator<CODE>;
|
|
152
155
|
```
|
|
153
156
|
|
|
154
157
|
### CODE
|
package/dist/escaped.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APC, APC_OPEN, BACKSLASH, BELL, CODE_TYPES, CSI, CSI_OPEN, DCS, DCS_OPEN, DEC_OPEN, ESC, OSC, OSC_OPEN, PM, PM_OPEN, PRIVATE_OPENERS, SOS, SOS_OPEN, ST, STRING_OPENERS, TOKEN_TYPES, parser } from "./parse-
|
|
1
|
+
import { APC, APC_OPEN, BACKSLASH, BELL, CODE_TYPES, CSI, CSI_OPEN, DCS, DCS_OPEN, DEC_OPEN, ESC, OSC, OSC_OPEN, PM, PM_OPEN, PRIVATE_OPENERS, SOS, SOS_OPEN, ST, STRING_OPENERS, TOKEN_TYPES, parser } from "./parse-DX-Po36R.js";
|
|
2
2
|
|
|
3
3
|
//#region src/tokenize.escaped.ts
|
|
4
4
|
const CSI_ESCAPED = "\\u009b";
|
|
@@ -61,77 +61,72 @@ function* tokenizer(input) {
|
|
|
61
61
|
if (i < input.length) {
|
|
62
62
|
const candidates = INTRODUCER_LOOKUP.get(input[i + 1]);
|
|
63
63
|
if (candidates) {
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
let matched = false;
|
|
65
|
+
for (const [seq, len] of candidates) if (i + len <= input.length && input.substring(i, i + len) === seq) {
|
|
66
|
+
matched = true;
|
|
67
|
+
if (seq === CSI_ESCAPED) {
|
|
66
68
|
yield emit({
|
|
67
69
|
type: TOKEN_TYPES.INTRODUCER,
|
|
68
70
|
pos: i,
|
|
69
|
-
raw:
|
|
71
|
+
raw: seq,
|
|
70
72
|
code: CSI
|
|
71
73
|
});
|
|
72
74
|
i += len;
|
|
73
75
|
setState("SEQUENCE", CSI);
|
|
74
76
|
} else {
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
+
const next = input[i + len];
|
|
78
|
+
if (next === CSI_OPEN) {
|
|
77
79
|
yield emit({
|
|
78
80
|
type: TOKEN_TYPES.INTRODUCER,
|
|
79
81
|
pos: i,
|
|
80
|
-
raw:
|
|
82
|
+
raw: seq + next,
|
|
81
83
|
code: CSI
|
|
82
84
|
});
|
|
83
85
|
i += len + 1;
|
|
84
86
|
setState("SEQUENCE", CSI);
|
|
85
|
-
} else if (
|
|
87
|
+
} else if (next === OSC_OPEN) {
|
|
86
88
|
yield emit({
|
|
87
89
|
type: TOKEN_TYPES.INTRODUCER,
|
|
88
90
|
pos: i,
|
|
89
|
-
raw:
|
|
91
|
+
raw: seq + next,
|
|
90
92
|
code: OSC
|
|
91
93
|
});
|
|
92
94
|
i += len + 1;
|
|
93
95
|
setState("SEQUENCE", OSC);
|
|
94
|
-
} else if (STRING_OPENERS.has(
|
|
96
|
+
} else if (STRING_OPENERS.has(next)) {
|
|
95
97
|
yield emit({
|
|
96
98
|
type: TOKEN_TYPES.INTRODUCER,
|
|
97
99
|
pos: i,
|
|
98
|
-
raw:
|
|
99
|
-
code:
|
|
100
|
+
raw: seq + next,
|
|
101
|
+
code: next
|
|
100
102
|
});
|
|
101
103
|
i += len + 1;
|
|
102
|
-
setState("SEQUENCE",
|
|
103
|
-
} else if (
|
|
104
|
+
setState("SEQUENCE", next);
|
|
105
|
+
} else if (next && next.charCodeAt(0) >= 32 && next.charCodeAt(0) <= 47) {
|
|
104
106
|
yield emit({
|
|
105
107
|
type: TOKEN_TYPES.INTRODUCER,
|
|
106
108
|
pos: i,
|
|
107
|
-
raw:
|
|
109
|
+
raw: seq + next,
|
|
108
110
|
code: ESC,
|
|
109
|
-
intermediate:
|
|
111
|
+
intermediate: next
|
|
110
112
|
});
|
|
111
113
|
i += len + 1;
|
|
112
114
|
setState("SEQUENCE", ESC);
|
|
113
|
-
} else if (
|
|
115
|
+
} else if (next) {
|
|
114
116
|
yield emit({
|
|
115
117
|
type: TOKEN_TYPES.INTRODUCER,
|
|
116
118
|
pos: i,
|
|
117
|
-
raw:
|
|
119
|
+
raw: seq,
|
|
118
120
|
code: ESC
|
|
119
121
|
});
|
|
120
122
|
i += len;
|
|
121
123
|
setState("SEQUENCE", ESC);
|
|
122
|
-
} else {
|
|
123
|
-
yield emit({
|
|
124
|
-
type: TOKEN_TYPES.INTRODUCER,
|
|
125
|
-
pos: i,
|
|
126
|
-
raw: sequence,
|
|
127
|
-
code: ESC
|
|
128
|
-
});
|
|
129
|
-
i += len;
|
|
130
124
|
}
|
|
131
125
|
}
|
|
132
126
|
break;
|
|
133
127
|
}
|
|
134
|
-
|
|
128
|
+
if (!matched) i++;
|
|
129
|
+
} else i++;
|
|
135
130
|
}
|
|
136
131
|
} else if (state === "SEQUENCE") {
|
|
137
132
|
let terminator = "";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { APC, APC_OPEN, BACKSLASH, BELL, CODE_TYPES, CSI, CSI_OPEN, DCS, DCS_OPEN, DEC_OPEN, ESC, OSC, OSC_OPEN, PM, PM_OPEN, PRIVATE_OPENERS, SOS, SOS_OPEN, ST, STRING_OPENERS, TOKEN_TYPES, parse, parser, tokenize, tokenizer } from "./parse-
|
|
1
|
+
import { APC, APC_OPEN, BACKSLASH, BELL, CODE_TYPES, CSI, CSI_OPEN, DCS, DCS_OPEN, DEC_OPEN, ESC, OSC, OSC_OPEN, PM, PM_OPEN, PRIVATE_OPENERS, SOS, SOS_OPEN, ST, STRING_OPENERS, TOKEN_TYPES, parse, parser, tokenize, tokenizer } from "./parse-DX-Po36R.js";
|
|
2
2
|
|
|
3
3
|
export { APC, APC_OPEN, BACKSLASH, BELL, CODE_TYPES, CSI, CSI_OPEN, DCS, DCS_OPEN, DEC_OPEN, ESC, OSC, OSC_OPEN, PM, PM_OPEN, PRIVATE_OPENERS, SOS, SOS_OPEN, ST, STRING_OPENERS, TOKEN_TYPES, parse, parser, tokenize, tokenizer };
|
|
@@ -47,7 +47,9 @@ const CODE_TYPES = {
|
|
|
47
47
|
|
|
48
48
|
//#endregion
|
|
49
49
|
//#region src/parsers/csi.ts
|
|
50
|
-
function parseCSI(
|
|
50
|
+
function parseCSI(introducer, dataTokens, final) {
|
|
51
|
+
const data = dataTokens.map((t) => t.raw).join("");
|
|
52
|
+
const raw = introducer.raw + data + final.raw;
|
|
51
53
|
const params = [];
|
|
52
54
|
let intermediates = "";
|
|
53
55
|
if (data) {
|
|
@@ -59,30 +61,28 @@ function parseCSI(pos, raw, data, final) {
|
|
|
59
61
|
}
|
|
60
62
|
intermediates = data.slice(i);
|
|
61
63
|
if (paramSection) {
|
|
62
|
-
|
|
63
|
-
for (
|
|
64
|
-
params.push(current || "-1");
|
|
65
|
-
current = "";
|
|
66
|
-
} else current += paramSection[j];
|
|
67
|
-
params.push(current || "-1");
|
|
64
|
+
const parts = paramSection.replace(/:/g, ";").split(";");
|
|
65
|
+
for (const part of parts) params.push(part || "-1");
|
|
68
66
|
}
|
|
69
67
|
}
|
|
70
|
-
const command = intermediates + final;
|
|
68
|
+
const command = intermediates + (final?.raw ?? "");
|
|
71
69
|
return {
|
|
72
70
|
type: CODE_TYPES.CSI,
|
|
73
|
-
pos,
|
|
71
|
+
pos: introducer.pos,
|
|
74
72
|
raw,
|
|
75
73
|
command,
|
|
76
74
|
params
|
|
77
75
|
};
|
|
78
76
|
}
|
|
79
|
-
function parsePrivateCSI(
|
|
80
|
-
const
|
|
77
|
+
function parsePrivateCSI(introducer, dataTokens, finalToken) {
|
|
78
|
+
const data = dataTokens.map((t) => t.raw).join("");
|
|
79
|
+
const raw = introducer.raw + data + (finalToken?.raw ?? "");
|
|
80
|
+
const privateIndicator = data[0] || "";
|
|
81
81
|
const withoutIndicator = data.slice(1);
|
|
82
|
-
const match = withoutIndicator.match(/^([\d
|
|
82
|
+
const match = withoutIndicator.match(/^([\d;:]*)(.*)/);
|
|
83
83
|
const paramsRaw = match?.[1] ?? "";
|
|
84
84
|
const intermediates = match?.[2] ?? "";
|
|
85
|
-
const command = `${privateIndicator}${intermediates}${
|
|
85
|
+
const command = `${privateIndicator}${intermediates}${finalToken.raw}`;
|
|
86
86
|
const params = [];
|
|
87
87
|
if (paramsRaw) {
|
|
88
88
|
let current = "";
|
|
@@ -94,7 +94,7 @@ function parsePrivateCSI(pos, raw, data, final) {
|
|
|
94
94
|
}
|
|
95
95
|
return {
|
|
96
96
|
type: CODE_TYPES.PRIVATE,
|
|
97
|
-
pos,
|
|
97
|
+
pos: introducer.pos,
|
|
98
98
|
raw,
|
|
99
99
|
command,
|
|
100
100
|
params
|
|
@@ -110,10 +110,12 @@ const DCS_PATTERNS = new Map([
|
|
|
110
110
|
["|", 1],
|
|
111
111
|
["{", 1]
|
|
112
112
|
]);
|
|
113
|
-
function parseDCS(
|
|
113
|
+
function parseDCS(introducer, dataTokens, final) {
|
|
114
|
+
const data = dataTokens.map((t) => t.raw).join("");
|
|
115
|
+
const raw = introducer.raw + data + (final?.raw ?? "");
|
|
114
116
|
if (!data) return {
|
|
115
117
|
type: CODE_TYPES.DCS,
|
|
116
|
-
pos,
|
|
118
|
+
pos: introducer.pos,
|
|
117
119
|
raw,
|
|
118
120
|
command: "",
|
|
119
121
|
params: []
|
|
@@ -131,7 +133,7 @@ function parseDCS(pos, raw, data) {
|
|
|
131
133
|
}
|
|
132
134
|
return {
|
|
133
135
|
type: CODE_TYPES.DCS,
|
|
134
|
-
pos,
|
|
136
|
+
pos: introducer.pos,
|
|
135
137
|
raw,
|
|
136
138
|
command: pattern,
|
|
137
139
|
params
|
|
@@ -139,7 +141,7 @@ function parseDCS(pos, raw, data) {
|
|
|
139
141
|
}
|
|
140
142
|
return {
|
|
141
143
|
type: CODE_TYPES.DCS,
|
|
142
|
-
pos,
|
|
144
|
+
pos: introducer.pos,
|
|
143
145
|
raw,
|
|
144
146
|
command: "",
|
|
145
147
|
params: [data]
|
|
@@ -148,15 +150,16 @@ function parseDCS(pos, raw, data) {
|
|
|
148
150
|
|
|
149
151
|
//#endregion
|
|
150
152
|
//#region src/parsers/dec.ts
|
|
151
|
-
function parseDEC(
|
|
152
|
-
const
|
|
153
|
+
function parseDEC(introducer, dataTokens, final) {
|
|
154
|
+
const data = dataTokens.map((t) => t.raw).join("");
|
|
155
|
+
const raw = introducer.raw + data + final.raw;
|
|
153
156
|
let i = 0;
|
|
154
157
|
let paramsRaw = "";
|
|
155
|
-
while (i <
|
|
156
|
-
paramsRaw +=
|
|
158
|
+
while (i < data.length && data.charCodeAt(i) >= 48 && data.charCodeAt(i) <= 63) {
|
|
159
|
+
paramsRaw += data[i];
|
|
157
160
|
i++;
|
|
158
161
|
}
|
|
159
|
-
const command =
|
|
162
|
+
const command = data.slice(i) + final.raw;
|
|
160
163
|
const params = [];
|
|
161
164
|
if (paramsRaw) {
|
|
162
165
|
let current = "";
|
|
@@ -168,7 +171,7 @@ function parseDEC(pos, raw, data, final) {
|
|
|
168
171
|
}
|
|
169
172
|
return {
|
|
170
173
|
type: CODE_TYPES.DEC,
|
|
171
|
-
pos,
|
|
174
|
+
pos: introducer.pos,
|
|
172
175
|
raw,
|
|
173
176
|
command,
|
|
174
177
|
params
|
|
@@ -177,30 +180,29 @@ function parseDEC(pos, raw, data, final) {
|
|
|
177
180
|
|
|
178
181
|
//#endregion
|
|
179
182
|
//#region src/parsers/esc.ts
|
|
180
|
-
function parseESC(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
command: token.intermediate,
|
|
186
|
-
params: command ? [command] : []
|
|
187
|
-
};
|
|
183
|
+
function parseESC(introducer, dataTokens, final) {
|
|
184
|
+
const data = dataTokens.map((t) => t.raw).join("");
|
|
185
|
+
const command = introducer.intermediate || (dataTokens[0]?.raw ?? final?.raw);
|
|
186
|
+
const params = introducer.intermediate ? final?.raw ? [final.raw] : [] : [];
|
|
187
|
+
const raw = introducer.raw + data + (final?.raw ?? "");
|
|
188
188
|
return {
|
|
189
189
|
type: CODE_TYPES.ESC,
|
|
190
|
-
pos:
|
|
190
|
+
pos: introducer.pos,
|
|
191
191
|
raw,
|
|
192
192
|
command,
|
|
193
|
-
params
|
|
193
|
+
params
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
//#endregion
|
|
198
198
|
//#region src/parsers/osc.ts
|
|
199
|
-
function parseOSC(
|
|
199
|
+
function parseOSC(introducer, dataTokens, final) {
|
|
200
|
+
const data = dataTokens.map((t) => t.raw).join("");
|
|
201
|
+
const raw = introducer.raw + data + final.raw;
|
|
200
202
|
const semicolonIndex = data.indexOf(";");
|
|
201
203
|
if (semicolonIndex === -1) return {
|
|
202
204
|
type: CODE_TYPES.OSC,
|
|
203
|
-
pos,
|
|
205
|
+
pos: introducer.pos,
|
|
204
206
|
raw,
|
|
205
207
|
command: data,
|
|
206
208
|
params: []
|
|
@@ -209,7 +211,7 @@ function parseOSC(pos, raw, data) {
|
|
|
209
211
|
const remainder = data.slice(semicolonIndex + 1);
|
|
210
212
|
if (command === "1337") return {
|
|
211
213
|
type: CODE_TYPES.OSC,
|
|
212
|
-
pos,
|
|
214
|
+
pos: introducer.pos,
|
|
213
215
|
raw,
|
|
214
216
|
command,
|
|
215
217
|
params: [remainder]
|
|
@@ -225,13 +227,55 @@ function parseOSC(pos, raw, data) {
|
|
|
225
227
|
}
|
|
226
228
|
return {
|
|
227
229
|
type: CODE_TYPES.OSC,
|
|
228
|
-
pos,
|
|
230
|
+
pos: introducer.pos,
|
|
229
231
|
raw,
|
|
230
232
|
command,
|
|
231
233
|
params
|
|
232
234
|
};
|
|
233
235
|
}
|
|
234
236
|
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/parsers/apc.ts
|
|
239
|
+
function parseAPC(introducer, dataTokens, final) {
|
|
240
|
+
const data = dataTokens.map((t) => t.raw).join("");
|
|
241
|
+
const raw = introducer.raw + data + final.raw;
|
|
242
|
+
return {
|
|
243
|
+
type: CODE_TYPES.STRING,
|
|
244
|
+
pos: introducer.pos,
|
|
245
|
+
raw,
|
|
246
|
+
command: "APC",
|
|
247
|
+
params: data ? [data] : []
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/parsers/pm.ts
|
|
253
|
+
function parsePM(introducer, dataTokens, final) {
|
|
254
|
+
const data = dataTokens.map((t) => t.raw).join("");
|
|
255
|
+
const raw = introducer.raw + data + final.raw;
|
|
256
|
+
return {
|
|
257
|
+
type: CODE_TYPES.STRING,
|
|
258
|
+
pos: introducer.pos,
|
|
259
|
+
raw,
|
|
260
|
+
command: "PM",
|
|
261
|
+
params: data ? [data] : []
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/parsers/sos.ts
|
|
267
|
+
function parseSOS(introducer, dataTokens, final) {
|
|
268
|
+
const data = dataTokens.map((t) => t.raw).join("");
|
|
269
|
+
const raw = introducer.raw + data + final.raw;
|
|
270
|
+
return {
|
|
271
|
+
type: CODE_TYPES.STRING,
|
|
272
|
+
pos: introducer.pos,
|
|
273
|
+
raw,
|
|
274
|
+
command: "SOS",
|
|
275
|
+
params: data ? [data] : []
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
235
279
|
//#endregion
|
|
236
280
|
//#region src/tokenize.ts
|
|
237
281
|
const INTRODUCERS = new Set([
|
|
@@ -317,15 +361,6 @@ function* tokenizer(input) {
|
|
|
317
361
|
i += 2;
|
|
318
362
|
setState("SEQUENCE", ESC);
|
|
319
363
|
} else if (next) {
|
|
320
|
-
yield emit$1({
|
|
321
|
-
type: TOKEN_TYPES.INTRODUCER,
|
|
322
|
-
pos: i,
|
|
323
|
-
raw: char,
|
|
324
|
-
code: ESC
|
|
325
|
-
});
|
|
326
|
-
i += 1;
|
|
327
|
-
setState("SEQUENCE", ESC);
|
|
328
|
-
} else {
|
|
329
364
|
yield emit$1({
|
|
330
365
|
type: TOKEN_TYPES.INTRODUCER,
|
|
331
366
|
pos: i,
|
|
@@ -333,6 +368,7 @@ function* tokenizer(input) {
|
|
|
333
368
|
code: ESC
|
|
334
369
|
});
|
|
335
370
|
i++;
|
|
371
|
+
setState("SEQUENCE", ESC);
|
|
336
372
|
}
|
|
337
373
|
}
|
|
338
374
|
}
|
|
@@ -419,70 +455,50 @@ function* parser(tokens) {
|
|
|
419
455
|
continue;
|
|
420
456
|
}
|
|
421
457
|
if (token.type === TOKEN_TYPES.INTRODUCER) {
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
let
|
|
425
|
-
let finalToken;
|
|
458
|
+
const introducer = token;
|
|
459
|
+
const data = [];
|
|
460
|
+
let final;
|
|
426
461
|
current = tokens.next();
|
|
427
|
-
while (!current.done
|
|
462
|
+
while (!current.done) {
|
|
428
463
|
const nextToken = current.value;
|
|
429
|
-
if (nextToken.type === TOKEN_TYPES.DATA)
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
raw += nextToken.raw;
|
|
464
|
+
if (nextToken.type === TOKEN_TYPES.DATA) data.push(nextToken);
|
|
465
|
+
else if (nextToken.type === TOKEN_TYPES.FINAL) {
|
|
466
|
+
final = nextToken;
|
|
467
|
+
current = tokens.next();
|
|
468
|
+
break;
|
|
435
469
|
}
|
|
436
470
|
current = tokens.next();
|
|
437
471
|
}
|
|
438
|
-
if (
|
|
472
|
+
if (final) switch (introducer.code) {
|
|
439
473
|
case CSI:
|
|
440
|
-
if (data.startsWith(DEC_OPEN)) yield emit(parseDEC(
|
|
441
|
-
else if (PRIVATE_OPENERS.has(data[0])) yield emit(parsePrivateCSI(
|
|
442
|
-
else yield emit(parseCSI(
|
|
474
|
+
if (data[0]?.raw.startsWith(DEC_OPEN)) yield emit(parseDEC(introducer, data, final));
|
|
475
|
+
else if (PRIVATE_OPENERS.has(data[0]?.raw)) yield emit(parsePrivateCSI(introducer, data, final));
|
|
476
|
+
else yield emit(parseCSI(introducer, data, final));
|
|
443
477
|
break;
|
|
444
478
|
case OSC:
|
|
445
|
-
yield emit(parseOSC(
|
|
479
|
+
yield emit(parseOSC(introducer, data, final));
|
|
446
480
|
break;
|
|
447
481
|
case DCS:
|
|
448
482
|
case DCS_OPEN:
|
|
449
|
-
yield emit(parseDCS(
|
|
483
|
+
yield emit(parseDCS(introducer, data, final));
|
|
450
484
|
break;
|
|
451
485
|
case APC:
|
|
452
486
|
case APC_OPEN:
|
|
453
|
-
yield emit(
|
|
454
|
-
type: CODE_TYPES.STRING,
|
|
455
|
-
pos,
|
|
456
|
-
raw,
|
|
457
|
-
command: "APC",
|
|
458
|
-
params: data ? [data] : []
|
|
459
|
-
});
|
|
487
|
+
yield emit(parseAPC(introducer, data, final));
|
|
460
488
|
break;
|
|
461
489
|
case PM:
|
|
462
490
|
case PM_OPEN:
|
|
463
|
-
yield emit(
|
|
464
|
-
type: CODE_TYPES.STRING,
|
|
465
|
-
pos,
|
|
466
|
-
raw,
|
|
467
|
-
command: "PM",
|
|
468
|
-
params: data ? [data] : []
|
|
469
|
-
});
|
|
491
|
+
yield emit(parsePM(introducer, data, final));
|
|
470
492
|
break;
|
|
471
493
|
case SOS:
|
|
472
494
|
case SOS_OPEN:
|
|
473
|
-
yield emit(
|
|
474
|
-
type: CODE_TYPES.STRING,
|
|
475
|
-
pos,
|
|
476
|
-
raw,
|
|
477
|
-
command: "SOS",
|
|
478
|
-
params: data ? [data] : []
|
|
479
|
-
});
|
|
495
|
+
yield emit(parseSOS(introducer, data, final));
|
|
480
496
|
break;
|
|
481
497
|
case ESC:
|
|
482
|
-
yield emit(parseESC(
|
|
498
|
+
yield emit(parseESC(introducer, data, final));
|
|
483
499
|
break;
|
|
484
500
|
}
|
|
485
|
-
else if (
|
|
501
|
+
else if (introducer.code === ESC) yield emit(parseESC(introducer, data, void 0));
|
|
486
502
|
} else current = tokens.next();
|
|
487
503
|
}
|
|
488
504
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ansi-tools/parser",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Tokenize and parse strings containing ANSI escape sequences and control codes",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -19,6 +19,13 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"prebuild": "pnpm type-check && pnpm test",
|
|
24
|
+
"build": "tsdown --dts src/index.ts src/escaped.ts",
|
|
25
|
+
"test": "node --test",
|
|
26
|
+
"type-check": "tsc",
|
|
27
|
+
"prepack": "pnpm build"
|
|
28
|
+
},
|
|
22
29
|
"keywords": [
|
|
23
30
|
"ansi",
|
|
24
31
|
"escape codes",
|
|
@@ -29,15 +36,16 @@
|
|
|
29
36
|
"publishConfig": {
|
|
30
37
|
"access": "public"
|
|
31
38
|
},
|
|
39
|
+
"homepage": "https://github.com/webpro/ANSI.tools/tree/main/packages/parser",
|
|
40
|
+
"bugs": "https://github.com/webpro/ANSI.tools/issues",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "github:webpro/ANSI.tools",
|
|
44
|
+
"directory": "packages/parser"
|
|
45
|
+
},
|
|
32
46
|
"devDependencies": {
|
|
33
47
|
"@types/node": "^24.0.13",
|
|
34
48
|
"tsdown": "^0.12.9",
|
|
35
49
|
"typescript": "^5.8.3"
|
|
36
|
-
},
|
|
37
|
-
"scripts": {
|
|
38
|
-
"prebuild": "pnpm type-check && pnpm test",
|
|
39
|
-
"build": "tsdown --dts src/index.ts src/escaped.ts",
|
|
40
|
-
"test": "node --test",
|
|
41
|
-
"type-check": "tsc"
|
|
42
50
|
}
|
|
43
|
-
}
|
|
51
|
+
}
|