feat: separate plain output flags for stdout and stderr
This commit is contained in:
parent
9d599d98bf
commit
cdfafc9d5f
2 changed files with 23 additions and 9 deletions
11
index.ts
11
index.ts
|
|
@ -15,7 +15,8 @@ const { values: args, positionals } = parseArgs({
|
|||
save: { type: "boolean" },
|
||||
s: { type: "boolean" },
|
||||
plain: { type: "boolean" },
|
||||
p: { type: "boolean" },
|
||||
plainOut: { type: "boolean" },
|
||||
plainErr: { type: "boolean" },
|
||||
},
|
||||
strict: true,
|
||||
allowPositionals: true,
|
||||
|
|
@ -27,7 +28,8 @@ const configFile = Bun.file(`${home}/.aicl_config.json`);
|
|||
|
||||
async function main() {
|
||||
const newConvo = args.new ?? args.n;
|
||||
const plain = args.plain ?? args.p ?? !process.stdout.isTTY;
|
||||
const plainOut = args.plainOut ?? args.plain ?? !process.stdout.isTTY;
|
||||
const plainErr = args.plainErr ?? args.plain ?? !process.stderr.isTTY;
|
||||
let saveConfig = args.save ?? args.s;
|
||||
|
||||
let config: { model?: string };
|
||||
|
|
@ -47,9 +49,10 @@ async function main() {
|
|||
|
||||
if (saveConfig) {
|
||||
await configFile.write(JSON.stringify(config, null, " "));
|
||||
return;
|
||||
}
|
||||
|
||||
const renderer = new Renderer(plain);
|
||||
const renderer = new Renderer(plainOut, plainErr);
|
||||
|
||||
const provider = createOpenAICompatible({
|
||||
name: "llama.cpp",
|
||||
|
|
@ -88,7 +91,7 @@ async function main() {
|
|||
convo.messages.push({ role: "assistant", content: await text });
|
||||
await convoFile.write(JSON.stringify(convo));
|
||||
|
||||
if (!plain) {
|
||||
if (!plainOut) {
|
||||
const [width] = process.stdout.getWindowSize();
|
||||
await Bun.spawn({
|
||||
cmd: ["glow", "-w", `${width}`, "-"],
|
||||
|
|
|
|||
|
|
@ -18,7 +18,10 @@ export default class Renderer {
|
|||
private charsSinceNL = 0;
|
||||
private memOk = true;
|
||||
|
||||
constructor(private isPlain = false) {
|
||||
constructor(
|
||||
private isPlain = false,
|
||||
private isPlainErr = false,
|
||||
) {
|
||||
process.stdout.addListener("drain", () => {
|
||||
this.memOk = true;
|
||||
});
|
||||
|
|
@ -73,25 +76,33 @@ export default class Renderer {
|
|||
`${styles.dim.open}${styles.italic.open}`,
|
||||
process.stderr,
|
||||
);
|
||||
|
||||
this.write("\n", process.stderr);
|
||||
reasoningFile.write("");
|
||||
break;
|
||||
}
|
||||
case "reasoning-delta": {
|
||||
this.write(part.text, process.stderr);
|
||||
if (!this.isPlainErr)
|
||||
this.checkContainment(part.text, process.stderr);
|
||||
reasoningWriter.write(part.text);
|
||||
break;
|
||||
}
|
||||
case "reasoning-end": {
|
||||
if (!this.isPlainErr) {
|
||||
this.moveCursor(-this.lineCount - 1, process.stderr);
|
||||
this.clearScreenDown(process.stderr);
|
||||
this.resetCounts();
|
||||
} else {
|
||||
this.write("\n--- Done Thinking ---\n", process.stderr);
|
||||
}
|
||||
|
||||
if (supportsColorStderr)
|
||||
this.write(
|
||||
`${styles.italic.close}${styles.dim.close}`,
|
||||
process.stderr,
|
||||
);
|
||||
this.moveCursor(-this.lineCount - 1, process.stderr);
|
||||
this.clearScreenDown(process.stderr);
|
||||
this.resetCounts();
|
||||
|
||||
reasoningWriter.end();
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue