/**
 * vscode-pvs colors.
 */ export enum PvsColor { blue = "blue" , darkblue = "darkblue" , yellow = "yellow" , darkyellow = "darkyellow" , gold = "gold" , green = "green" , darkgreen = "darkgreen" , red = "red" , white = "white" , black = "black" , gray = "gray" , darkgray = "darkgray" } ; export declare type XTermColorTheme = "dark" | "light" ; export const ANSI_ESC = "\x1b[" ; export const ANSI_FOREGROUND = "38;" ; export const ANSI_BACKGROUND = "48;" ; export const ANSI_RESET_FOREGROUND = "38;39;" ; export const ANSI_RESET_BACKGROUND = "48;49;" ; export const ANSI_RESET = `${ ANSI_ESC }0m` ; /**
 * Utility function, returns a color based on the theme
 */ export function getColor ( color , theme ) { switch ( color ) { case PvsColor . yellow : { return theme === "dark" ? PvsColor . yellow : PvsColor . darkyellow ; } case PvsColor . blue : { return theme === "dark" ? PvsColor . blue : PvsColor . darkblue ; } case PvsColor . green : { return theme === "dark" ? PvsColor . green : PvsColor . darkgreen ; } case PvsColor . gray : { return theme === "dark" ? PvsColor . gray : PvsColor . black ; } default : { break ; } } return color ; } export const htmlColorCode = { blue : "#00b6fc" , darkblue : "#117AD0" , green : "mediumspringgreen" , darkgreen : "darkgreen" , yellow : "yellow" , darkyellow : "#999900" , gold : "gold" , red : "#f26158" , black : "#1e1e1e" , white : "whitesmoke" , gray : "gray" , darkgray : "darkgray" } ; export const ansiColorCode = { blue : 39 , darkblue : 26 , yellow : 229 , darkyellow : 202 , gold : 220 , green : 42 , darkgreen : 22 , red : 160 , white : 254 , black : 0 , gray : 7 , darkgray : 239 } ; const ansiColor256 = { yellow : `5;${ ansiColorCode . yellow }` , darkyellow : `5;${ ansiColorCode . darkyellow }` , gold : `5;${ ansiColorCode . gold }` , blue : `5;${ ansiColorCode . blue }` , darkblue : `5;${ ansiColorCode . darkblue }` , red : `5;${ ansiColorCode . red }` , white : `5;${ ansiColorCode . white }` , black : `5;${ ansiColorCode . black }` , green : `5;${ ansiColorCode . green }` , darkgreen : `5;${ ansiColorCode . darkgreen }` , gray : `5;${ ansiColorCode . gray }` , darkgray : `5;${ ansiColorCode . darkgray }` , } ; export const ansiColorRegex = /\x1b\[(\d;?)*m/g ; /**
 * Utility function, removes ansi sequences from the text
 */ export function getPlainText ( ctext ) { if ( ctext ) { return ctext . replace ( new RegExp ( ansiColorRegex ) , "" ) ; } return ctext ; } /**
 * Utility function, checks if the provided text is plain text (i.e., without ansi escape sequences)
 */ export function isPlainText ( ctext ) { if ( ctext ) { return ! ( new RegExp ( ansiColorRegex ) . test ( ctext ) ) ; } return true ; } export interface AnsiHighlightOptions { background ? : PvsColor ; foreground ? : PvsColor ; bold ? : boolean ; } export function ansiColorText ( text , opt ? ) { if ( text ) { opt = opt || { } ; let ansiCode = "" ; ansiCode += opt . bold ? `${ ANSI_ESC }1m` : "" ; ansiCode += opt . background && ansiColor256 [ opt . background ] ? `${ ANSI_ESC }${ ANSI_BACKGROUND }${ ansiColor256 [ opt . background ] }m` : "" ; ansiCode += opt . foreground && ansiColor256 [ opt . foreground ] ? `${ ANSI_ESC }${ ANSI_FOREGROUND }${ ansiColor256 [ opt . foreground ] }m` : "" ; ansiCode += text . toLocaleString ( ) ; ansiCode += ANSI_RESET ; return ansiCode ; } return text ; } export function colorText ( text , opt ) { if ( text ) { if ( typeof opt === "object" ) { return ansiColorText ( text , opt ) ; } else { return ansiColorText ( text , { foreground : opt } ) ; } } return text ; }