refactor: simplify renderer drain handling and expand LaTeX arrow replacements
This commit is contained in:
parent
7367cfdfe3
commit
0ed6a23334
2 changed files with 10 additions and 16 deletions
|
|
@ -13,7 +13,6 @@ import { renderMarkdown } from "./markdown";
|
||||||
export default class Renderer {
|
export default class Renderer {
|
||||||
private lineCount = 0;
|
private lineCount = 0;
|
||||||
private charsSinceNL = 0;
|
private charsSinceNL = 0;
|
||||||
private memOk = true;
|
|
||||||
private buffer = "";
|
private buffer = "";
|
||||||
private unsafeIndex = 0;
|
private unsafeIndex = 0;
|
||||||
private start = 0;
|
private start = 0;
|
||||||
|
|
@ -22,22 +21,15 @@ export default class Renderer {
|
||||||
constructor(
|
constructor(
|
||||||
private isPlain = false,
|
private isPlain = false,
|
||||||
private isPlainErr = false,
|
private isPlainErr = false,
|
||||||
) {
|
) {}
|
||||||
process.stdout.addListener("drain", () => {
|
|
||||||
this.memOk = true;
|
|
||||||
});
|
|
||||||
process.stderr.addListener("drain", () => {
|
|
||||||
this.memOk = true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private write(text: string, pipe: WriteStream = process.stdout) {
|
private write(text: string, pipe: WriteStream = process.stdout) {
|
||||||
this.memOk = pipe.write(text);
|
pipe.write(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private moveClearReset(y: number, pipe: WriteStream = process.stdout) {
|
private moveClearReset(y: number, pipe: WriteStream = process.stdout) {
|
||||||
this.memOk = pipe.moveCursor(-9999, y);
|
pipe.moveCursor(-9999, y);
|
||||||
this.memOk = pipe.clearScreenDown();
|
pipe.clearScreenDown();
|
||||||
this.resetCounts();
|
this.resetCounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,8 +151,6 @@ export default class Renderer {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!this.memOk) await Bun.sleep(10);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -152,8 +152,12 @@ export async function renderMarkdown(
|
||||||
image: () => chalk.red("Images are unsupported (for now)\n"),
|
image: () => chalk.red("Images are unsupported (for now)\n"),
|
||||||
text: (children) =>
|
text: (children) =>
|
||||||
children
|
children
|
||||||
.replaceAll("$\\rightarrow$", "->")
|
.replaceAll("$\\rightarrow$", "-->")
|
||||||
.replaceAll("$\\leftarrow$", "<-")
|
.replaceAll("$\\leftarrow$", "<--")
|
||||||
|
.replaceAll("$\\leftrightarrow$", "<->")
|
||||||
|
.replaceAll("$\\Rightarrow$", "==>")
|
||||||
|
.replaceAll("$\\Leftarrow$", "<==")
|
||||||
|
.replaceAll("$\\Leftrightarrow$", "<=>")
|
||||||
.replaceAll("$\\to$", "->"),
|
.replaceAll("$\\to$", "->"),
|
||||||
html: () => chalk.red("HTML is unsupported\n"),
|
html: () => chalk.red("HTML is unsupported\n"),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue