File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change 1
- console . log ( 'soon' ) ;
1
+ import React from 'react' ;
2
+
3
+ const ansiToJSON = require ( 'ansi-to-json' ) ;
4
+
5
+ function ansiJSONtoStyleBundle ( ansiBundle ) {
6
+ const style = { } ;
7
+ if ( ansiBundle . bg ) {
8
+ style . backgroundColor = `rgb(${ ansiBundle . bg } )` ;
9
+ }
10
+ if ( ansiBundle . fg ) {
11
+ style . color = `rgb(${ ansiBundle . fg } )` ;
12
+ }
13
+ return {
14
+ content : ansiBundle . content ,
15
+ style,
16
+ } ;
17
+ }
18
+
19
+ function ansiToInlineStyle ( text ) {
20
+ return ansiToJSON ( text ) . map ( ansiJSONtoStyleBundle )
21
+ }
22
+
23
+ function inlineBundleToReact ( bundle , key ) {
24
+ return < span style = { bundle . style } key = { key } > { bundle . content } </ span >
25
+ }
26
+
27
+ export default function Ansi ( props ) {
28
+ const { text } = props ;
29
+ return (
30
+ < code >
31
+ { ansiToInlineStyle ( text ) . map ( inlineBundleToReact ) }
32
+ </ code >
33
+ )
34
+ }
35
+
Original file line number Diff line number Diff line change 13
13
"author" :
" Kyle Kelley <[email protected] >" ,
14
14
"license" : " MPL-2.0" ,
15
15
"dependencies" : {
16
- "ansi-parser" : " ^3.2.0" ,
17
- "ansi-to-html" : " ^0.3.0" ,
18
- "entities" : " ^1.1.1"
16
+ "ansi-to-json" : " ^1.0.0"
19
17
}
20
18
}
You can’t perform that action at this time.
0 commit comments