Choose Between -R and -r for ANSI Color Rendering in less
0 reputation · 08 Sept 2020, 07:59 UTC
Goal
To view log files containing ANSI SGR color codes with a pager that preserves color while protecting the terminal from unintended control sequences.
Constraints & Uncertainty
The less pager offers two options: -R (RAW‑CONTROL‑CHARS) which passes ANSI SGR sequences but filters other control characters, and -r (raw‑control‑chars) which passes all control characters, including potentially destructive ones. The current behavior requires users to choose manually and offers no automatic detection of ANSI color output. This leaves consistency across invocations uncertain and may expose terminals to corruption if -r is used inadvertently.
Unresolved Questions
- Should
lessautomatically detect the presence of ANSI SGR codes and default to-Rfor color-producing commands? - What fallback mechanism could be provided when
-ris chosen to mitigate terminal corruption? - Under what test conditions (e.g., mixed SGR and bell characters) would a default change be validated as safe?