3 ms·
Disable, filter out ansi escape sequence(s)?
by sargstuff 3y ago
Disable, filter out ansi escape sequence(s)?
- junon 3y agoI maintain `ansi-regex` on npm. Believe me when I say doing this with any amount of certainty is almost impossible.
- sargstuff 3y agoDisable, filter out ansi escape sequence(s), rewrite/map ansi escape sequence(s) to tput format. No source code or familiarity with using LD_ tricks? use python wrapper around program and script python for appropriate mods before passing along to window. Wonder if this was one reason for Sun Solaris NeWS (post script based vs, text based window manager) Perhaps use python from command line with gui extensions and no ansi escape sequence support as window manger. Run terminal window without ansi escape seqence support. Better coverage if done with ebpf filter at the OS level.
- junon 3y agoThe OS has nothing to do with this aside setting the title I suppose, and that's if native widgets are being used and depends on the system. Further, there's nothing special about escapes. Their "feature" is that they're just text, part of the normal stream of bytes. Anything can be an escape if it's interpreted as such by whatever is consuming the stream.
- sargstuff 3y ago> "The OS has nothing to do with this aside setting ..." note: Additional technical information context/solution provided for answer is a bit beyond the typical response required for question. OS has better control/access to user set of i/o streams. Not the most efficient/convenient way, but ebpf can be setup to detect 'escape text patterns' and filter by user/xwindows widgets/aspect of program such as title. Would be a pain, because of need to deal with inband/non-cannonical characters (ctrl-D & EOF being majority of live stream problem) Sticking to 'title change' is a non-continuous stream aka for this talk, first non-connonical character closes the stream, aka no distinction between Form Feed / Line Feed or ctrl-D. Simple user land way would be to redirect terminal to sed /awk script to identify 'title' command, strip out the 'security sequence issues' before passing along i/o to what ever is going to do the 'window with title to change'. OS, windows manager, initial login shell and process initiating the window who's title are to be changed are parent processes with io points that can be redirect with the aforemention script. in-band control for terminals also allows for redirecting to remote machines via programs like telenet without the need for ssh! (for security, would need to do a few other things too) 1st process to Using loopback device/socket instead of named/anonymous pipe redirection will allow for raw/non-cannonical input (control done out of band) -- assuming the filter program (other than standard user shell) setup to handle/pass along raw/cannonical input/output. Sort fun way to customize 'rm -rf' with a pop-up check question 'Are you really sure you want remove everything' and terminate the command if unintentional (and/or keep tabs on what removed by running find command / mail list). further search terms: stty, tty, raw, cooked, canonical, non-cannonical For this topic, perhaps confirm with user if really wanted to allow (escape sequence), retry(filter out ansi sequence), aboard(skip it). Or just log attempt for review/action later.
- deleted 3y ago[deleted]
- sargstuff 3y agoAny related ansi NP = P escape clause proofs?
- JdeBP 3y agoNo it isn't. The problem is using regular expressions as the tool for doing it. By feeding the character stream through a proper DEC VT state machine, it's actually fairly trivial. After all, terminal emulators do exactly this. And it's easy to spot the ones that use state machines instead of regex string matching (which, alas, a few do). The string matchers have had loads of bugs and problems over the years handling unknown but correctly formed control sequences, which the state machine implementations just swallow and ignore with ease.
- junon 3y agoDEC VT is far from the only escape code set. That's more my point. I agree regex isn't the best tool especially for stream processing, but the amount of escape codes out there (and the fact anything can be an escape code...) is what makes it "nearly impossible".
- deleted 3y ago[deleted]