@softwarefactory-project/re-ansi 0.4.0 → 0.5.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 CHANGED
@@ -7,9 +7,11 @@ Ansi code to HTML
7
7
  re-ansi supports:
8
8
 
9
9
  * Cursor movement: `\n`, line erase and `\r` line erase
10
- * SGR parameter: italic and bold
10
+ * SGR parameter: italic, bold, underline and line-through
11
11
  * 3/4 bits [color code][ansi-color-code]
12
12
 
13
+ re-ansi removes styles on new lines, so that a `<br />` can't be nested inside `<span style>` elements.
14
+
13
15
  For details, see the `AnsiCode.parse` function.
14
16
 
15
17
  ## Install
@@ -79,27 +81,32 @@ Make sure to read about [React][reason-react] and [Reason][rescript-lang] too.
79
81
 
80
82
  ## Changes
81
83
 
84
+ ### 0.5.0
85
+
86
+ - Add support for `[m` and `[K`.
87
+
82
88
  ### 0.4.0
83
89
 
84
- - Add support for underline and line-through text decoration
85
- - Add support for lighter font style
90
+ - Add support for underline and line-through text decoration.
91
+ - Add support for lighter font style.
92
+ - Add initial support for color reset.
86
93
 
87
94
  ### 0.3.0
88
95
 
89
- - Add unique keys to react list elements
90
- - Create a href elements for http links
96
+ - Add unique keys to react list elements.
97
+ - Create a href elements for http links.
91
98
 
92
99
  ### 0.2.1
93
100
 
94
- - Fix Ansi.parse to return the full document instead of the last line
101
+ - Fix Ansi.parse to return the full document instead of the last line.
95
102
 
96
103
  ### 0.2.0
97
104
 
98
- - Fix a recursion limit in Ansi.parse for log bigger than 10MB
105
+ - Fix a recursion limit in Ansi.parse for log bigger than 10MB.
99
106
 
100
107
  ### 0.1.3
101
108
 
102
- - Initial release
109
+ - Initial release.
103
110
 
104
111
  [ansi-color-code]: https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
105
112
  [reason-react]: https://reasonml.github.io/reason-react/docs/en/components
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwarefactory-project/re-ansi",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "ANSI code to HTML",
5
5
  "files": ["README.md", "LICENSE", "bsconfig.json", "src"],
6
6
  "main": "./src/Ansi.bs.js",
package/src/Ansi.bs.js CHANGED
@@ -105,16 +105,16 @@ function getColorStyle(colorMode, colorValue) {
105
105
  }
106
106
 
