feat(tts): add --edit flag and fix CLI argument parsing

- Improved input trimming and console output formatting in `tts.ts`
- Updated codespan colors in the markdown renderer for better visual contrast
- Disabled `noPropertyAccessFromIndexSignature` in tsconfig.json
This commit is contained in:
mitchell 2026-06-08 16:09:28 -04:00
parent 39cb573619
commit a03e6e94a9
4 changed files with 35 additions and 13 deletions

View file

@ -8,7 +8,7 @@ import { Conversation } from "./src/conversation";
import Renderer from "./src/render"; import Renderer from "./src/render";
const { values: args, positionals } = parseArgs({ const { values: args, positionals } = parseArgs({
args: process.argv, args: process.argv.slice(2),
options: { options: {
model: { type: "string" }, model: { type: "string" },
m: { type: "string" }, m: { type: "string" },
@ -62,7 +62,7 @@ async function main() {
if (modelFlag) convo.model = modelFlag; if (modelFlag) convo.model = modelFlag;
} }
const prompt = positionals.slice(2).join(" ") || "Introduce yourself."; const prompt = positionals.join(" ") || "Introduce yourself.";
convo.messages.push({ role: "user", content: prompt }); convo.messages.push({ role: "user", content: prompt });
const { fullStream, text, totalUsage } = streamText({ const { fullStream, text, totalUsage } = streamText({

View file

@ -144,7 +144,7 @@ class LmcRenderer extends Renderer {
} }
override codespan({ text }: Tokens.Codespan) { override codespan({ text }: Tokens.Codespan) {
return chalk.bgRgb(192, 192, 192).black.bold(text); return chalk.bgRgb(192, 192, 192).rgb(24, 24, 24).bold(text);
} }
override link({ href, tokens }: Tokens.Link) { override link({ href, tokens }: Tokens.Link) {

View file

@ -23,12 +23,12 @@
"noUnusedLocals": true, "noUnusedLocals": true,
"noUnusedParameters": true, "noUnusedParameters": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"noPropertyAccessFromIndexSignature": true, "noPropertyAccessFromIndexSignature": false,
// Recommended Options // Recommended Options
"strict": true, "strict": true,
"jsx": "react-jsx", "jsx": "react-jsx",
//"allowImportingTsExtensions": true, "allowImportingTsExtensions": false,
"allowArbitraryExtensions": true, "allowArbitraryExtensions": true,
"verbatimModuleSyntax": true, "verbatimModuleSyntax": true,
"isolatedModules": true, "isolatedModules": true,

38
tts.ts
View file

@ -1,3 +1,4 @@
import fs from "node:fs/promises";
import os from "node:os"; import os from "node:os";
import process from "node:process"; import process from "node:process";
import { createInterface } from "node:readline"; import { createInterface } from "node:readline";
@ -18,6 +19,8 @@ async function main() {
w: { type: "boolean" }, w: { type: "boolean" },
url: { type: "string" }, url: { type: "string" },
u: { type: "string" }, u: { type: "string" },
edit: { type: "boolean" },
e: { type: "boolean" },
}, },
strict: true, strict: true,
allowPositionals: false, allowPositionals: false,
@ -25,6 +28,7 @@ async function main() {
const wait = args.wait ?? args.w; const wait = args.wait ?? args.w;
const url = args.url ?? args.u; const url = args.url ?? args.u;
const edit = args.edit ?? args.e;
let input = url let input = url
? url ? url
@ -34,16 +38,17 @@ async function main() {
process.stdin.on("data", (chunk) => (data += chunk)); process.stdin.on("data", (chunk) => (data += chunk));
process.stdin.on("end", () => resolve(data)); process.stdin.on("end", () => resolve(data));
}); });
input = input.trim();
if (url !== undefined) { if (url !== undefined) {
const result = await fetch(input.trim()); const result = await fetch(input);
const window = new Window({ url: input.trim() }); const window = new Window({ url: input });
const doc = window.document; const doc = window.document;
doc.write(await result.text()); doc.write(await result.text());
await window.happyDOM.waitUntilComplete(); await window.happyDOM.waitUntilComplete();
const readable = new Readability(doc).parse(); const readable = new Readability(doc).parse();
if (readable?.textContent) input = readable.textContent; if (readable?.textContent) input = readable.textContent.trim();
if (input.trim() === result.url) { if (input === result.url) {
console.error("Unable to read web page."); console.error("Unable to read web page.");
process.exit(1); process.exit(1);
} }
@ -59,6 +64,18 @@ async function main() {
await execa({ cwd, shell: true, reject: false })`rm *.wav`; await execa({ cwd, shell: true, reject: false })`rm *.wav`;
if (edit) {
const file = await fs.open(`${cwd}input.txt`, "w+");
await file.writeFile(input);
const editor = process.env.EDITOR || "nano";
await execa({
stdin: "inherit",
stdout: "inherit",
})`${editor} ${cwd}input.txt`;
input = await file.readFile("utf8");
await file.close();
}
console.log(chalk.blue("Welcome to TTSC!")); console.log(chalk.blue("Welcome to TTSC!"));
console.log( console.log(
chalk.yellow( chalk.yellow(
@ -107,9 +124,11 @@ async function main() {
const [columns] = process.stdout.getWindowSize(); const [columns] = process.stdout.getWindowSize();
const text = wrapAnsi(info.text, columns); const text = wrapAnsi(info.text, columns);
const file = `${home}/.ttsc/${info.file}.wav`; const file = `${home}/.ttsc/${info.file}.wav`;
console.log(`\n${chalk.blue(file)}:\n${text}\n`);
if (!wait) { if (wait) {
console.write(".");
} else {
console.log(`\n${chalk.blue(file)}\n${text}\n`);
await execa({ await execa({
cwd, cwd,
stdin: "ignore", stdin: "ignore",
@ -126,10 +145,9 @@ async function main() {
const duration = ((stop - start) / 1000).toFixed(2); const duration = ((stop - start) / 1000).toFixed(2);
console.log(chalk.green(`\nProcessing finished: ${duration}s`)); console.log(chalk.green(`\nProcessing finished: ${duration}s`));
console.log(chalk.yellow(`Combining audio with sox...`)); console.log(chalk.yellow(`Combining audio with sox...\n`));
try { try {
await execa({ cwd, shell: true })`sox *.wav output.wav`; await execa({ cwd, shell: true })`sox *.wav output.wav`;
console.log(chalk.green(`Playing audio from ${cwd}output.wav`));
} catch (err) { } catch (err) {
if (err instanceof Object && "code" in err && err.code === "ENOENT") { if (err instanceof Object && "code" in err && err.code === "ENOENT") {
console.error("Sox not found. Unable to combine outputs."); console.error("Sox not found. Unable to combine outputs.");
@ -140,6 +158,10 @@ async function main() {
process.exit(); process.exit();
} }
const [columns] = process.stdout.getWindowSize();
console.log(wrapAnsi(input, columns));
console.log(chalk.green(`Playing audio from ${cwd}output.wav`));
await execa({ await execa({
cwd, cwd,
stdin: "ignore", stdin: "ignore",