feat: add chalk styling for terminal output

This commit is contained in:
mitchell 2026-04-17 00:13:17 -04:00
parent 4bbe1a38d4
commit 712666255a
4 changed files with 21 additions and 5 deletions

View file

@ -1,5 +1,7 @@
import os from "node:os";
import type { AsyncIterableStream, TextStreamPart, ToolSet } from "ai";
import styles from "ansi-styles";
import { supportsColor } from "chalk";
const home = os.homedir();
const reasoningWriter = Bun.file(`${home}/.aicl_reasoning.md`).writer();
@ -56,14 +58,17 @@ export default class StreamRenderer {
for await (const part of stream) {
if (part.type === "reasoning-start") {
this.write("\u001b[2m\u001b[3m\n");
if (supportsColor)
this.write(`${styles.dim.open}${styles.italic.open}`);
this.write("\n");
} else if (part.type === "reasoning-delta") {
this.write(part.text);
reasoningWriter.write(part.text);
this.checkContainment(part.text);
} else if (part.type === "reasoning-end") {
this.write("\n\u001b[22m\u001b[23m");
this.moveCursor(0, -this.lineCount - 2);
if (supportsColor)
this.write(`${styles.italic.close}${styles.dim.close}`);
this.moveCursor(0, -this.lineCount - 1);
this.clearScreenDown();
this.resetCounts();
reasoningWriter.end();