107
107
  function getColorStyleCss(color) {
108
- if (color.TAG === /* Foreground */0) {
109
- return Belt_Option.flatMap(fourBitColors(color._0), (function (color) {
108
+ if (color.TAG) {
109
+ return Belt_Option.flatMap(fourBitColors(color._0), (function (background) {
110
110
  return {
111
- color: color
111
+ background: background
112
112
  };
113
113
  }));
114
114
  } else {
115
- return Belt_Option.flatMap(fourBitColors(color._0), (function (background) {
115
+ return Belt_Option.flatMap(fourBitColors(color._0), (function (color) {
116
116
  return {
117
- background: background
117
+ color: color
118
118
  };
119
119
  }));
120
120
  }
@@ -296,138 +296,154 @@ function parse(txt, pos) {
296
296
  var match$2 = codePoints.tl;
297
297
  if (!match$2) {
298
298
  return [
299
- 1,
300
- undefined
299
+ length,
300
+ /* Clear */0
301
301
  ];
302
302
  }
303
303
  var style$2 = match$2.hd;
304
304
  var exit$2 = 0;
305
- if (style$2 !== 48) {
306
- if (style$2 !== 49) {
307
- exit$2 = 5;
308
- } else {
309
- var match$3 = match$2.tl;
310
- if (match$3) {
311
- var match$4 = match$3.tl;
312
- if (match$4 && !match$4.tl) {
313
- colorMode = match$3.hd;
314
- colorValue = match$4.hd;
315
- xs = codePoints;
316
- exit$1 = 2;
305
+ var exit$3 = 0;
306
+ var match$3 = match$2.tl;
307
+ if (match$3) {
308
+ if (match$3.hd === 75) {
309
+ return [
310
+ 4,
311
+ /* EraseLine */1
312
+ ];
313
+ }
314
+ exit$3 = 6;
315
+ } else {
316
+ exit$3 = 6;
317
+ }
318
+ if (exit$3 === 6) {
319
+ var switcher = style$2 - 48 | 0;
320
+ if (switcher === 0 || switcher === 1) {
321
+ if (switcher !== 0) {
322
+ var match$4 = match$2.tl;
323
+ if (match$4) {
324
+ var match$5 = match$4.tl;
325
+ if (match$5 && !match$5.tl) {
326
+ colorMode = match$4.hd;
327
+ colorValue = match$5.hd;
328
+ xs = codePoints;
329
+ exit$1 = 2;
330
+ } else {
331
+ exit$2 = 5;
332
+ }
317
333
  } else {
318
334
  exit$2 = 5;
319
335
  }
320
336
  } else {
321
- exit$2 = 5;
322
- }
323
- }
324
- } else {
325
- var match$5 = match$2.tl;
326
- if (!match$5) {
327
- return [
328
- length,
329
- /* Clear */0
330
- ];
331
- }
332
- var style$3 = match$5.hd;
333
- var exit$3 = 0;
334
- if (style$3 !== 48) {
335
- if (style$3 === 75) {
336
- return [
337
- 4,
338
- /* EraseLine */1
339
- ];
340
- }
341
- exit$3 = 6;
342
- } else {
343
- if (!match$5.tl) {
344
- return [
345
- length,
346
- /* Clear */0
347
- ];
348
- }
349
- exit$3 = 6;
350
- }
351
- if (exit$3 === 6) {
352
- var match$6 = match$5.tl;
353
- if (match$6 && match$6.hd === 59) {
354
- var match$7 = match$6.tl;
355
- if (!match$7) {
337
+ var match$6 = match$2.tl;
338
+ if (!match$6) {
356
339
  return [
357
- 1,
358
- undefined
340
+ length,
341
+ /* Clear */0
359
342
  ];
360
343
  }
361
- var match$8 = match$7.tl;
362
- if (match$8) {
363
- var match$9 = match$8.tl;
364
- var colorValue$2 = match$8.hd;
365
- var colorMode$2 = match$7.hd;
366
- if (match$9) {
367
- if (match$9.hd !== 59) {
368
- exit$2 = 5;
369
- } else {
344
+ var style$3 = match$6.hd;
345
+ var exit$4 = 0;
346
+ if (style$3 !== 48) {
347
+ exit$4 = 7;
348
+ } else {
349
+ if (!match$6.tl) {
350
+ return [
351
+ length,
352
+ /* Clear */0
353
+ ];
354
+ }
355
+ exit$4 = 7;
356
+ }
357
+ if (exit$4 === 7) {
358
+ var match$7 = match$6.tl;
359
+ if (match$7 && match$7.hd === 59) {
360
+ var match$8 = match$7.tl;
361
+ if (!match$8) {
362
+ return [
363
+ 1,
364
+ undefined
365
+ ];
366
+ }
367
+ var match$9 = match$8.tl;
368
+ if (match$9) {
370
369
  var match$10 = match$9.tl;
371
- if (!match$10) {
372
- return [
373
- 1,
374
- undefined
375
- ];
376
- }
377
- var cm2$1 = match$10.hd;
378
- var match$11 = match$10.tl;
379
- if (match$11) {
380
- if (match$11.tl) {
381
- if (cm2$1 !== 49) {
382
- exit$2 = 5;
383
- } else {
384
- var match$12 = match$10.tl;
385
- var match$13 = match$12.tl;
386
- if (match$13.tl) {
387
- return [
388
- 1,
389
- undefined
390
- ];
370
+ var colorValue$2 = match$9.hd;
371
+ var colorMode$2 = match$8.hd;
372
+ if (match$10) {
373
+ if (match$10.hd !== 59) {
374
+ exit$2 = 5;
375
+ } else {
376
+ var match$11 = match$10.tl;
377
+ if (!match$11) {
378
+ return [
379
+ 1,
380
+ undefined
381
+ ];
382
+ }
383
+ var cm2$1 = match$11.hd;
384
+ var match$12 = match$11.tl;
385
+ if (match$12) {
386
+ if (match$12.tl) {
387
+ if (cm2$1 !== 49) {
388
+ exit$2 = 5;
389
+ } else {
390
+ var match$13 = match$11.tl;
391
+ var match$14 = match$13.tl;
392
+ if (match$14.tl) {
393
+ return [
394
+ 1,
395
+ undefined
396
+ ];
397
+ }
398
+ style$1 = style$3;
399
+ cm1 = colorMode$2;
400
+ cv1 = colorValue$2;
401
+ cm2 = match$13.hd;
402
+ cv2 = match$14.hd;
403
+ xs$1 = codePoints;
404
+ exit$1 = 4;
405
+ }
406
+ } else {
407
+ style$1 = style$3;
408
+ cm1 = colorMode$2;
409
+ cv1 = colorValue$2;
410
+ cm2 = cm2$1;
411
+ cv2 = match$12.hd;
412
+ xs$1 = codePoints;
413
+ exit$1 = 4;
391
414
  }
392
- style$1 = style$3;
393
- cm1 = colorMode$2;
394
- cv1 = colorValue$2;
395
- cm2 = match$12.hd;
396
- cv2 = match$13.hd;
397
- xs$1 = codePoints;
398
- exit$1 = 4;
415
+ } else {
416
+ exit$2 = 5;
399
417
  }
400
- } else {
401
- style$1 = style$3;
402
- cm1 = colorMode$2;
403
- cv1 = colorValue$2;
404
- cm2 = cm2$1;
405
- cv2 = match$11.hd;
406
- xs$1 = codePoints;
407
- exit$1 = 4;
408
418
  }
409
419
  } else {
410
- exit$2 = 5;
420
+ colorMode$1 = colorMode$2;
421
+ colorValue$1 = colorValue$2;
422
+ style = style$3;
423
+ exit$1 = 3;
411
424
  }
425
+ } else {
426
+ exit$2 = 5;
412
427
  }
413
428
  } else {
414
- colorMode$1 = colorMode$2;
415
- colorValue$1 = colorValue$2;
416
- style = style$3;
417
- exit$1 = 3;
429
+ exit$2 = 5;
418
430
  }
419
- } else {
420
- exit$2 = 5;
421
431
  }
422
- } else {
423
- exit$2 = 5;
432
+
433
+ }
434
+ } else {
435
+ if (switcher === 27) {
436
+ return [
437
+ 3,
438
+ /* EraseLine */1
439
+ ];
424
440
  }
441
+ exit$2 = 5;
425
442
  }
426
-
427
443
  }
428
444
  if (exit$2 === 5) {
429
- var match$14 = match$2.tl;
430
- if (!match$14) {
445
+ var match$15 = match$2.tl;
446
+ if (!match$15) {
431
447
  return [
432
448
  length,
433
449
  Belt_Option.flatMap(get$1(style$2), (function (style) {
@@ -438,26 +454,26 @@ function parse(txt, pos) {
438
454
  }))
439
455
  ];
440
456
  }
441
- var colorValue$3 = match$14.hd;
442
- var exit$4 = 0;
443
- var match$15 = match$14.tl;
444
- if (match$15) {
445
- if (match$15.hd !== 59) {
446
- exit$4 = 6;
457
+ var colorValue$3 = match$15.hd;
458
+ var exit$5 = 0;
459
+ var match$16 = match$15.tl;
460
+ if (match$16) {
461
+ if (match$16.hd !== 59) {
462
+ exit$5 = 6;
447
463
  } else {
448
- var match$16 = match$15.tl;
449
- if (!match$16) {
464
+ var match$17 = match$16.tl;
465
+ if (!match$17) {
450
466
  return [
451
467
  1,
452
468
  undefined
453
469
  ];
454
470
  }
455
- if (match$16.tl) {
456
- exit$4 = 6;
471
+ if (match$17.tl) {
472
+ exit$5 = 6;
457
473
  } else {
458
474
  colorMode$1 = style$2;
459
475
  colorValue$1 = colorValue$3;
460
- style = match$16.hd;
476
+ style = match$17.hd;
461
477
  exit$1 = 3;
462
478
  }
463
479
  }
@@ -467,56 +483,56 @@ function parse(txt, pos) {
467
483
  xs = codePoints;
468
484
  exit$1 = 2;
469
485
  }
470
- if (exit$4 === 6) {
486
+ if (exit$5 === 6) {
471
487
  if (colorValue$3 !== 59) {
472
488
  return [
473
489
  1,
474
490
  undefined
475
491
  ];
476
492
  }
477
- var match$17 = match$14.tl;
478
- var match$18 = match$17.tl;
479
- if (!match$18) {
493
+ var match$18 = match$15.tl;
494
+ var match$19 = match$18.tl;
495
+ if (!match$19) {
480
496
  return [
481
497
  1,
482
498
  undefined
483
499
  ];
484
500
  }
485
- var match$19 = match$18.tl;
486
- var colorValue$4 = match$18.hd;
487
- var colorMode$3 = match$17.hd;
488
- if (match$19) {
489
- if (match$19.hd !== 59) {
501
+ var match$20 = match$19.tl;
502
+ var colorValue$4 = match$19.hd;
503
+ var colorMode$3 = match$18.hd;
504
+ if (match$20) {
505
+ if (match$20.hd !== 59) {
490
506
  return [
491
507
  1,
492
508
  undefined
493
509
  ];
494
510
  }
495
- var match$20 = match$19.tl;
496
- if (!match$20) {
511
+ var match$21 = match$20.tl;
512
+ if (!match$21) {
497
513
  return [
498
514
  1,
499
515
  undefined
500
516
  ];
501
517
  }
502
- var cm2$2 = match$20.hd;
503
- var match$21 = match$20.tl;
504
- if (!match$21) {
518
+ var cm2$2 = match$21.hd;
519
+ var match$22 = match$21.tl;
520
+ if (!match$22) {
505
521
  return [
506
522
  1,
507
523
  undefined
508
524
  ];
509
525
  }
510
- if (match$21.tl) {
526
+ if (match$22.tl) {
511
527
  if (cm2$2 !== 49) {
512
528
  return [
513
529
  1,
514
530
  undefined
515
531
  ];
516
532
  }
517
- var match$22 = match$20.tl;
518
- var match$23 = match$22.tl;
519
- if (match$23.tl) {
533
+ var match$23 = match$21.tl;
534
+ var match$24 = match$23.tl;
535
+ if (match$24.tl) {
520
536
  return [
521
537
  1,
522
538
  undefined
@@ -525,8 +541,8 @@ function parse(txt, pos) {
525
541
  style$1 = style$2;
526
542
  cm1 = colorMode$3;
527
543
  cv1 = colorValue$4;
528
- cm2 = match$22.hd;
529
- cv2 = match$23.hd;
544
+ cm2 = match$23.hd;
545
+ cv2 = match$24.hd;
530
546
  xs$1 = codePoints;
531
547
  exit$1 = 4;
532
548
  } else {
@@ -534,7 +550,7 @@ function parse(txt, pos) {
534
550
  cm1 = colorMode$3;
535
551
  cv1 = colorValue$4;
536
552
  cm2 = cm2$2;
537
- cv2 = match$21.hd;
553
+ cv2 = match$22.hd;
538
554
  xs$1 = codePoints;
539
555
  exit$1 = 4;
540
556
  }
@@ -549,27 +565,14 @@ function parse(txt, pos) {
549
565
  }
550
566
 
551
567
  } else {
552
- var match$24 = codePoints.tl;
553
- if (!match$24) {
554
- return [
555
- 1,
556
- undefined
557
- ];
558
- }
559
- if (match$24.hd !== 27) {
560
- return [
561
- 1,
562
- undefined
563
- ];
564
- }
565
- var match$25 = match$24.tl;
568
+ var match$25 = codePoints.tl;
566
569
  if (!match$25) {
567
570
  return [
568
571
  1,
569
572
  undefined
570
573
  ];
571
574
  }
572
- if (match$25.hd !== 91) {
575
+ if (match$25.hd !== 27) {
573
576
  return [
574
577
  1,
575
578
  undefined
@@ -582,7 +585,7 @@ function parse(txt, pos) {
582
585
  undefined
583
586
  ];
584
587
  }
585
- if (match$26.hd !== 49) {
588
+ if (match$26.hd !== 91) {
586
589
  return [
587
590
  1,
588
591
  undefined
@@ -595,7 +598,7 @@ function parse(txt, pos) {
595
598
  undefined
596
599
  ];
597
600
  }
598
- if (match$27.hd !== 65) {
601
+ if (match$27.hd !== 49) {
599
602
  return [
600
603
  1,
601
604
  undefined
@@ -608,7 +611,7 @@ function parse(txt, pos) {
608
611
  undefined
609
612
  ];
610
613
  }
611
- if (match$28.hd !== 27) {
614
+ if (match$28.hd !== 65) {
612
615
  return [
613
616
  1,
614
617
  undefined
@@ -621,14 +624,27 @@ function parse(txt, pos) {
621
624
  undefined
622
625
  ];
623
626
  }
624
- if (match$29.hd !== 91) {
627
+ if (match$29.hd !== 27) {
625
628
  return [
626
629
  1,
627
630
  undefined
628
631
  ];
629
632
  }
630
633
  var match$30 = match$29.tl;
631
- if (match$30 && match$30.hd === 74) {
634
+ if (!match$30) {
635
+ return [
636
+ 1,
637
+ undefined
638
+ ];
639
+ }
640
+ if (match$30.hd !== 91) {
641
+ return [
642
+ 1,
643
+ undefined
644
+ ];
645
+ }
646
+ var match$31 = match$30.tl;
647
+ if (match$31 && match$31.hd === 74) {
632
648
  return [
633
649
  9,
634
650
  /* EraseLine */1
@@ -771,7 +787,7 @@ function parse$1(txt, length, pos) {
771
787
 
772
788
  }
773
789
  } else {
774
- if (code.TAG === /* HRef */0) {
790
+ if (!code.TAG) {
775
791
  return [
776
792
  pos$1,
777
793
  {
package/src/Ansi.re CHANGED
@@ -174,12 +174,16 @@ module AnsiCode = {
174
174
  switch (codePoints) {
175
175
  // \n\x0d[1A\x0d[J
176
176
  | [10, 27, 91, 49, 65, 27, 91, 74, ..._] => (9, EraseLine->Some)
177
- // [1K
178
- | [91, 48, 75, ..._] => (4, EraseLine->Some)
177
+ // [_K
178
+ | [91, _, 75, ..._] => (4, EraseLine->Some)
179
+ // [K
180
+ | [91, 75, ..._] => (3, EraseLine->Some)
179
181
  // [00m
180
182
  | [91, 48, 48]
181
183
  // [0m
182
- | [91, 48] => (length, Clear->Some)
184
+ | [91, 48]
185
+ // [m
186
+ | [91] => (length, Clear->Some)
183
187
  // [_m
184
188
  | [91, style] => (
185
189
  length,