updates ssh.ts
This commit is contained in:
@@ -252,6 +252,7 @@ function parseColorTokens(message: string, renderColor: boolean): ColorToken[] {
|
||||
if (message) {
|
||||
let inColorStart = false;
|
||||
let inColorEnd = false;
|
||||
let noEscape = false;
|
||||
let chars: string[] = [];
|
||||
let startedColors: string[] = [];
|
||||
const messageLength = message.length;
|
||||
@@ -260,6 +261,19 @@ function parseColorTokens(message: string, renderColor: boolean): ColorToken[] {
|
||||
const nextC = (i + 1) < messageLength
|
||||
? message.charAt(i + 1)
|
||||
: null;
|
||||
const nextNexC = (i + 2) < messageLength
|
||||
? message.charAt(i + 2)
|
||||
: null;
|
||||
if (noEscape) {
|
||||
if (c === "]" && nextC === "]" && nextNexC === "]") {
|
||||
// end no escape
|
||||
noEscape = false;
|
||||
i += 2;
|
||||
} else {
|
||||
chars.push(c);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
switch (c) {
|
||||
case "\\":
|
||||
if (nextC === null) {
|
||||
@@ -276,6 +290,11 @@ function parseColorTokens(message: string, renderColor: boolean): ColorToken[] {
|
||||
} else if (nextC == "/") {
|
||||
inColorEnd = true;
|
||||
i++;
|
||||
} else if (nextC == "[" && nextNexC == "[") {
|
||||
// now no escape
|
||||
noEscape = true;
|
||||
i += 2;
|
||||
break;
|
||||
} else {
|
||||
inColorStart = true;
|
||||
}
|
||||
@@ -337,14 +356,51 @@ const COLOR_MAP: Record<string, string> = {
|
||||
blink: "5",
|
||||
bold: "1",
|
||||
under: "4",
|
||||
|
||||
black: "30",
|
||||
red: "31",
|
||||
green: "32",
|
||||
yellow: "33",
|
||||
blue: "34",
|
||||
pink: "35",
|
||||
cyan: "36",
|
||||
white: "37",
|
||||
|
||||
bg_black: "40",
|
||||
bg_red: "41",
|
||||
bg_green: "42",
|
||||
bg_yellow: "43",
|
||||
bg_blue: "44",
|
||||
bg_pink: "45",
|
||||
bg_cyan: "46",
|
||||
bg_white: "47",
|
||||
|
||||
black_bright: "90",
|
||||
red_bright: "91",
|
||||
green_bright: "92",
|
||||
yellow_bright: "93",
|
||||
blue_bright: "94",
|
||||
pink_bright: "95",
|
||||
cyan_bright: "96",
|
||||
white_bright: "97",
|
||||
|
||||
bg_black_bright: "100",
|
||||
bg_red_bright: "101",
|
||||
bg_green_bright: "102",
|
||||
bg_yellow_bright: "103",
|
||||
bg_blue_bright: "104",
|
||||
bg_pink_bright: "105",
|
||||
bg_cyan_bright: "106",
|
||||
bg_white_bright: "107",
|
||||
};
|
||||
|
||||
function getColorCode(color: string): string {
|
||||
if (color.startsWith("#")) {
|
||||
return color.substring(1);
|
||||
}
|
||||
return COLOR_MAP[color];
|
||||
}
|
||||
|
||||
function renderColorTokens(tokens: ColorToken[]): string {
|
||||
const text: string[] = [];
|
||||
const colorMapStack = new Map<string, number[]>();
|
||||
@@ -352,7 +408,7 @@ function renderColorTokens(tokens: ColorToken[]): string {
|
||||
if (token.type === "color") {
|
||||
const color = token.color;
|
||||
if (color) {
|
||||
const colorCode = COLOR_MAP[color];
|
||||
const colorCode = getColorCode(color);
|
||||
if (!colorCode) {
|
||||
text.push(`[${token.colorStart ? "" : "/"}${color}]`);
|
||||
continue;
|
||||
@@ -370,7 +426,7 @@ function renderColorTokens(tokens: ColorToken[]): string {
|
||||
const colors: string[] = [];
|
||||
for (const [color, colorStack] of colorMapStack) {
|
||||
if (colorStack.length > 0) {
|
||||
const currentColorCode = COLOR_MAP[color];
|
||||
const currentColorCode = getColorCode(color);
|
||||
if (currentColorCode) {
|
||||
colors.push(currentColorCode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user