MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / encodeConsoleColor

Function encodeConsoleColor

frontend/src/hooks/useTerminal.ts:398–483  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

396}
397
398export function encodeConsoleColor(text: string) {
399 text = text.replace(/(\x1B[^m]*m)/gm, "$1;");
400 text = text.replace(/ \[([A-Za-z0-9 _\-\\.]+)]/gim, " [§3$1§r]");
401 text = text.replace(/^\[([A-Za-z0-9 _\-\\.]+)]/gim, "[§3$1§r]");
402 text = text.replace(/((["'])(.*?)\1)/gm, "§e$1§r");
403 text = text.replace(/([0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2})/gim, "§6$1§r");
404 text = text.replace(/([0-9]{2,4}[\/\-][0-9]{2,4}[\/\-][0-9]{2,4})/gim, "§6$1§r");
405 text = text.replace(/(\x1B[^m]*m);/gm, "$1");
406 // ["](.*?)["];
407 text = text.replace(/§0/gim, TERM_COLOR.TERM_TEXT_BLACK);
408 text = text.replace(/§1/gim, TERM_COLOR.TERM_TEXT_DARK_BLUE);
409 text = text.replace(/§2/gim, TERM_COLOR.TERM_TEXT_DARK_GREEN);
410 text = text.replace(/§3/gim, TERM_COLOR.TERM_TEXT_DARK_AQUA);
411 text = text.replace(/§4/gim, TERM_COLOR.TERM_TEXT_DARK_RED);
412 text = text.replace(/§5/gim, TERM_COLOR.TERM_TEXT_DARK_PURPLE);
413 text = text.replace(/§6/gim, TERM_COLOR.TERM_TEXT_GOLD);
414 text = text.replace(/§7/gim, TERM_COLOR.TERM_TEXT_GRAY);
415 text = text.replace(/§8/gim, TERM_COLOR.TERM_TEXT_DARK_GRAY);
416 text = text.replace(/§9/gim, TERM_COLOR.TERM_TEXT_BLUE);
417 text = text.replace(/§a/gim, TERM_COLOR.TERM_TEXT_GREEN);
418 text = text.replace(/§b/gim, TERM_COLOR.TERM_TEXT_AQUA);
419 text = text.replace(/§c/gim, TERM_COLOR.TERM_TEXT_RED);
420 text = text.replace(/§d/gim, TERM_COLOR.TERM_TEXT_LIGHT_PURPLE);
421 text = text.replace(/§e/gim, TERM_COLOR.TERM_TEXT_YELLOW);
422 text = text.replace(/§f/gim, TERM_COLOR.TERM_TEXT_WHITE);
423 text = text.replace(/§k/gim, TERM_COLOR.TERM_TEXT_OBFUSCATED);
424 text = text.replace(/§l/gim, TERM_COLOR.TERM_TEXT_BOLD);
425 text = text.replace(/§m/gim, TERM_COLOR.TERM_TEXT_STRIKETHROUGH);
426 text = text.replace(/§n/gim, TERM_COLOR.TERM_TEXT_UNDERLINE);
427 text = text.replace(/§o/gim, TERM_COLOR.TERM_TEXT_ITALIC);
428 text = text.replace(/§r/gim, TERM_COLOR.TERM_RESET);
429
430 text = text.replace(/&0/gim, TERM_COLOR.TERM_TEXT_BLACK);
431 text = text.replace(/&1/gim, TERM_COLOR.TERM_TEXT_DARK_BLUE);
432 text = text.replace(/&2/gim, TERM_COLOR.TERM_TEXT_DARK_GREEN);
433 text = text.replace(/&3/gim, TERM_COLOR.TERM_TEXT_DARK_AQUA);
434 text = text.replace(/&4/gim, TERM_COLOR.TERM_TEXT_DARK_RED);
435 text = text.replace(/&5/gim, TERM_COLOR.TERM_TEXT_DARK_PURPLE);
436 text = text.replace(/&6/gim, TERM_COLOR.TERM_TEXT_GOLD);
437 text = text.replace(/&7/gim, TERM_COLOR.TERM_TEXT_GRAY);
438 text = text.replace(/&8/gim, TERM_COLOR.TERM_TEXT_DARK_GRAY);
439 text = text.replace(/&9/gim, TERM_COLOR.TERM_TEXT_BLUE);
440 text = text.replace(/&a/gim, TERM_COLOR.TERM_TEXT_GREEN);
441 text = text.replace(/&b/gim, TERM_COLOR.TERM_TEXT_AQUA);
442 text = text.replace(/&c/gim, TERM_COLOR.TERM_TEXT_RED);
443 text = text.replace(/&d/gim, TERM_COLOR.TERM_TEXT_LIGHT_PURPLE);
444 text = text.replace(/&e/gim, TERM_COLOR.TERM_TEXT_YELLOW);
445 text = text.replace(/&f/gim, TERM_COLOR.TERM_TEXT_WHITE);
446 text = text.replace(/&k/gim, TERM_COLOR.TERM_TEXT_OBFUSCATED);
447 text = text.replace(/&l/gim, TERM_COLOR.TERM_TEXT_BOLD);
448 text = text.replace(/&m/gim, TERM_COLOR.TERM_TEXT_STRIKETHROUGH);
449 text = text.replace(/&n/gim, TERM_COLOR.TERM_TEXT_UNDERLINE);
450 text = text.replace(/&o/gim, TERM_COLOR.TERM_TEXT_ITALIC);
451 text = text.replace(/&r/gim, TERM_COLOR.TERM_RESET);
452
453 const RegExpStringArr = [
454 //blue
455 ["\\d{1,3}%", "true", "false"],

Callers 1

useTerminalFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected