| ... | @@ -131,10 +131,27 @@ export function bgRgb(r: number, g: number, b: number): string { | ... | @@ -131,10 +131,27 @@ export function bgRgb(r: number, g: number, b: number): string { |
| 131 | | 131 | |
| 132 | // cursor management | 132 | // cursor management |
| 133 | | 133 | |
| | 134 | /** save the position of the cursor, restored with {@linkcode cursorRestore}. */ |
| | 135 | export const cursorSave: string = "\x1b7"; |
| | 136 | /** restore the position of the cursor, saved with {@linkcode cursorSave}. */ |
| | 137 | export const cursorRestore: string = "\x1b8"; |
| | 138 | |
| 134 | /** move the cursor up `n` units. */ | 139 | /** move the cursor up `n` units. */ |
| 135 | export function cursorUp(n: number): string { | 140 | export function cursorUp(n: number): string { |
| 136 | return n ? `\x1b[${n}A` : ""; | 141 | return n ? `\x1b[${n}A` : ""; |
| 137 | } | 142 | } |
| | 143 | /** move the cursor down `n` units. */ |
| | 144 | export function cursorDown(n: number): string { |
| | 145 | return n ? `\x1b[${n}B` : ""; |
| | 146 | } |
| | 147 | /** move the cursor right `n` units. */ |
| | 148 | export function cursorRight(n: number): string { |
| | 149 | return n ? `\x1b[${n}C` : ""; |
| | 150 | } |
| | 151 | /** move the cursor right `n` units. */ |
| | 152 | export function cursorLeft(n: number): string { |
| | 153 | return n ? `\x1b[${n}D` : ""; |
| | 154 | } |
| 138 | /** move the cursor to the start of it's current line. */ | 155 | /** move the cursor to the start of it's current line. */ |
| 139 | export const startOfLine: string = "\r"; | 156 | export const startOfLine: string = "\r"; |
| 140 | /** move the cursor to the start of the next line. */ | 157 | /** move the cursor to the start of the next line. */ |
| ... | @@ -211,7 +228,8 @@ export function debugAnsi(text: string): string { | ... | @@ -211,7 +228,8 @@ export function debugAnsi(text: string): string { |
| 211 | "fgMagenta", "fgWhite", "fgBrightBlack", "fgBrightRed", | 228 | "fgMagenta", "fgWhite", "fgBrightBlack", "fgBrightRed", |
| 212 | "fgBrightGreen", "fgBrightYellow", "fgBrightBlue", "fgBrightMagenta", | 229 | "fgBrightGreen", "fgBrightYellow", "fgBrightBlue", "fgBrightMagenta", |
| 213 | "fgBrightCyan", "fgBrightWhite", "clearToEndOfLine", "clearToStartOfLine", | 230 | "fgBrightCyan", "fgBrightWhite", "clearToEndOfLine", "clearToStartOfLine", |
| 214 | "clearFullLine", "syncStart", "syncEnd", "bold", "dim", "resetWeight" | 231 | "clearFullLine", "syncStart", "syncEnd", "bold", "dim", "resetWeight", |
| | 232 | "cursorSave", "cursorRestore" |
| 215 | ]; | 233 | ]; |
| 216 | for (const key of verbaitim) { | 234 | for (const key of verbaitim) { |
| 217 | text = text.replaceAll( | 235 | text = text.replaceAll( |
| ... | @@ -220,6 +238,9 @@ export function debugAnsi(text: string): string { | ... | @@ -220,6 +238,9 @@ export function debugAnsi(text: string): string { |
| 220 | ); | 238 | ); |
| 221 | } | 239 | } |
| 222 | text = text.replace(/\x1b\[(\d+)A/g, style(fgYellow, "$${cursorUp($1)}")); | 240 | text = text.replace(/\x1b\[(\d+)A/g, style(fgYellow, "$${cursorUp($1)}")); |
| | 241 | text = text.replace(/\x1b\[(\d+)B/g, style(fgYellow, "$${cursorDown($1)}")); |
| | 242 | text = text.replace(/\x1b\[(\d+)C/g, style(fgYellow, "$${cursorRight($1)}")); |
| | 243 | text = text.replace(/\x1b\[(\d+)D/g, style(fgYellow, "$${cursorLeft($1)}")); |
| 223 | text = text.replace(/\n/g, style(fgRed, "\\n")); | 244 | text = text.replace(/\n/g, style(fgRed, "\\n")); |
| 224 | text = text.replace(/\r/g, style(fgMagenta, "\\r")); | 245 | text = text.replace(/\r/g, style(fgMagenta, "\\r")); |
| 225 | return text; | 246 | return text; |