Re: 'safe' printing to the terminal
[email protected] (Aristotle Pagaltzis via perl5-porters) Sun, 10 May 2026 17:47:38 +0200
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
* Michiel Beijen <[email protected]> [2026-05-09 14:51]: > Is there a 'best practice' way to achieve something similar in Perl? I don’t think so. I don’t know the entire CPAN off the top of my head, obviously, but I’ve been around CPAN for a while and I don’t remember ever coming across anything like that. A probably-easily-90% fix is to just escape the escape character (0x1B), but I have no guess for how much complexity is necessary to get to 100%. > I know there used to be a discussion about this in gnu coreutils (ls > and friends) and there is now quotearg.c which is MANY lines of code. The place I’d be most inclined to look would be the source of the `less` pager… but it’s not a pleasant codebase for finding or isolating that logic. :-/ (It has a toggle for whether to pass escape sequences through or escape them, which is stored in the `ctldisp` variable. You can start with that symbol and lose your mind from there…) * David Christensen <[email protected]> [2026-05-09 23:55]: > https://metacpan.org/pod/String::ShellQuote > > I would advise testing what shell_quote() does when given control > characters, ANSI escape sequences, Unicode, etc.. That is not really applicable. Maybe it happens to work for that purpose by accident, but terminal control sequence escaping is a completely different animal from shell metacharacter quoting.