Re: 'safe' printing to the terminal
[email protected] (Dan) Sun, 10 May 2026 15:54:27 -0400
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <CABMkAVV2WgpBMf6HpTr_nohbB1dpKK+zoCzPJq5szf4YZjJd7g@mail.gmail.com> |
On Sun, May 10, 2026 at 2:30 PM David Christensen <[email protected]> wrote: > On 5/10/26 08:47, Aristotle Pagaltzis via perl5-porters wrote: > > * David Christensen <[email protected]> [2026-05-09 23:55]: > >> https://metacpan.org/pod/String::ShellQuote > > > Yes, you are right -- String::ShellQuote does not decode ANSI escape codes: > > 2026-05-10 11:21:01 dpchrist@laalaa ~ > $ perl -MString::ShellQuote -e '$s="\033[0;31m"."red text > "."\033[0m"."normal text"; print $s, $/, shell_quote($s), $/' > red text normal text > 'red text normal text' > > > This does: > > 2026-05-10 11:22:05 dpchrist@laalaa ~ > $ perl -e '$s="\033[0;31m"."red text "."\033[0m"."normal text"; print > $s, $/, map({ord($_) < 32 || 126 < ord($_) ? sprintf("\\0%o", ord):$_} > split(//,$s)), $/' > red text normal text > \033[0;31mred text \033[0mnormal text > https://metacpan.org/pod/Term::ANSIColor (which is core) has a colorstrip function, but I don't know if it covers all the use cases desired here. -Dan