diff --git a/index.ts b/index.ts index 35c5ec7..e7c52a3 100644 --- a/index.ts +++ b/index.ts @@ -2,35 +2,37 @@ import util from "node:util"; import { createOpenAICompatible } from "@ai-sdk/openai-compatible"; import { streamText } from "ai"; +import chalk from "chalk"; +import wrapAnsi from "wrap-ansi"; import { initConfig, loadConfig } from "./src/config"; import { Conversation } from "./src/conversation"; import Renderer from "./src/render"; -const { values: args, positionals } = util.parseArgs({ - args: process.argv.slice(2), - options: { - model: { type: "string" }, - m: { type: "string" }, - new: { type: "boolean" }, - n: { type: "boolean" }, - config: { type: "boolean" }, - c: { type: "boolean" }, - plain: { type: "boolean" }, - "plain-out": { type: "boolean" }, - "plain-err": { type: "boolean" }, - version: { type: "boolean" }, - v: { type: "boolean" }, - "git-message": { type: "boolean" }, - g: { type: "boolean" }, - review: { type: "boolean" }, - r: { type: "boolean" }, - }, - strict: true, - allowPositionals: true, -}); - async function main() { + const { values: args, positionals } = util.parseArgs({ + args: process.argv.slice(2), + options: { + model: { type: "string" }, + m: { type: "string" }, + new: { type: "boolean" }, + n: { type: "boolean" }, + config: { type: "boolean" }, + c: { type: "boolean" }, + plain: { type: "boolean" }, + "plain-out": { type: "boolean" }, + "plain-err": { type: "boolean" }, + version: { type: "boolean" }, + v: { type: "boolean" }, + "git-message": { type: "boolean" }, + g: { type: "boolean" }, + review: { type: "boolean" }, + r: { type: "boolean" }, + }, + strict: true, + allowPositionals: true, + }); + const newConvo = args.new ?? args.n; const plainOut = args["plain-out"] ?? args.plain ?? !process.stdout.isTTY; const plainErr = args["plain-err"] ?? args.plain ?? !process.stderr.isTTY; @@ -103,6 +105,9 @@ Review the above diff for any potential bugs, best practices, performance issues } main().catch((err) => { - console.error(err); + if ("message" in err) { + const [columns] = process.stderr.getWindowSize(); + console.error(wrapAnsi(chalk.red(err.message), columns)); + } else console.log(err); process.exit(1); }); diff --git a/tts.ts b/tts.ts index 94cce7b..06d3693 100644 --- a/tts.ts +++ b/tts.ts @@ -180,6 +180,9 @@ async function main() { } main().catch((err) => { - console.error(err); + if ("message" in err) { + const [columns] = process.stderr.getWindowSize(); + console.error(wrapAnsi(chalk.red(err.message), columns)); + } else console.log(err); process.exit(1); });