MCPcopy Create free account
hub / github.com/devcontainers/cli / colorize

Function colorize

src/spec-utils/log.ts:250–262  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

248}
249
250export function colorize(text: string) {
251 let m: RegExpExecArray | null;
252 let lastIndex = 0;
253 const fragments: string[] = [];
254 terminalEscapeSequences.lastIndex = 0;
255 while (m = terminalEscapeSequences.exec(text)) {
256 fragments.push(colorizePlainText(text.substring(lastIndex, m.index)));
257 fragments.push(m[0]);
258 lastIndex = terminalEscapeSequences.lastIndex;
259 }
260 fragments.push(colorizePlainText(text.substr(lastIndex)));
261 return fragments.join('');
262}
263
264function colorizePlainText(text: string) {
265 const num = /(?<=^|[^A-Za-z0-9_\-\.])[0-9]+(\.[0-9]+)*(?=$|[^A-Za-z0-9_\-\.])/g;

Callers 1

toTerminalTextFunction · 0.85

Calls 2

colorizePlainTextFunction · 0.85
execMethod · 0.65

Tested by

no test coverage detected