Re: 'safe' printing to the terminal

[email protected] (David Christensen) Sun, 10 May 2026 11:28:12 -0700
Newsgroups perl.perl5.porters
Message-ID <[email protected]>
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


See also String::Escape:

https://metacpan.org/pod/String::Escape


David