feat: add chalk styling for terminal output
This commit is contained in:
parent
4bbe1a38d4
commit
712666255a
4 changed files with 21 additions and 5 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue