@@ -4,27 +4,6 @@ const React = require('react');
4
4
const Anser = require ( 'anser' ) ;
5
5
const escapeCarriageReturn = require ( 'escape-carriage' ) ;
6
6
7
- type AnserJsonEntry = {
8
- content : string ,
9
- fg : string ,
10
- bg : string ,
11
- fg_truecolor : string ,
12
- bg_truecolor : string ,
13
- clearLine : boolean ,
14
- was_processed : boolean ,
15
- isEmpty : ( ) => boolean
16
- } ;
17
-
18
- type AnserJson = Array < AnserJsonEntry > ;
19
-
20
- type AnsiBundle = {
21
- content : string ,
22
- style : {
23
- color ?: string ,
24
- backgroundColor ?: string
25
- }
26
- } ;
27
-
28
7
/**
29
8
* ansiToJson
30
9
* Convert ANSI strings into JSON output.
@@ -34,15 +13,15 @@ type AnsiBundle = {
34
13
* @param {String } input The input string.
35
14
* @return {Array } The parsed input.
36
15
*/
37
- function ansiToJSON ( input : string ) : AnserJson {
16
+ function ansiToJSON ( input ) {
38
17
input = escapeCarriageReturn ( input ) ;
39
18
return Anser . ansiToJson ( input , {
40
19
json : true ,
41
20
remove_empty : true ,
42
21
} ) ;
43
22
}
44
23
45
- function ansiJSONtoStyleBundle ( ansiBundle : AnserJsonEntry ) : AnsiBundle {
24
+ function ansiJSONtoStyleBundle ( ansiBundle ) {
46
25
const style = { } ;
47
26
if ( ansiBundle . bg ) {
48
27
style . backgroundColor = `rgb(${ ansiBundle . bg } )` ;
@@ -56,11 +35,11 @@ function ansiJSONtoStyleBundle(ansiBundle: AnserJsonEntry): AnsiBundle {
56
35
} ;
57
36
}
58
37
59
- function ansiToInlineStyle ( text : string ) : Array < AnsiBundle > {
38
+ function ansiToInlineStyle ( text ) {
60
39
return ansiToJSON ( text ) . map ( ansiJSONtoStyleBundle ) ;
61
40
}
62
41
63
- function linkifyBundle ( bundle : AnsiBundle ) {
42
+ function linkifyBundle ( bundle ) {
64
43
return {
65
44
...bundle ,
66
45
content : bundle . content . split ( ' ' ) . reduce ( ( result , word , index ) => [
@@ -90,7 +69,13 @@ function inlineBundleToReact(bundle, key) {
90
69
} , bundle . content ) ;
91
70
}
92
71
93
- function Ansi ( props : { children : string , className ?: string } ) {
72
+ type Props = {
73
+ children ?: React$Element < any > ,
74
+ className ?: string ,
75
+ linkify ?: boolean
76
+ } ;
77
+
78
+ function Ansi ( props : Props ) {
94
79
return React . createElement (
95
80
'code' ,
96
81
{ className : props . className } ,
0 commit comments