🔧 Update color rendering logic and upgrade script dependencies
This commit is contained in:
@@ -414,7 +414,7 @@ interface ColorToken {
|
|||||||
color?: string;
|
color?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseColorTokens(message: string, renderColor: boolean): ColorToken[] {
|
function parseColorTokens(message: string): ColorToken[] {
|
||||||
const tokens: ColorToken[] = [];
|
const tokens: ColorToken[] = [];
|
||||||
if (message) {
|
if (message) {
|
||||||
let inColorStart = false;
|
let inColorStart = false;
|
||||||
@@ -588,11 +588,11 @@ function __getColorCode(color: string): string {
|
|||||||
return COLOR_MAP[color];
|
return COLOR_MAP[color];
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderColorTokens(tokens: ColorToken[]): string {
|
function renderColorTokens(tokens: ColorToken[], renderColor: bool): string {
|
||||||
const text: string[] = [];
|
const text: string[] = [];
|
||||||
const colorMapStack = new Map<string, number[]>();
|
const colorMapStack = new Map<string, number[]>();
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
if (token.type === "color") {
|
if (token.type === "color" && renderColor) {
|
||||||
const color = token.color;
|
const color = token.color;
|
||||||
if (color) {
|
if (color) {
|
||||||
const colorCode = __getColorCode(color);
|
const colorCode = __getColorCode(color);
|
||||||
@@ -629,7 +629,7 @@ function renderColorTokens(tokens: ColorToken[]): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text.push("\x1b[0m"); // FINALLY END ALL COLOR
|
renderColor && text.push("\x1b[0m"); // FINALLY END ALL COLOR
|
||||||
return text.join("");
|
return text.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -322,12 +322,12 @@
|
|||||||
},
|
},
|
||||||
"tree.ts": {
|
"tree.ts": {
|
||||||
"script_name": "tree.ts",
|
"script_name": "tree.ts",
|
||||||
"script_length": 2773,
|
"script_length": 2855,
|
||||||
"script_sha256": "269af8218f226dd722ebce67eaa7acfc83cec4400bf1c047ebb0cbddc364ab58",
|
"script_sha256": "7df6c0ead4d18499c3318eb5e7b638ef535b6a05930a3ae13f1a4e554d9e9dc7",
|
||||||
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/tree.ts",
|
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/tree.ts",
|
||||||
"single_script_file": true,
|
"single_script_file": true,
|
||||||
"publish_time": 1769361581018,
|
"publish_time": 1769361581018,
|
||||||
"update_time": 1769705771521
|
"update_time": 1775868785446
|
||||||
},
|
},
|
||||||
"trim.ts": {
|
"trim.ts": {
|
||||||
"script_name": "trim.ts",
|
"script_name": "trim.ts",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
log,
|
log,
|
||||||
parseIntVal,
|
parseIntVal,
|
||||||
term,
|
term,
|
||||||
} from "https://global.hatter.ink/script/get/@21/deno-commons-mod.ts";
|
} from "https://global.hatter.ink/script/get/@70/deno-commons-mod.ts";
|
||||||
import {parseArgs} from "jsr:@std/cli/parse-args";
|
import {parseArgs} from "jsr:@std/cli/parse-args";
|
||||||
|
|
||||||
const defaultSkipDirs = [
|
const defaultSkipDirs = [
|
||||||
@@ -35,7 +35,7 @@ async function listDir(
|
|||||||
const showNextDepth = (depth + 1) <= maxDepth;
|
const showNextDepth = (depth + 1) <= maxDepth;
|
||||||
console.log(
|
console.log(
|
||||||
`${tab}- [${dirEntry.name}]${
|
`${tab}- [${dirEntry.name}]${
|
||||||
showNextDepth ? "" : term.blue(" \t[...more dirs...]")
|
showNextDepth ? "" : term.auto("[blue][[[ \t[...more dirs...]]]][/]")
|
||||||
}`,
|
}`,
|
||||||
);
|
);
|
||||||
if (showNextDepth) {
|
if (showNextDepth) {
|
||||||
@@ -48,22 +48,22 @@ async function listDir(
|
|||||||
} else if (dirEntry.isFile) {
|
} else if (dirEntry.isFile) {
|
||||||
const fileInfo = await Deno.stat(fullName);
|
const fileInfo = await Deno.stat(fullName);
|
||||||
if (fileInfo.size > 1024 * 1024) {
|
if (fileInfo.size > 1024 * 1024) {
|
||||||
fileDesc = term.red(
|
fileDesc = term.auto(
|
||||||
` - ${formatSize2(fileInfo.size)}`,
|
`[red][[[ - ${formatSize2(fileInfo.size)}]]]][/]`,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
fileDesc = term.yellow(
|
fileDesc = term.auto(
|
||||||
` - ${formatSize2(fileInfo.size)}`,
|
`[yellow][[[ - ${formatSize2(fileInfo.size)}]]][/]`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(
|
console.log(
|
||||||
`${tab}- ${term.green(dirEntry.name)} \t${fileDesc}`,
|
`${tab}- ${term.auto("[green][[["+dirEntry.name+"]]][/]")} \t${fileDesc}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(term.red(`${tab} ERROR: ${e}`));
|
console.log(term.auto(`[red][[[${tab} ERROR: ${e}]]][/]`));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,5 +93,5 @@ tree.ts [parameters] <dir>
|
|||||||
|
|
||||||
main().catch((e) => log.error(e));
|
main().catch((e) => log.error(e));
|
||||||
|
|
||||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260130T005327+08:00.MEUCICFLf8ZlGN4bSzCiRBlW
|
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260411T085252+08:00.MEQCIF2mljiVKgw/oBHggTcd
|
||||||
// AnPVvd4by4hrwq6ZZPaN/cY6AiEAtyx0B6/EINNU2ilPoY1g0+LGc5FylLEJ5Ybn+pkpn8I=
|
// bIyoWblVNdk8NxsEqMsxUqFMAiBVZKjn/XaZOPwpluv8wOlRtl/FqZZ3fmPj3YgGjVNjsg==
|
||||||
|
|||||||
Reference in New Issue
Block a user