@optique/core 0.10.3 → 0.10.4-dev.410
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/dist/message.cjs +104 -95
- package/dist/message.js +104 -95
- package/package.json +1 -1
package/dist/message.cjs
CHANGED
|
@@ -253,115 +253,124 @@ function formatMessage(msg, options = {}) {
|
|
|
253
253
|
const resetSequence = `\x1b[0m${resetSuffix}`;
|
|
254
254
|
function* stream() {
|
|
255
255
|
const wordPattern = /\s*\S+\s*/g;
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
256
|
+
let prevWasLineBreak = false;
|
|
257
|
+
for (const term of msg) {
|
|
258
|
+
const isAfterLineBreak = prevWasLineBreak;
|
|
259
|
+
prevWasLineBreak = false;
|
|
260
|
+
if (term.type === "text") {
|
|
261
|
+
const rawText = isAfterLineBreak ? term.text.replace(/^\n(?!\n)/, "") : term.text;
|
|
262
|
+
if (rawText.includes("\n\n")) {
|
|
263
|
+
const paragraphs = rawText.split(/\n\n+/);
|
|
264
|
+
for (let paragraphIndex = 0; paragraphIndex < paragraphs.length; paragraphIndex++) {
|
|
265
|
+
if (paragraphIndex > 0) yield {
|
|
266
|
+
text: "\n",
|
|
267
|
+
width: -1
|
|
268
|
+
};
|
|
269
|
+
const paragraph = paragraphs[paragraphIndex].replace(/\n/g, " ");
|
|
270
|
+
wordPattern.lastIndex = 0;
|
|
271
|
+
while (true) {
|
|
272
|
+
const match = wordPattern.exec(paragraph);
|
|
273
|
+
if (match == null) break;
|
|
274
|
+
yield {
|
|
275
|
+
text: match[0],
|
|
276
|
+
width: match[0].length
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
const normalizedText = rawText.replace(/\n/g, " ");
|
|
282
|
+
if (normalizedText.trim() === "" && normalizedText.length > 0) yield {
|
|
283
|
+
text: " ",
|
|
284
|
+
width: 1
|
|
271
285
|
};
|
|
286
|
+
else {
|
|
287
|
+
wordPattern.lastIndex = 0;
|
|
288
|
+
while (true) {
|
|
289
|
+
const match = wordPattern.exec(normalizedText);
|
|
290
|
+
if (match == null) break;
|
|
291
|
+
yield {
|
|
292
|
+
text: match[0],
|
|
293
|
+
width: match[0].length
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}
|
|
272
297
|
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
298
|
+
} else if (term.type === "optionName") {
|
|
299
|
+
const name = useQuotes ? `\`${term.optionName}\`` : term.optionName;
|
|
300
|
+
yield {
|
|
301
|
+
text: useColors ? `\x1b[3m${name}${resetSequence}` : name,
|
|
302
|
+
width: name.length
|
|
303
|
+
};
|
|
304
|
+
} else if (term.type === "optionNames") {
|
|
305
|
+
const names = term.optionNames.map((name) => useQuotes ? `\`${name}\`` : name);
|
|
306
|
+
let i = 0;
|
|
307
|
+
for (const name of names) {
|
|
308
|
+
if (i > 0) yield {
|
|
309
|
+
text: "/",
|
|
310
|
+
width: 1
|
|
311
|
+
};
|
|
285
312
|
yield {
|
|
286
|
-
text:
|
|
287
|
-
width:
|
|
313
|
+
text: useColors ? `\x1b[3m${name}${resetSequence}` : name,
|
|
314
|
+
width: name.length
|
|
288
315
|
};
|
|
316
|
+
i++;
|
|
289
317
|
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
318
|
+
} else if (term.type === "metavar") {
|
|
319
|
+
const metavar$1 = useQuotes ? `\`${term.metavar}\`` : term.metavar;
|
|
320
|
+
yield {
|
|
321
|
+
text: useColors ? `\x1b[1m${metavar$1}${resetSequence}` : metavar$1,
|
|
322
|
+
width: metavar$1.length
|
|
323
|
+
};
|
|
324
|
+
} else if (term.type === "value") {
|
|
325
|
+
const value$1 = useQuotes ? `${JSON.stringify(term.value)}` : term.value;
|
|
326
|
+
yield {
|
|
327
|
+
text: useColors ? `\x1b[32m${value$1}${resetSequence}` : value$1,
|
|
328
|
+
width: value$1.length
|
|
329
|
+
};
|
|
330
|
+
} else if (term.type === "values") for (let i = 0; i < term.values.length; i++) {
|
|
302
331
|
if (i > 0) yield {
|
|
303
|
-
text: "
|
|
332
|
+
text: " ",
|
|
304
333
|
width: 1
|
|
305
334
|
};
|
|
335
|
+
const value$1 = useQuotes ? JSON.stringify(term.values[i]) : term.values[i];
|
|
306
336
|
yield {
|
|
307
|
-
text: useColors ? `\x1b[
|
|
308
|
-
width:
|
|
337
|
+
text: useColors ? i <= 0 ? `\x1b[32m${value$1}` : i + 1 >= term.values.length ? `${value$1}${resetSequence}` : value$1 : value$1,
|
|
338
|
+
width: value$1.length
|
|
309
339
|
};
|
|
310
|
-
i++;
|
|
311
340
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if (i > 0) yield {
|
|
326
|
-
text: " ",
|
|
327
|
-
width: 1
|
|
328
|
-
};
|
|
329
|
-
const value$1 = useQuotes ? JSON.stringify(term.values[i]) : term.values[i];
|
|
330
|
-
yield {
|
|
331
|
-
text: useColors ? i <= 0 ? `\x1b[32m${value$1}` : i + 1 >= term.values.length ? `${value$1}${resetSequence}` : value$1 : value$1,
|
|
332
|
-
width: value$1.length
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
else if (term.type === "envVar") {
|
|
336
|
-
const envVar$1 = useQuotes ? `\`${term.envVar}\`` : term.envVar;
|
|
337
|
-
yield {
|
|
338
|
-
text: useColors ? `\x1b[1;4m${envVar$1}${resetSequence}` : envVar$1,
|
|
339
|
-
width: envVar$1.length
|
|
340
|
-
};
|
|
341
|
-
} else if (term.type === "commandLine") {
|
|
342
|
-
const cmd = useQuotes ? `\`${term.commandLine}\`` : term.commandLine;
|
|
343
|
-
yield {
|
|
344
|
-
text: useColors ? `\x1b[36m${cmd}${resetSequence}` : cmd,
|
|
345
|
-
width: cmd.length
|
|
346
|
-
};
|
|
347
|
-
} else if (term.type === "lineBreak") yield {
|
|
348
|
-
text: "\n",
|
|
349
|
-
width: -1
|
|
350
|
-
};
|
|
351
|
-
else if (term.type === "url") {
|
|
352
|
-
const urlString = term.url.href;
|
|
353
|
-
const displayText = useQuotes ? `<${urlString}>` : urlString;
|
|
354
|
-
if (useColors) {
|
|
355
|
-
const hyperlink = `\x1b]8;;${urlString}\x1b\\${displayText}\x1b]8;;\x1b\\${resetSuffix}`;
|
|
341
|
+
else if (term.type === "envVar") {
|
|
342
|
+
const envVar$1 = useQuotes ? `\`${term.envVar}\`` : term.envVar;
|
|
343
|
+
yield {
|
|
344
|
+
text: useColors ? `\x1b[1;4m${envVar$1}${resetSequence}` : envVar$1,
|
|
345
|
+
width: envVar$1.length
|
|
346
|
+
};
|
|
347
|
+
} else if (term.type === "commandLine") {
|
|
348
|
+
const cmd = useQuotes ? `\`${term.commandLine}\`` : term.commandLine;
|
|
349
|
+
yield {
|
|
350
|
+
text: useColors ? `\x1b[36m${cmd}${resetSequence}` : cmd,
|
|
351
|
+
width: cmd.length
|
|
352
|
+
};
|
|
353
|
+
} else if (term.type === "lineBreak") {
|
|
356
354
|
yield {
|
|
357
|
-
text:
|
|
355
|
+
text: "\n",
|
|
356
|
+
width: -1
|
|
357
|
+
};
|
|
358
|
+
prevWasLineBreak = true;
|
|
359
|
+
} else if (term.type === "url") {
|
|
360
|
+
const urlString = term.url.href;
|
|
361
|
+
const displayText = useQuotes ? `<${urlString}>` : urlString;
|
|
362
|
+
if (useColors) {
|
|
363
|
+
const hyperlink = `\x1b]8;;${urlString}\x1b\\${displayText}\x1b]8;;\x1b\\${resetSuffix}`;
|
|
364
|
+
yield {
|
|
365
|
+
text: hyperlink,
|
|
366
|
+
width: displayText.length
|
|
367
|
+
};
|
|
368
|
+
} else yield {
|
|
369
|
+
text: displayText,
|
|
358
370
|
width: displayText.length
|
|
359
371
|
};
|
|
360
|
-
} else
|
|
361
|
-
|
|
362
|
-
width: displayText.length
|
|
363
|
-
};
|
|
364
|
-
} else throw new TypeError(`Invalid MessageTerm type: ${term["type"]}.`);
|
|
372
|
+
} else throw new TypeError(`Invalid MessageTerm type: ${term["type"]}.`);
|
|
373
|
+
}
|
|
365
374
|
}
|
|
366
375
|
let output = "";
|
|
367
376
|
let totalWidth = 0;
|
package/dist/message.js
CHANGED
|
@@ -252,115 +252,124 @@ function formatMessage(msg, options = {}) {
|
|
|
252
252
|
const resetSequence = `\x1b[0m${resetSuffix}`;
|
|
253
253
|
function* stream() {
|
|
254
254
|
const wordPattern = /\s*\S+\s*/g;
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
255
|
+
let prevWasLineBreak = false;
|
|
256
|
+
for (const term of msg) {
|
|
257
|
+
const isAfterLineBreak = prevWasLineBreak;
|
|
258
|
+
prevWasLineBreak = false;
|
|
259
|
+
if (term.type === "text") {
|
|
260
|
+
const rawText = isAfterLineBreak ? term.text.replace(/^\n(?!\n)/, "") : term.text;
|
|
261
|
+
if (rawText.includes("\n\n")) {
|
|
262
|
+
const paragraphs = rawText.split(/\n\n+/);
|
|
263
|
+
for (let paragraphIndex = 0; paragraphIndex < paragraphs.length; paragraphIndex++) {
|
|
264
|
+
if (paragraphIndex > 0) yield {
|
|
265
|
+
text: "\n",
|
|
266
|
+
width: -1
|
|
267
|
+
};
|
|
268
|
+
const paragraph = paragraphs[paragraphIndex].replace(/\n/g, " ");
|
|
269
|
+
wordPattern.lastIndex = 0;
|
|
270
|
+
while (true) {
|
|
271
|
+
const match = wordPattern.exec(paragraph);
|
|
272
|
+
if (match == null) break;
|
|
273
|
+
yield {
|
|
274
|
+
text: match[0],
|
|
275
|
+
width: match[0].length
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
} else {
|
|
280
|
+
const normalizedText = rawText.replace(/\n/g, " ");
|
|
281
|
+
if (normalizedText.trim() === "" && normalizedText.length > 0) yield {
|
|
282
|
+
text: " ",
|
|
283
|
+
width: 1
|
|
270
284
|
};
|
|
285
|
+
else {
|
|
286
|
+
wordPattern.lastIndex = 0;
|
|
287
|
+
while (true) {
|
|
288
|
+
const match = wordPattern.exec(normalizedText);
|
|
289
|
+
if (match == null) break;
|
|
290
|
+
yield {
|
|
291
|
+
text: match[0],
|
|
292
|
+
width: match[0].length
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
271
296
|
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
297
|
+
} else if (term.type === "optionName") {
|
|
298
|
+
const name = useQuotes ? `\`${term.optionName}\`` : term.optionName;
|
|
299
|
+
yield {
|
|
300
|
+
text: useColors ? `\x1b[3m${name}${resetSequence}` : name,
|
|
301
|
+
width: name.length
|
|
302
|
+
};
|
|
303
|
+
} else if (term.type === "optionNames") {
|
|
304
|
+
const names = term.optionNames.map((name) => useQuotes ? `\`${name}\`` : name);
|
|
305
|
+
let i = 0;
|
|
306
|
+
for (const name of names) {
|
|
307
|
+
if (i > 0) yield {
|
|
308
|
+
text: "/",
|
|
309
|
+
width: 1
|
|
310
|
+
};
|
|
284
311
|
yield {
|
|
285
|
-
text:
|
|
286
|
-
width:
|
|
312
|
+
text: useColors ? `\x1b[3m${name}${resetSequence}` : name,
|
|
313
|
+
width: name.length
|
|
287
314
|
};
|
|
315
|
+
i++;
|
|
288
316
|
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
317
|
+
} else if (term.type === "metavar") {
|
|
318
|
+
const metavar$1 = useQuotes ? `\`${term.metavar}\`` : term.metavar;
|
|
319
|
+
yield {
|
|
320
|
+
text: useColors ? `\x1b[1m${metavar$1}${resetSequence}` : metavar$1,
|
|
321
|
+
width: metavar$1.length
|
|
322
|
+
};
|
|
323
|
+
} else if (term.type === "value") {
|
|
324
|
+
const value$1 = useQuotes ? `${JSON.stringify(term.value)}` : term.value;
|
|
325
|
+
yield {
|
|
326
|
+
text: useColors ? `\x1b[32m${value$1}${resetSequence}` : value$1,
|
|
327
|
+
width: value$1.length
|
|
328
|
+
};
|
|
329
|
+
} else if (term.type === "values") for (let i = 0; i < term.values.length; i++) {
|
|
301
330
|
if (i > 0) yield {
|
|
302
|
-
text: "
|
|
331
|
+
text: " ",
|
|
303
332
|
width: 1
|
|
304
333
|
};
|
|
334
|
+
const value$1 = useQuotes ? JSON.stringify(term.values[i]) : term.values[i];
|
|
305
335
|
yield {
|
|
306
|
-
text: useColors ? `\x1b[
|
|
307
|
-
width:
|
|
336
|
+
text: useColors ? i <= 0 ? `\x1b[32m${value$1}` : i + 1 >= term.values.length ? `${value$1}${resetSequence}` : value$1 : value$1,
|
|
337
|
+
width: value$1.length
|
|
308
338
|
};
|
|
309
|
-
i++;
|
|
310
339
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if (i > 0) yield {
|
|
325
|
-
text: " ",
|
|
326
|
-
width: 1
|
|
327
|
-
};
|
|
328
|
-
const value$1 = useQuotes ? JSON.stringify(term.values[i]) : term.values[i];
|
|
329
|
-
yield {
|
|
330
|
-
text: useColors ? i <= 0 ? `\x1b[32m${value$1}` : i + 1 >= term.values.length ? `${value$1}${resetSequence}` : value$1 : value$1,
|
|
331
|
-
width: value$1.length
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
else if (term.type === "envVar") {
|
|
335
|
-
const envVar$1 = useQuotes ? `\`${term.envVar}\`` : term.envVar;
|
|
336
|
-
yield {
|
|
337
|
-
text: useColors ? `\x1b[1;4m${envVar$1}${resetSequence}` : envVar$1,
|
|
338
|
-
width: envVar$1.length
|
|
339
|
-
};
|
|
340
|
-
} else if (term.type === "commandLine") {
|
|
341
|
-
const cmd = useQuotes ? `\`${term.commandLine}\`` : term.commandLine;
|
|
342
|
-
yield {
|
|
343
|
-
text: useColors ? `\x1b[36m${cmd}${resetSequence}` : cmd,
|
|
344
|
-
width: cmd.length
|
|
345
|
-
};
|
|
346
|
-
} else if (term.type === "lineBreak") yield {
|
|
347
|
-
text: "\n",
|
|
348
|
-
width: -1
|
|
349
|
-
};
|
|
350
|
-
else if (term.type === "url") {
|
|
351
|
-
const urlString = term.url.href;
|
|
352
|
-
const displayText = useQuotes ? `<${urlString}>` : urlString;
|
|
353
|
-
if (useColors) {
|
|
354
|
-
const hyperlink = `\x1b]8;;${urlString}\x1b\\${displayText}\x1b]8;;\x1b\\${resetSuffix}`;
|
|
340
|
+
else if (term.type === "envVar") {
|
|
341
|
+
const envVar$1 = useQuotes ? `\`${term.envVar}\`` : term.envVar;
|
|
342
|
+
yield {
|
|
343
|
+
text: useColors ? `\x1b[1;4m${envVar$1}${resetSequence}` : envVar$1,
|
|
344
|
+
width: envVar$1.length
|
|
345
|
+
};
|
|
346
|
+
} else if (term.type === "commandLine") {
|
|
347
|
+
const cmd = useQuotes ? `\`${term.commandLine}\`` : term.commandLine;
|
|
348
|
+
yield {
|
|
349
|
+
text: useColors ? `\x1b[36m${cmd}${resetSequence}` : cmd,
|
|
350
|
+
width: cmd.length
|
|
351
|
+
};
|
|
352
|
+
} else if (term.type === "lineBreak") {
|
|
355
353
|
yield {
|
|
356
|
-
text:
|
|
354
|
+
text: "\n",
|
|
355
|
+
width: -1
|
|
356
|
+
};
|
|
357
|
+
prevWasLineBreak = true;
|
|
358
|
+
} else if (term.type === "url") {
|
|
359
|
+
const urlString = term.url.href;
|
|
360
|
+
const displayText = useQuotes ? `<${urlString}>` : urlString;
|
|
361
|
+
if (useColors) {
|
|
362
|
+
const hyperlink = `\x1b]8;;${urlString}\x1b\\${displayText}\x1b]8;;\x1b\\${resetSuffix}`;
|
|
363
|
+
yield {
|
|
364
|
+
text: hyperlink,
|
|
365
|
+
width: displayText.length
|
|
366
|
+
};
|
|
367
|
+
} else yield {
|
|
368
|
+
text: displayText,
|
|
357
369
|
width: displayText.length
|
|
358
370
|
};
|
|
359
|
-
} else
|
|
360
|
-
|
|
361
|
-
width: displayText.length
|
|
362
|
-
};
|
|
363
|
-
} else throw new TypeError(`Invalid MessageTerm type: ${term["type"]}.`);
|
|
371
|
+
} else throw new TypeError(`Invalid MessageTerm type: ${term["type"]}.`);
|
|
372
|
+
}
|
|
364
373
|
}
|
|
365
374
|
let output = "";
|
|
366
375
|
let totalWidth = 0;
|