nanorc color rules render inconsistently across terminals without per-rule diagnostics
0 reputation · 03 Feb 2021, 02:35 UTC
0 reputation · 03 Feb 2021, 02:35 UTC
Identical nanorc files using color directives with named 16-color slots can display different hues in different terminal emulators, even when the syntax rules load without errors.
Nano binds highlighting to the terminal's 16-color palette rather than embedding RGB values, and the parser does not emit a per-rule diagnostic when a color name is misspelled or unsupported; the rule silently falls back to default foreground and background. Behavior may also differ between nano releases that advertise truecolor support and older releases still shipped by some distributions.
Goal: determine whether nano validates color slots against the active terminal entry before rendering, and whether silent fallbacks can be detected without comparing output across terminals.
Does nano check each color slot against terminfo before applying a rule?
Is there a diagnostic or log that reveals when a rule falls back to default colors?
What approach works when a terminal advertises 24-bit color but renders nano's sequences incorrectly?
37275 reputation · 03 Feb 2021, 13:39 UTC
Nano resolves color names to 16-color codes from the terminfo database at startup. These codes are stored and reused for every rule; the parser does not re-validate each slot against terminfo during rule application. This means that if a color name is unrecognized or missing from the terminal’s entry, the rule silently falls back to the default foreground and background, and no error or warning is produced. [assumption: the startup‑only resolution pattern is consistent across nano builds without truecolor support; versions prior to 6.2 lack truecolor entirely.]
Enabling nano’s -d flag produces debug output, but the messages do not identify which color rule caused a fallback. Silent fallbacks are by design, making it difficult to spot misconfigured directives without manually comparing terminfo entries or terminal output. [confirmed: no per‑rule diagnostic is emitted by default; debug output is limited and not rule‑specific.]
If the terminal reports 24‑bit capability but nano was compiled without truecolor support (versions prior to 6.2), it continues sending 16-color ANSI sequences. The terminal maps those to its own palette, which can shift, mute, or otherwise alter hues. This is a limitation of nano’s color implementation, not a runtime validation failure. [likely: the discrepancy arises from 16‑color vs 24‑bit mapping; if nano was built with truecolor, the behavior may differ.]
nano --version. Versions before 6.2 are assumed to lack truecolor support.infocmp -C $TERM | grep -i <color>. Confirm the named slots are defined for your terminal type.nano -d file.txt. Note that per‑rule diagnostics are not included.To refine which step is most relevant, it helps to know your nano build version and the exact TERM value in use.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.