Re: 'safe' printing to the terminal
[email protected] ("H.Merijn Brand" via perl5-porters) Mon, 11 May 2026 11:50:49 +0200
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <20260511115013.7df505d2@pc09> |
On Sun, 10 May 2026 17:47:38 +0200, Aristotle Pagaltzis via perl5-porters <[email protected]> wrote: > * 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%. Note that quite a lot of ANSI-compliant devices *also* support the 8-bit Fe/C1 versions of escape sequences (e.g. \e[ can be abbreviated to \x9b) See https://en.wikipedia.org/wiki/ANSI_escape_code#Fe_Escape_sequences > > 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. -- H.Merijn Brand https://tux.nl Perl Monger http://amsterdam.pm.org/ using perl5.00307 .. 5.37 porting perl5 on HP-UX, AIX, and Linux https://tux.nl/email.html http://qa.perl.org https://www.test-smoke.org
signature.asc
(application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEGolmczWuFi3lJEbAA6FHoT5dwJgFAmoBpnkACgkQA6FHoT5d wJjznQgAjUUmSunrbBOmx1CG/IIuhr8GJZeXLL9UiEHWTn6mB8n2GFOCRZ+KO/p8 dNhX53vJLukNqM/WNT2PWMe+6oxF1q5B4sWYtlF0Es4NtpQIQRo72pSxCXe2mFrX M/bYuMQFErLtS5zT1PTL1t2nDgRnL3zPThHsU14Ed9llSn3KChEqOQKiOm6KHFPH A8A8kT/i+0fcRMI3LCwwqsfWLSnKkzUfxduSur7mShBo70e0SnxF5mripuxb88LA NzvSWt3mrqxCAe6Ve0m0WASlWFM6/aIrzSYm92nlqSRR0CclP7Gvh3INjnPGFvOR uyD+0DNg9g2A9Bi7bPKgMF73TEfXqA== =IaAn -----END PGP SIGNATURE-----