Commit 6bb2f8e
committed
util: strip whole CSI sequences per ECMA-48
stripVTControlCharacters() recognises a control sequence by a hand
written list of final bytes, inherited from the bundled copy of
ansi-regex. The list covers neither parameter bytes such as `<` and
`:`, used by mouse reports and by sub parameters, nor final bytes such
as `@`, `X`, `d`, `a` and `b`. A sequence that uses one of them
matches only in part, so the rest of it is left in the string rather
than removed.
getStringWidth() strips before measuring and readline places the cursor
from that width, so the leftovers are counted as printable columns.
Add an alternative built from the control sequence structure in
ECMA-48 5.4: any number of parameter bytes (0x30-0x3F), any number of
intermediate bytes (0x20-0x2F), then a single final byte (0x40-0x7E).
Both existing alternatives are kept and the new one is only reached
where they do not match, so a match can be extended but never shortened.
The new alternative carries its own introducer instead of sharing the
existing prefix, because the shared prefix also consumes `;` and the
two competing for the same run made the match quadratic.
Signed-off-by: Luan Taraschi <130802253+luantaraschi@users.noreply.github.com>1 parent e2b33e2 commit 6bb2f8e
2 files changed
Lines changed: 39 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
| 289 | + | |
289 | 290 | | |
290 | | - | |
| 291 | + | |
291 | 292 | | |
292 | 293 | | |
293 | | - | |
294 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
295 | 307 | | |
296 | 308 | | |
297 | 309 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
24 | 48 | | |
25 | 49 | | |
26 | 50 | | |
| |||
0 commit comments