updates ssh.ts
This commit is contained in:
@@ -252,6 +252,7 @@ function parseColorTokens(message: string, renderColor: boolean): ColorToken[] {
|
|||||||
if (message) {
|
if (message) {
|
||||||
let inColorStart = false;
|
let inColorStart = false;
|
||||||
let inColorEnd = false;
|
let inColorEnd = false;
|
||||||
|
let noEscape = false;
|
||||||
let chars: string[] = [];
|
let chars: string[] = [];
|
||||||
let startedColors: string[] = [];
|
let startedColors: string[] = [];
|
||||||
const messageLength = message.length;
|
const messageLength = message.length;
|
||||||
@@ -260,6 +261,19 @@ function parseColorTokens(message: string, renderColor: boolean): ColorToken[] {
|
|||||||
const nextC = (i + 1) < messageLength
|
const nextC = (i + 1) < messageLength
|
||||||
? message.charAt(i + 1)
|
? message.charAt(i + 1)
|
||||||
: null;
|
: 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) {
|
switch (c) {
|
||||||
case "\\":
|
case "\\":
|
||||||
if (nextC === null) {
|
if (nextC === null) {
|
||||||
@@ -276,6 +290,11 @@ function parseColorTokens(message: string, renderColor: boolean): ColorToken[] {
|
|||||||
} else if (nextC == "/") {
|
} else if (nextC == "/") {
|
||||||
inColorEnd = true;
|
inColorEnd = true;
|
||||||
i++;
|
i++;
|
||||||
|
} else if (nextC == "[" && nextNexC == "[") {
|
||||||
|
// now no escape
|
||||||
|
noEscape = true;
|
||||||
|
i += 2;
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
inColorStart = true;
|
inColorStart = true;
|
||||||
}
|
}
|
||||||
@@ -337,14 +356,51 @@ const COLOR_MAP: Record<string, string> = {
|
|||||||
blink: "5",
|
blink: "5",
|
||||||
bold: "1",
|
bold: "1",
|
||||||
under: "4",
|
under: "4",
|
||||||
|
|
||||||
|
black: "30",
|
||||||
red: "31",
|
red: "31",
|
||||||
green: "32",
|
green: "32",
|
||||||
yellow: "33",
|
yellow: "33",
|
||||||
blue: "34",
|
blue: "34",
|
||||||
pink: "35",
|
pink: "35",
|
||||||
cyan: "36",
|
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 {
|
function renderColorTokens(tokens: ColorToken[]): string {
|
||||||
const text: string[] = [];
|
const text: string[] = [];
|
||||||
const colorMapStack = new Map<string, number[]>();
|
const colorMapStack = new Map<string, number[]>();
|
||||||
@@ -352,7 +408,7 @@ function renderColorTokens(tokens: ColorToken[]): string {
|
|||||||
if (token.type === "color") {
|
if (token.type === "color") {
|
||||||
const color = token.color;
|
const color = token.color;
|
||||||
if (color) {
|
if (color) {
|
||||||
const colorCode = COLOR_MAP[color];
|
const colorCode = getColorCode(color);
|
||||||
if (!colorCode) {
|
if (!colorCode) {
|
||||||
text.push(`[${token.colorStart ? "" : "/"}${color}]`);
|
text.push(`[${token.colorStart ? "" : "/"}${color}]`);
|
||||||
continue;
|
continue;
|
||||||
@@ -370,7 +426,7 @@ function renderColorTokens(tokens: ColorToken[]): string {
|
|||||||
const colors: string[] = [];
|
const colors: string[] = [];
|
||||||
for (const [color, colorStack] of colorMapStack) {
|
for (const [color, colorStack] of colorMapStack) {
|
||||||
if (colorStack.length > 0) {
|
if (colorStack.length > 0) {
|
||||||
const currentColorCode = COLOR_MAP[color];
|
const currentColorCode = getColorCode(color);
|
||||||
if (currentColorCode) {
|
if (currentColorCode) {
|
||||||
colors.push(currentColorCode);
|
colors.push(currentColorCode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import {parseArgs} from "node:util";
|
import {parseArgs} from "node:util";
|
||||||
|
|
||||||
import {execCommandShell, log, readFileToString, term,} from "https://script.hatter.ink/@29/deno-commons-mod.ts";
|
import {execCommandShell, log, readFileToString, term,} from "https://script.hatter.ink/@32/deno-commons-mod.ts";
|
||||||
import JSON5 from "npm:json5";
|
import JSON5 from "npm:json5";
|
||||||
|
|
||||||
class SshTsArgs {
|
class SshTsArgs {
|
||||||
@@ -49,7 +49,11 @@ function printSshConfig(sshConfig: SshConfig) {
|
|||||||
maxProfileHostLength = sshProfile.host.length;
|
maxProfileHostLength = sshProfile.host.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(term.auto("[green][OK ][/green] Total 10 server(s):"));
|
console.log(
|
||||||
|
term.auto(
|
||||||
|
`[green]\\[OK ][/] Total [bold]${allProfiles.length}[/] server(s):`,
|
||||||
|
),
|
||||||
|
);
|
||||||
allProfiles.sort((a, b) => a.localeCompare(b));
|
allProfiles.sort((a, b) => a.localeCompare(b));
|
||||||
for (let i = 0; i < allProfiles.length; i++) {
|
for (let i = 0; i < allProfiles.length; i++) {
|
||||||
const k = allProfiles[i];
|
const k = allProfiles[i];
|
||||||
@@ -57,7 +61,7 @@ function printSshConfig(sshConfig: SshConfig) {
|
|||||||
const features = [];
|
const features = [];
|
||||||
if (sshProfile.proxy) features.push("proxy");
|
if (sshProfile.proxy) features.push("proxy");
|
||||||
if (sshProfile.forward_agent) features.push("forward_agent");
|
if (sshProfile.forward_agent) features.push("forward_agent");
|
||||||
const nameWithPad = `${k}${
|
const nameWithPad = `[bold]${k}[/]${
|
||||||
" ".repeat(maxProfileNameLength - k.length)
|
" ".repeat(maxProfileNameLength - k.length)
|
||||||
}`;
|
}`;
|
||||||
const hostWithPad = `${sshProfile.host}${
|
const hostWithPad = `${sshProfile.host}${
|
||||||
@@ -69,7 +73,7 @@ function printSshConfig(sshConfig: SshConfig) {
|
|||||||
: "aliases"
|
: "aliases"
|
||||||
}: [${(sshProfile.alias && sshProfile.alias.join(", ")) || ""}]`;
|
}: [${(sshProfile.alias && sshProfile.alias.join(", ")) || ""}]`;
|
||||||
console.log(term.auto(
|
console.log(term.auto(
|
||||||
`- ${nameWithPad} : [blue]${hostWithPad}[/blue] [yellow]${alias}[/yellow] # ${sshProfile.comment}${
|
`- ${nameWithPad} : [blue][[[${hostWithPad}]]][/] [yellow][[[${alias}]]][/] # ${sshProfile.comment}${
|
||||||
(features.length > 0) ? (" ;[" + features.join(" ") + "]") : ""
|
(features.length > 0) ? (" ;[" + features.join(" ") + "]") : ""
|
||||||
}`,
|
}`,
|
||||||
));
|
));
|
||||||
@@ -80,7 +84,9 @@ function printSshConfig(sshConfig: SshConfig) {
|
|||||||
if (sshConfig.default_proxy) features.push("proxy");
|
if (sshConfig.default_proxy) features.push("proxy");
|
||||||
if (sshConfig.default_forward_agent) features.push("forward_agent");
|
if (sshConfig.default_forward_agent) features.push("forward_agent");
|
||||||
console.log();
|
console.log();
|
||||||
log.info(`Global default features: [${features.join(" ")}]`);
|
log.info(
|
||||||
|
term.auto(`Global default features: [[[[${features.join(" ")}]]]]`),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,20 +200,21 @@ async function main() {
|
|||||||
sshConfig.default_username || "root";
|
sshConfig.default_username || "root";
|
||||||
sshArgs.push(`${sshUsername}@${sshProfile.host}`);
|
sshArgs.push(`${sshUsername}@${sshProfile.host}`);
|
||||||
|
|
||||||
console.log(
|
const joinedSshArgs = sshArgs.map((arg) => {
|
||||||
term.auto(`[green][OK ][/green] ${sshCommand} ${
|
|
||||||
sshArgs.map((arg) => {
|
|
||||||
if (arg.includes(" ")) {
|
if (arg.includes(" ")) {
|
||||||
return `"${arg}"`;
|
return `"${arg}"`;
|
||||||
} else {
|
} else {
|
||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
}).join(" ")
|
}).join(" ");
|
||||||
}`),
|
console.log(
|
||||||
|
term.auto(
|
||||||
|
`[green]\\[OK ][/] [bold][blue][[[${sshCommand}]]][/][/] [yellow][[[${joinedSshArgs}]]][/]`,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
await execCommandShell(sshCommand, sshArgs);
|
await execCommandShell(sshCommand, sshArgs);
|
||||||
}
|
}
|
||||||
await main();
|
await main();
|
||||||
|
|
||||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260207T015534+08:00.MEYCIQDrK2IaMQnSL1d0Z+jd
|
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260208T142616+08:00.MEYCIQDb99eHtM0E2g2/SJc2
|
||||||
// G9+7qDQzyNxCR2N18b/+3lHjHQIhAM/Om/+Z6qoK2hiX84idYKeHc/JmizWUi/yqxI+xcvWl
|
// cLX9TpTZIY6WFl1hR0F9E3RmhwIhAJMoT77cJYjJwvLySwe8QYzGrpWHe4ROBIdRXiQERNMT
|
||||||
|
|||||||
Reference in New Issue
Block a user