refactor: spinner handling and markdown line wrapping
This commit is contained in:
parent
9da57fe2fc
commit
5e733a4e14
2 changed files with 14 additions and 14 deletions
|
|
@ -89,18 +89,14 @@ export default class Renderer {
|
|||
this.resetCounts();
|
||||
|
||||
const spin = spinner({ withGuide: false, indicator: "timer" });
|
||||
let spinning = false;
|
||||
if (!this.isPlain) {
|
||||
spinning = true;
|
||||
spin.start("Waiting for response");
|
||||
}
|
||||
|
||||
for await (const part of stream) {
|
||||
switch (part.type) {
|
||||
case "reasoning-start": {
|
||||
if (spinning) {
|
||||
spin.clear();
|
||||
}
|
||||
if (supportsColorStderr)
|
||||
this.write(
|
||||
`${styles.dim.open}${styles.italic.open}`,
|
||||
|
|
@ -132,9 +128,7 @@ export default class Renderer {
|
|||
break;
|
||||
}
|
||||
case "text-start": {
|
||||
if (spinning) {
|
||||
spin.clear();
|
||||
}
|
||||
this.write("\n");
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,15 +46,19 @@ export async function renderMarkdown(
|
|||
chalk.greenBright,
|
||||
];
|
||||
const color = colors[level - 1] ?? chalk.white;
|
||||
return color.bold(`${"#".repeat(level)} ${children}\n\n`);
|
||||
return Bun.wrapAnsi(
|
||||
color.bold(`${"#".repeat(level)} ${children}\n\n`),
|
||||
columns,
|
||||
);
|
||||
},
|
||||
paragraph: (children) => `${children}\n\n`,
|
||||
paragraph: (children) => Bun.wrapAnsi(`${children}\n\n`, columns),
|
||||
blockquote: (children) => {
|
||||
const lines = children.split("\n");
|
||||
return lines
|
||||
const toRender = lines
|
||||
.map((line) => `${chalk.dim("> ")}${line}`)
|
||||
.join("\n")
|
||||
.replace(/\n$/, "\n\n");
|
||||
return Bun.wrapAnsi(toRender, columns);
|
||||
},
|
||||
code: (children, meta) => {
|
||||
let toRender = children;
|
||||
|
|
@ -73,7 +77,10 @@ export async function renderMarkdown(
|
|||
return `\`\`\`${chalk.blue(meta?.language ?? "")}\n${toRender}\`\`\`\n`;
|
||||
},
|
||||
list: (children, { depth }) =>
|
||||
Bun.wrapAnsi(
|
||||
`${depth > 0 ? "\n" : ""}${children.trimEnd()}${depth === 0 ? "\n\n" : ""}`,
|
||||
columns,
|
||||
),
|
||||
listItem: (children, { index, depth, ordered, start, checked }) => {
|
||||
const indent = " ".repeat(depth);
|
||||
let marker = "";
|
||||
|
|
@ -119,6 +126,5 @@ export async function renderMarkdown(
|
|||
html: () => "",
|
||||
});
|
||||
|
||||
const replaced = rendered.replace(/\n\n$/, "\n");
|
||||
return Bun.wrapAnsi(replaced, columns, { trim: false });
|
||||
return rendered.replace(/\n\n$/, "\n");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue