@@ -41,12 +41,15 @@ This is a longer paragraph that should cause terminal wrapping when the terminal
4141
4242 const delay = (ms: number) => new Promise((r) => setTimeout(r, ms));
4343
44-async function main() {
44+async function streamWithPrefix(prefix: string, text: string) {
4545 const highlighter = createHighlighter({ theme: "truecolor" });
4646
47+ // Write the prefix directly — it's not part of the highlighter output
48+ process.stdout.write(prefix);
49+
4750 // Stream character by character with a small delay to make it visible
48- for (let i = 0; i < markdown.length; i++) {
49- const output = highlighter.write(markdown[i]!);
51+ for (let i = 0; i < text.length; i++) {
52+ const output = highlighter.write(text[i]!);
5053 if (output) process.stdout.write(output);
5154 await delay(8);
5255 }
@@ -58,4 +61,35 @@ async function main() {
5861 process.stdout.write("\n");
5962 }
6063
64+async function main() {
65+ // 1. Standard full-document streaming
66+ const highlighter = createHighlighter({ theme: "truecolor" });
67+
68+ for (let i = 0; i < markdown.length; i++) {
69+ const output = highlighter.write(markdown[i]!);
70+ if (output) process.stdout.write(output);
71+ await delay(8);
72+ }
73+
74+ const final = highlighter.end();
75+ if (final) process.stdout.write(final);
76+ process.stdout.write("\n");
77+
78+ // 2. Inline prefix preservation — short line (should NOT erase prefix)
79+ await streamWithPrefix("AI: ", "Here is some **bold** and *italic* text.");
80+
81+ // 3. Inline prefix preservation — long line that wraps
82+ await streamWithPrefix(
83+ "Assistant: ",
84+ "This is a much longer response that should wrap across multiple terminal lines to test the edge case where cursor-back might overshoot past the prefix on the first visual line.",
85+ );
86+
87+ // 4. Multiple prefixed responses in sequence
88+ await streamWithPrefix("Q: ", "What is `yoctomarkdown`?");
89+ await streamWithPrefix(
90+ "A: ",
91+ "A **tiny** streaming markdown highlighter for the terminal.",
92+ );
93+}
94+
6195 main();