/**
 * Copyright 2019 Twitter, Inc.
 * Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 */ import { RenderedSpan } from "sqrl-common" ; import chalk from "chalk" ; const classColor = { type : "magentaBright" , "type:syntax" : "magenta" , value : "blueBright" , separator : "blue" , "value:json" : "gray" , } ; export function spanToShell ( span ) { let color = null ; for ( let idx = 0 ; idx < span . class . length ; idx ++ ) { const joined = span . class . slice ( 0 , idx + 1 ) . join ( ":" ) ; color = classColor [ joined ] || color ; } let rv ; if ( span . children ) { rv = span . children . map ( ( child ) => spanToShell ( child ) ) . join ( "" ) ; } else { rv = span . text ; } if ( color ) { return chalk [ color ] ( rv ) ; } else { return rv ; } }