@softwarefactory-project/re-ansi 0.5.0 → 0.7.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/src/Ansi.bs.js DELETED
@@ -1,931 +0,0 @@
1
- 'use strict';
2
-
3
- var Curry = require("bs-platform/lib/js/curry.js");
4
- var React = require("react");
5
- var Belt_List = require("bs-platform/lib/js/belt_List.js");
6
- var Belt_Option = require("bs-platform/lib/js/belt_Option.js");
7
- var Caml_option = require("bs-platform/lib/js/caml_option.js");
8
-
9
- function fourBitColors(code) {
10
- switch (code) {
11
- case 0 :
12
- return "black";
13
- case 1 :
14
- return "red";
15
- case 2 :
16
- return "green";
17
- case 3 :
18
- return "yellow";
19
- case 4 :
20
- return "blue";
21
- case 5 :
22
- return "magenta";
23
- case 6 :
24
- return "cyan";
25
- case 8 :
26
- console.log("Unknown color value:", code);
27
- return ;
28
- case 9 :
29
- return "initial";
30
- case 10 :
31
- return "grey";
32
- case 11 :
33
- return "#DA2647";
34
- case 12 :
35
- return "#87FF2A";
36
- case 13 :
37
- return "#FFF700";
38
- case 14 :
39
- return "#5DADEC";
40
- case 15 :
41
- return "#FF3399";
42
- case 16 :
43
- return "#8DD9CC";
44
- case 7 :
45
- case 17 :
46
- return "white";
47
- default:
48
- console.log("Unknown color value:", code);
49
- return ;
50
- }
51
- }
52
-
53
- function combine(css1, css2) {
54
- return Object.assign({}, css1, css2);
55
- }
56
-
57
- function addWeight(fontWeight) {
58
- return {
59
- fontWeight: fontWeight
60
- };
61
- }
62
-
63
- function addStyle(fontStyle) {
64
- return {
65
- fontStyle: fontStyle
66
- };
67
- }
68
-
69
- function addDecoration(textDecoration) {
70
- return {
71
- textDecoration: textDecoration
72
- };
73
- }
74
-
75
- function int_of_cp(c) {
76
- return c - 48 | 0;
77
- }
78
-
79
- function getColorStyle(colorMode, colorValue) {
80
- switch (colorMode) {
81
- case 0 :
82
- case 4 :
83
- return {
84
- TAG: /* Background */1,
85
- _0: colorValue
86
- };
87
- case 1 :
88
- case 2 :
89
- case 5 :
90
- case 6 :
91
- case 7 :
92
- case 8 :
93
- break;
94
- case 3 :
95
- case 9 :
96
- return {
97
- TAG: /* Foreground */0,
98
- _0: colorValue
99
- };
100
- default:
101
-
102
- }
103
- console.log("Unknown color code:", colorMode, colorValue);
104
-
105
- }
106
-
107
- function getColorStyleCss(color) {
108
- if (color.TAG) {
109
- return Belt_Option.flatMap(fourBitColors(color._0), (function (background) {
110
- return {
111
- background: background
112
- };
113
- }));
114
- } else {
115
- return Belt_Option.flatMap(fourBitColors(color._0), (function (color) {
116
- return {
117
- color: color
118
- };
119
- }));
120
- }
121
- }
122
-
123
- function get(colorMode, colorValue) {
124
- return Belt_Option.flatMap(getColorStyle(colorMode - 48 | 0, colorValue - 48 | 0), getColorStyleCss);
125
- }
126
-
127
- var ColorCss = {
128
- getColorStyle: getColorStyle,
129
- getColorStyleCss: getColorStyleCss,
130
- get: get
131
- };
132
-
133
- function getFontStyle(fontMode) {
134
- switch (fontMode) {
135
- case 1 :
136
- return /* FontStyle */{
137
- _0: addWeight("bold")
138
- };
139
- case 2 :
140
- return /* FontStyle */{
141
- _0: addWeight("lighter")
142
- };
143
- case 3 :
144
- return /* FontStyle */{
145
- _0: addStyle("italic")
146
- };
147
- case 4 :
148
- return /* FontStyle */{
149
- _0: addDecoration("underline")
150
- };
151
- case 0 :
152
- case 7 :
153
- return /* Regular */0;
154
- case 5 :
155
- case 6 :
156
- case 8 :
157
- return ;
158
- case 9 :
159
- return /* FontStyle */{
160
- _0: addDecoration("line-through")
161
- };
162
- default:
163
- return ;
164
- }
165
- }
166
-
167
- function getFontStyleCss(font) {
168
- if (font) {
169
- return Caml_option.some(font._0);
170
- }
171
-
172
- }
173
-
174
- function get$1(fontMode) {
175
- return Belt_Option.flatMap(getFontStyle(fontMode - 48 | 0), getFontStyleCss);
176
- }
177
-
178
- var FontCss = {
179
- getFontStyle: getFontStyle,
180
- getFontStyleCss: getFontStyleCss,
181
- get: get$1
182
- };
183
-
184
- var linkRe = /^(http(s)?:\/\/[^\s]+)/;
185
-
186
- function get$2(txt) {
187
- return Belt_Option.getWithDefault(Belt_Option.flatMap(Caml_option.null_to_opt(linkRe.exec(txt)), (function (res) {
188
- return Belt_Option.flatMap(res.length !== 3 ? undefined : Caml_option.nullable_to_opt(res[0]), (function (url) {
189
- return [
190
- url.length,
191
- {
192
- TAG: /* HRef */0,
193
- _0: url
194
- }
195
- ];
196
- }));
197
- })), [
198
- 1,
199
- undefined
200
- ]);
201
- }
202
-
203
- var HttpLink = {
204
- linkRe: linkRe,
205
- get: get$2
206
- };
207
-
208
- function parse(txt, pos) {
209
- var match = txt.codePointAt(pos);
210
- var exit = 0;
211
- if (match === undefined) {
212
- return [
213
- 0,
214
- undefined
215
- ];
216
- }
217
- if (match >= 14) {
218
- if (match !== 27) {
219
- if (match !== 104) {
220
- return [
221
- 0,
222
- undefined
223
- ];
224
- }
225
- var func = function (param, param$1) {
226
- return param$1.slice(pos, param);
227
- };
228
- return get$2(Curry._2(func, 512, txt));
229
- }
230
- exit = 1;
231
- } else {
232
- if (match === 10) {
233
- return [
234
- 1,
235
- /* CarriageReturn */2
236
- ];
237
- }
238
- if (match < 13) {
239
- return [
240
- 0,
241
- undefined
242
- ];
243
- }
244
- exit = 1;
245
- }
246
- if (exit === 1) {
247
- var cps = function (_idx, _acc) {
248
- while(true) {
249
- var acc = _acc;
250
- var idx = _idx;
251
- var match = idx > 10;
252
- var match$1 = txt.codePointAt(pos + idx | 0);
253
- if (match) {
254
- return acc;
255
- }
256
- if (match$1 === undefined) {
257
- return acc;
258
- }
259
- if (match$1 === 109) {
260
- return acc;
261
- }
262
- _acc = Belt_List.add(acc, match$1);
263
- _idx = idx + 1 | 0;
264
- continue ;
265
- };
266
- };
267
- var codePoints = Belt_List.reverse(cps(1, /* [] */0));
268
- var length = Belt_List.length(codePoints) + 2 | 0;
269
- var exit$1 = 0;
270
- var colorMode;
271
- var colorValue;
272
- var xs;
273
- var colorMode$1;
274
- var colorValue$1;
275
- var style;
276
- var style$1;
277
- var cm1;
278
- var cv1;
279
- var cm2;
280
- var cv2;
281
- var xs$1;
282
- if (!codePoints) {
283
- return [
284
- 1,
285
- undefined
286
- ];
287
- }
288
- var match$1 = codePoints.hd;
289
- if (match$1 !== 10) {
290
- if (match$1 !== 91) {
291
- return [
292
- 1,
293
- undefined
294
- ];
295
- }
296
- var match$2 = codePoints.tl;
297
- if (!match$2) {
298
- return [
299
- length,
300
- /* Clear */0
301
- ];
302
- }
303
- var style$2 = match$2.hd;
304
- var exit$2 = 0;
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
- }
333
- } else {
334
- exit$2 = 5;
335
- }
336
- } else {
337
- var match$6 = match$2.tl;
338
- if (!match$6) {
339
- return [
340
- length,
341
- /* Clear */0
342
- ];
343
- }
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) {
369
- var match$10 = match$9.tl;
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;
414
- }
415
- } else {
416
- exit$2 = 5;
417
- }
418
- }
419
- } else {
420
- colorMode$1 = colorMode$2;
421
- colorValue$1 = colorValue$2;
422
- style = style$3;
423
- exit$1 = 3;
424
- }
425
- } else {
426
- exit$2 = 5;
427
- }
428
- } else {
429
- exit$2 = 5;
430
- }
431
- }
432
-
433
- }
434
- } else {
435
- if (switcher === 27) {
436
- return [
437
- 3,
438
- /* EraseLine */1
439
- ];
440
- }
441
- exit$2 = 5;
442
- }
443
- }
444
- if (exit$2 === 5) {
445
- var match$15 = match$2.tl;
446
- if (!match$15) {
447
- return [
448
- length,
449
- Belt_Option.flatMap(get$1(style$2), (function (style) {
450
- return {
451
- TAG: /* Style */1,
452
- _0: style
453
- };
454
- }))
455
- ];
456
- }
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;
463
- } else {
464
- var match$17 = match$16.tl;
465
- if (!match$17) {
466
- return [
467
- 1,
468
- undefined
469
- ];
470
- }
471
- if (match$17.tl) {
472
- exit$5 = 6;
473
- } else {
474
- colorMode$1 = style$2;
475
- colorValue$1 = colorValue$3;
476
- style = match$17.hd;
477
- exit$1 = 3;
478
- }
479
- }
480
- } else {
481
- colorMode = style$2;
482
- colorValue = colorValue$3;
483
- xs = codePoints;
484
- exit$1 = 2;
485
- }
486
- if (exit$5 === 6) {
487
- if (colorValue$3 !== 59) {
488
- return [
489
- 1,
490
- undefined
491
- ];
492
- }
493
- var match$18 = match$15.tl;
494
- var match$19 = match$18.tl;
495
- if (!match$19) {
496
- return [
497
- 1,
498
- undefined
499
- ];
500
- }
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) {
506
- return [
507
- 1,
508
- undefined
509
- ];
510
- }
511
- var match$21 = match$20.tl;
512
- if (!match$21) {
513
- return [
514
- 1,
515
- undefined
516
- ];
517
- }
518
- var cm2$2 = match$21.hd;
519
- var match$22 = match$21.tl;
520
- if (!match$22) {
521
- return [
522
- 1,
523
- undefined
524
- ];
525
- }
526
- if (match$22.tl) {
527
- if (cm2$2 !== 49) {
528
- return [
529
- 1,
530
- undefined
531
- ];
532
- }
533
- var match$23 = match$21.tl;
534
- var match$24 = match$23.tl;
535
- if (match$24.tl) {
536
- return [
537
- 1,
538
- undefined
539
- ];
540
- }
541
- style$1 = style$2;
542
- cm1 = colorMode$3;
543
- cv1 = colorValue$4;
544
- cm2 = match$23.hd;
545
- cv2 = match$24.hd;
546
- xs$1 = codePoints;
547
- exit$1 = 4;
548
- } else {
549
- style$1 = style$2;
550
- cm1 = colorMode$3;
551
- cv1 = colorValue$4;
552
- cm2 = cm2$2;
553
- cv2 = match$22.hd;
554
- xs$1 = codePoints;
555
- exit$1 = 4;
556
- }
557
- } else {
558
- colorMode$1 = colorMode$3;
559
- colorValue$1 = colorValue$4;
560
- style = style$2;
561
- exit$1 = 3;
562
- }
563
- }
564
-
565
- }
566
-
567
- } else {
568
- var match$25 = codePoints.tl;
569
- if (!match$25) {
570
- return [
571
- 1,
572
- undefined
573
- ];
574
- }
575
- if (match$25.hd !== 27) {
576
- return [
577
- 1,
578
- undefined
579
- ];
580
- }
581
- var match$26 = match$25.tl;
582
- if (!match$26) {
583
- return [
584
- 1,
585
- undefined
586
- ];
587
- }
588
- if (match$26.hd !== 91) {
589
- return [
590
- 1,
591
- undefined
592
- ];
593
- }
594
- var match$27 = match$26.tl;
595
- if (!match$27) {
596
- return [
597
- 1,
598
- undefined
599
- ];
600
- }
601
- if (match$27.hd !== 49) {
602
- return [
603
- 1,
604
- undefined
605
- ];
606
- }
607
- var match$28 = match$27.tl;
608
- if (!match$28) {
609
- return [
610
- 1,
611
- undefined
612
- ];
613
- }
614
- if (match$28.hd !== 65) {
615
- return [
616
- 1,
617
- undefined
618
- ];
619
- }
620
- var match$29 = match$28.tl;
621
- if (!match$29) {
622
- return [
623
- 1,
624
- undefined
625
- ];
626
- }
627
- if (match$29.hd !== 27) {
628
- return [
629
- 1,
630
- undefined
631
- ];
632
- }
633
- var match$30 = match$29.tl;
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) {
648
- return [
649
- 9,
650
- /* EraseLine */1
651
- ];
652
- } else {
653
- return [
654
- 1,
655
- undefined
656
- ];
657
- }
658
- }
659
- switch (exit$1) {
660
- case 2 :
661
- return [
662
- length,
663
- Belt_Option.flatMap(get(colorMode, colorValue + (
664
- Belt_List.length(xs) === 4 ? 10 : 0
665
- ) | 0), (function (colorCss) {
666
- return {
667
- TAG: /* Style */1,
668
- _0: colorCss
669
- };
670
- }))
671
- ];
672
- case 3 :
673
- return [
674
- length,
675
- Belt_Option.flatMap(get(colorMode$1, colorValue$1), (function (colorCss) {
676
- var fontCss = get$1(style);
677
- if (fontCss !== undefined) {
678
- return {
679
- TAG: /* Style */1,
680
- _0: Object.assign({}, colorCss, Caml_option.valFromOption(fontCss))
681
- };
682
- } else {
683
- return {
684
- TAG: /* Style */1,
685
- _0: colorCss
686
- };
687
- }
688
- }))
689
- ];
690
- case 4 :
691
- return [
692
- length,
693
- Belt_Option.flatMap(get(cm1, cv1), (function (colorCss1) {
694
- return Belt_Option.flatMap(get(cm2, cv2 + (
695
- Belt_List.length(xs$1) === 9 ? 10 : 0
696
- ) | 0), (function (colorCss2) {
697
- var css = Object.assign({}, colorCss1, colorCss2);
698
- var fontCss = get$1(style$1);
699
- if (fontCss !== undefined) {
700
- return {
701
- TAG: /* Style */1,
702
- _0: Object.assign({}, css, Caml_option.valFromOption(fontCss))
703
- };
704
- } else {
705
- return {
706
- TAG: /* Style */1,
707
- _0: css
708
- };
709
- }
710
- }));
711
- }))
712
- ];
713
-
714
- }
715
- }
716
-
717
- }
718
-
719
- var AnsiCode = {
720
- fourBitColors: fourBitColors,
721
- combine: combine,
722
- addWeight: addWeight,
723
- addStyle: addStyle,
724
- addDecoration: addDecoration,
725
- int_of_cp: int_of_cp,
726
- ColorCss: ColorCss,
727
- FontCss: FontCss,
728
- HttpLink: HttpLink,
729
- parse: parse
730
- };
731
-
732
- function text(txt, from, to_) {
733
- var func = function (param, param$1) {
734
- return param$1.slice(from, param);
735
- };
736
- return {
737
- TAG: /* Text */0,
738
- _0: Curry._2(func, to_, txt)
739
- };
740
- }
741
-
742
- function parse$1(txt, length, pos) {
743
- var go = function (_pos, _prev) {
744
- while(true) {
745
- var prev = _prev;
746
- var pos = _pos;
747
- var match = pos === length;
748
- var match$1 = parse(txt, pos);
749
- if (match) {
750
- return [
751
- pos,
752
- {
753
- hd: text(txt, prev, pos),
754
- tl: /* [] */0
755
- }
756
- ];
757
- }
758
- var code = match$1[1];
759
- if (code !== undefined) {
760
- var prevElem = text(txt, prev, pos);
761
- var pos$1 = pos + match$1[0] | 0;
762
- if (typeof code === "number") {
763
- switch (code) {
764
- case /* Clear */0 :
765
- return [
766
- pos$1,
767
- {
768
- hd: prevElem,
769
- tl: /* [] */0
770
- }
771
- ];
772
- case /* EraseLine */1 :
773
- _prev = pos$1;
774
- _pos = pos$1;
775
- continue ;
776
- case /* CarriageReturn */2 :
777
- return [
778
- pos$1,
779
- {
780
- hd: prevElem,
781
- tl: {
782
- hd: /* LineBreak */0,
783
- tl: /* [] */0
784
- }
785
- }
786
- ];
787
-
788
- }
789
- } else {
790
- if (!code.TAG) {
791
- return [
792
- pos$1,
793
- {
794
- hd: prevElem,
795
- tl: {
796
- hd: {
797
- TAG: /* Link */1,
798
- _0: code._0
799
- },
800
- tl: /* [] */0
801
- }
802
- }
803
- ];
804
- }
805
- var match$2 = go(pos$1, pos$1);
806
- var styled = match$2[1];
807
- if (styled !== undefined) {
808
- return [
809
- match$2[0],
810
- {
811
- hd: prevElem,
812
- tl: {
813
- hd: {
814
- TAG: /* DocStyle */2,
815
- _0: code._0,
816
- _1: styled
817
- },
818
- tl: /* [] */0
819
- }
820
- }
821
- ];
822
- } else {
823
- return [
824
- pos$1,
825
- undefined
826
- ];
827
- }
828
- }
829
- } else {
830
- _pos = pos + 1 | 0;
831
- continue ;
832
- }
833
- };
834
- };
835
- return go(pos, pos);
836
- }
837
-
838
- var $$Document = {
839
- text: text,
840
- parse: parse$1
841
- };
842
-
843
- function parse$2(txt) {
844
- var go = function (_txt, _acc) {
845
- while(true) {
846
- var acc = _acc;
847
- var txt = _txt;
848
- var length = txt.length;
849
- var match = parse$1(txt, length, 0);
850
- var doc = match[1];
851
- var pos = match[0];
852
- if (doc === undefined) {
853
- return acc;
854
- }
855
- if (pos === length) {
856
- return Belt_List.add(acc, doc);
857
- }
858
- _acc = Belt_List.add(acc, doc);
859
- _txt = txt.slice(pos);
860
- continue ;
861
- };
862
- };
863
- return Belt_List.flatten(Belt_List.reverse(go(txt, /* [] */0)));
864
- }
865
-
866
- function render(doc) {
867
- var go = function (_xs, _idx, _acc) {
868
- while(true) {
869
- var acc = _acc;
870
- var idx = _idx;
871
- var xs = _xs;
872
- if (!xs) {
873
- return Belt_List.toArray(Belt_List.reverse(acc));
874
- }
875
- var txt = xs.hd;
876
- if (typeof txt === "number") {
877
- _acc = Belt_List.add(acc, React.createElement("br", {
878
- key: String(idx)
879
- }));
880
- _idx = idx + 1 | 0;
881
- _xs = xs.tl;
882
- continue ;
883
- }
884
- switch (txt.TAG | 0) {
885
- case /* Text */0 :
886
- _acc = Belt_List.add(acc, txt._0);
887
- _idx = idx + 1 | 0;
888
- _xs = xs.tl;
889
- continue ;
890
- case /* Link */1 :
891
- var href = txt._0;
892
- _acc = Belt_List.add(acc, React.createElement("a", {
893
- key: String(idx),
894
- href: href
895
- }, href));
896
- _idx = idx + 1 | 0;
897
- _xs = xs.tl;
898
- continue ;
899
- case /* DocStyle */2 :
900
- _acc = Belt_List.add(acc, React.createElement("span", {
901
- key: String(idx),
902
- style: txt._0
903
- }, go(txt._1, 0, /* [] */0)));
904
- _idx = idx + 1 | 0;
905
- _xs = xs.tl;
906
- continue ;
907
-
908
- }
909
- };
910
- };
911
- return go(doc, 0, /* [] */0);
912
- }
913
-
914
- function Ansi(Props) {
915
- var log = Props.log;
916
- return React.createElement("div", undefined, render(parse$2(log)));
917
- }
918
-
919
- var make = Ansi;
920
-
921
- var $$default = Ansi;
922
-
923
- exports.AnsiCode = AnsiCode;
924
- exports.$$Document = $$Document;
925
- exports.parse = parse$2;
926
- exports.render = render;
927
- exports.make = make;
928
- exports.$$default = $$default;
929
- exports.default = $$default;
930
- exports.__esModule = true;
931
- /* react Not a pure module */