| ... | ... | @@ -131,10 +131,27 @@ export function bgRgb(r: number, g: number, b: number): string { |
| 131 | 131 | |
| 132 | 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 | 139 | /** move the cursor up `n` units. */ |
| 135 | 140 | export function cursorUp(n: number): string { |
| 136 | 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 | 155 | /** move the cursor to the start of it's current line. */ |
| 139 | 156 | export const startOfLine: string = "\r"; |
| 140 | 157 | /** move the cursor to the start of the next line. */ |
| ... | ... | @@ -211,7 +228,8 @@ export function debugAnsi(text: string): string { |
| 211 | 228 | "fgMagenta", "fgWhite", "fgBrightBlack", "fgBrightRed", |
| 212 | 229 | "fgBrightGreen", "fgBrightYellow", "fgBrightBlue", "fgBrightMagenta", |
| 213 | 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 | 234 | for (const key of verbaitim) { |
| 217 | 235 | text = text.replaceAll( |
| ... | ... | @@ -220,6 +238,9 @@ export function debugAnsi(text: string): string { |
| 220 | 238 | ); |
| 221 | 239 | } |
| 222 | 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 | 244 | text = text.replace(/\n/g, style(fgRed, "\\n")); |
| 224 | 245 | text = text.replace(/\r/g, style(fgMagenta, "\\r")); |
| 225 | 246 | return text; |