color
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
// Reference:
|
// Reference:
|
||||||
// - https://docs.deno.com/runtime/fundamentals/testing/
|
// - https://docs.deno.com/runtime/fundamentals/testing/
|
||||||
|
|
||||||
import {decodeBase64, encodeBase64} from "jsr:@std/encoding/base64";
|
import { decodeBase64, encodeBase64 } from "jsr:@std/encoding/base64";
|
||||||
import {dirname, fromFileUrl} from "https://deno.land/std/path/mod.ts";
|
import { dirname, fromFileUrl } from "https://deno.land/std/path/mod.ts";
|
||||||
|
|
||||||
// reference: https://docs.deno.com/examples/hex_base64_encoding/
|
// reference: https://docs.deno.com/examples/hex_base64_encoding/
|
||||||
// import { decodeBase64, encodeBase64 } from "jsr:@std/encoding/base64";
|
// import { decodeBase64, encodeBase64 } from "jsr:@std/encoding/base64";
|
||||||
@@ -337,6 +337,11 @@ 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];
|
||||||
|
if (!colorCode) {
|
||||||
|
text.push(`[${token.colorStart ? "" : "/"}${color}]`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const colorStack = colorMapStack.get(color) ?? [];
|
const colorStack = colorMapStack.get(color) ?? [];
|
||||||
if (colorStack.length == 0) {
|
if (colorStack.length == 0) {
|
||||||
colorMapStack.set(color, colorStack);
|
colorMapStack.set(color, colorStack);
|
||||||
@@ -350,12 +355,9 @@ 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 colorCode = COLOR_MAP[color];
|
|
||||||
if (colorCode) {
|
|
||||||
colors.push(colorCode);
|
colors.push(colorCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (colors.length > 0) {
|
if (colors.length > 0) {
|
||||||
text.push(`\x1b[${colors.join(";")}m`);
|
text.push(`\x1b[${colors.join(";")}m`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
resolveFilename,
|
resolveFilename,
|
||||||
term,
|
term,
|
||||||
writeStringToFile,
|
writeStringToFile,
|
||||||
} from "https://global.hatter.ink/script/get/@18/deno-commons-mod.ts";
|
} from "https://global.hatter.ink/script/get/@27/deno-commons-mod.ts";
|
||||||
import {parseArgs} from "jsr:@std/cli/parse-args";
|
import {parseArgs} from "jsr:@std/cli/parse-args";
|
||||||
import {assertEquals} from "jsr:@std/assert";
|
import {assertEquals} from "jsr:@std/assert";
|
||||||
|
|
||||||
@@ -88,42 +88,18 @@ async function savePythonConfig(pythonConfig: PythonConfig): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleHelp(_args: string[]) {
|
function handleHelp(_args: string[]) {
|
||||||
const help = [];
|
const help =
|
||||||
help.push(
|
`[green]python.ts[/green] - Python version and virtual environment management tool
|
||||||
`${
|
|
||||||
term.green("python.ts")
|
|
||||||
} - Python version and virtual environment management tool
|
|
||||||
|
|
||||||
${term.green("python.ts")} ${
|
[green]python.ts[/green] [bold]python[/bold] - management python version [yellow]\\[alias: py, ver, version][/yellow]
|
||||||
term.bold("python")
|
[green]python.ts[/green] [bold]add-python[/bold] - add python version [yellow]\\[alias: add-py][/yellow]
|
||||||
} - management python version ${
|
[green]python.ts[/green] [bold]env[/bold] - management python virtual environment [yellow]\\[alias: env][/yellow]
|
||||||
term.yellow("[alias: py, ver, version]")
|
[green]python.ts[/green] [bold]add-venv[/bold] - add python virtual environment [yellow]\\[alias: add-env][/yellow]
|
||||||
}
|
[green]python.ts[/green] [bold]remove-venv[/bold] - remove python virtual environment [yellow]\\[alias: rm-venv, rm-env][/yellow]
|
||||||
${term.green("python.ts")} ${term.bold("add-python")} - add python version ${
|
[green]python.ts[/green] [bold]active-venv[/bold] - active python virtual environment [yellow]\\[alias: active, active-env][/yellow]`;
|
||||||
term.yellow("[alias: add-py]")
|
|
||||||
}
|
|
||||||
${term.green("python.ts")} ${
|
|
||||||
term.bold("venv")
|
|
||||||
} - management python virtual environment ${
|
|
||||||
term.yellow("[alias: env]")
|
|
||||||
}
|
|
||||||
${term.green("python.ts")} ${
|
|
||||||
term.bold("add-venv")
|
|
||||||
} - add python virtual environment ${term.yellow("[alias: add-env]")}
|
|
||||||
${term.green("python.ts")} ${
|
|
||||||
term.bold("remove-venv")
|
|
||||||
} - remove python virtual environment ${
|
|
||||||
term.yellow("[alias: rm-venv, rm-env]")
|
|
||||||
}
|
|
||||||
${term.green("python.ts")} ${
|
|
||||||
term.bold("active-venv")
|
|
||||||
} - active python virtual environment ${
|
|
||||||
term.yellow("[alias: active, active-env]")
|
|
||||||
}`,
|
|
||||||
);
|
|
||||||
// source <(cat ~/.venv-python-3.13.5/bin/activate)
|
// source <(cat ~/.venv-python-3.13.5/bin/activate)
|
||||||
// source <(python.ts venv test1)
|
// source <(python.ts venv test1)
|
||||||
console.log(help.join("\n"));
|
console.log(term.auto(help));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addVirtualEnv(
|
async function addVirtualEnv(
|
||||||
@@ -237,20 +213,24 @@ async function handlePython(args: string[]) {
|
|||||||
}
|
}
|
||||||
versions.sort(versionSort);
|
versions.sort(versionSort);
|
||||||
|
|
||||||
console.log(`Found ${versions.length} Python version(s)`);
|
console.log(
|
||||||
|
term.auto(
|
||||||
|
`Found [bold][green]${versions.length}[/green][/bold] Python version${
|
||||||
|
versions.length == 1 ? "" : "s"
|
||||||
|
}:`,
|
||||||
|
),
|
||||||
|
);
|
||||||
for (const version of versions) {
|
for (const version of versions) {
|
||||||
const pythonVersion = pythonConfig.versions[version];
|
const pythonVersion = pythonConfig.versions[version];
|
||||||
const versionPadding = " ".repeat(
|
const versionPadding = " ".repeat(
|
||||||
maxVersionLength - version.length,
|
maxVersionLength - version.length,
|
||||||
);
|
);
|
||||||
console.log(
|
console.log(
|
||||||
"-",
|
term.auto(
|
||||||
"version:",
|
`- version: [green][bold]${version}[/green][/bold]` +
|
||||||
term.green(term.bold(version)),
|
`; path: [blue]${pythonVersion.path}[/blue]` +
|
||||||
";path:",
|
`; comment: [yellow][under]${pythonVersion.comment}[/under][/yellow]`,
|
||||||
term.blue(pythonVersion.path),
|
),
|
||||||
";comment:",
|
|
||||||
term.yellow(term.under(pythonVersion.comment)),
|
|
||||||
);
|
);
|
||||||
// console.log("- Python:", version, pythonVersion,);
|
// console.log("- Python:", version, pythonVersion,);
|
||||||
}
|
}
|
||||||
@@ -361,7 +341,7 @@ python.ts venv [--name|-n filter-name]`);
|
|||||||
filterProfilesCount++;
|
filterProfilesCount++;
|
||||||
console.log(
|
console.log(
|
||||||
"-",
|
"-",
|
||||||
term.blue(term.bold(term.under(venv))),
|
term.auto(`[blue][under][bold]${venv}[/bold][/under][/blue]`),
|
||||||
term.yellow(
|
term.yellow(
|
||||||
pythonVenvProfile.alias
|
pythonVenvProfile.alias
|
||||||
? `[alias: ${pythonVenvProfile.alias.join(", ")}]`
|
? `[alias: ${pythonVenvProfile.alias.join(", ")}]`
|
||||||
@@ -546,5 +526,5 @@ Deno.test("versionSort", () => {
|
|||||||
assertEquals(["3.7", "3.10", "3.10.1", "3.11"], versions2);
|
assertEquals(["3.7", "3.10", "3.10.1", "3.11"], versions2);
|
||||||
});
|
});
|
||||||
|
|
||||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260127T224153+08:00.MEUCIQCuTKNb0y+N137tvQw+
|
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260205T232313+08:00.MEQCIHC9xGfzR6iiMjJjpPAc
|
||||||
// 47AFPWoCz5WaUSCJOUpcQBKDNwIgFxvsWvHCgWh5jpCjoQWURwLjAHsN9ze5K5X7KkVUuEM=
|
// lJ3lyEUT5a+7qLUml7HcEV6WAiA7ZZ5yUdtfk0J0zQBnam92VOHjYvH2sLrVBI/88vB1sQ==
|
||||||
|
|||||||
Reference in New Issue
Block a user