5 ms·
If you want to make string safe, filter out or escape all bytes / characters in 0-31 range. Maybe keep newlines if you expect multiple lines. Done -- as simple
by theamk 6y ago
If you want to make string safe, filter out or escape all bytes / characters in 0-31 range. Maybe keep newlines if you expect multiple lines.
Done -- as simple as it gets.
- caf 6y agoSome terminals support the C1 control set, and in particular 0x9b as the CSI is dangerous (it's a single character version of the ESC-[ CSI). So you have to watch out for that too.
- lunixbochs 6y agoInteresting: https://man7.org/linux/man-pages/man4/console_codes.4.html https://man7.org/linux/man-pages/man4/console_codes.4.html I'll definitely need to add support for that. Possibly annoying to strip that with utf8 involved. Any idea how many terminals support 0x9b?
- caf 6y agoWith UTF-8 you need to UTF-8 encode the 9b. For example this shows red on xfce4-terminal in UTF-8 mode: printf "\xc2\x9b31mHi\e[0m\n"
- ryan-c 6y ago...interesting
- lunixbochs 6y agoHm, but I won't know if the text/terminal is utf8 or not going in.
- caf 6y agoRight... and you have the Windows-1252 versus iso-8859-1 situation, which only differ in that the former puts printable characters where the latter has C1 control codes. Of course your code is a library so you have the library author's prerogative to punt that problem to the users :)