ANSI color-mode policy and SGR escape assembly for the text backend (issue #2062).
Color modes:
never no ANSI escapes
ansi16 SGR 30-37/90-97 foreground colors
ansi256 SGR 38;5;
Saved .txt artifacts default to 'never' so bytes stay reproducible. The 'auto' mode is resolved conservatively at output time: file output never resolves to color, and terminal output resolves through the environment and a stdout TTY probe. All escape bytes are built with achar() so this source stays pure ASCII.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | public, | parameter | :: | COLOR_NONE | = | -1 |
True when mode names one of the five canonical color modes.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | mode |
Canonicalize a user color-mode selection; unknown names fall back to 'never' so unexpected input can never leak escapes into output.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | name |
Resolve the color mode for file output. Saved files must stay reproducible, so 'auto' always resolves to 'never'; explicit modes are honored because the caller asked for them.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | mode |
Resolve the color mode for interactive terminal output. Explicit modes are honored; 'auto' is resolved from the environment and a stdout TTY probe.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | mode |
SGR foreground escape for the given color mode and RGB (0..1). Returns an empty string for 'never'/unknown modes.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | mode | |||
| real(kind=wp), | intent(in) | :: | r | |||
| real(kind=wp), | intent(in) | :: | g | |||
| real(kind=wp), | intent(in) | :: | b |
The SGR reset escape emitted after a colored span and before every newline or frame boundary.
Pack an RGB triple (0..1) into a single 24-bit integer for the per-cell color buffer.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | r | |||
| real(kind=wp), | intent(in) | :: | g | |||
| real(kind=wp), | intent(in) | :: | b |
Map an RGB triple to a standard (30-37) or bright (90-97) SGR foreground code by nearest 3-bit color plus a luminance-based bright bit.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | r | |||
| real(kind=wp), | intent(in) | :: | g | |||
| real(kind=wp), | intent(in) | :: | b |
Map an RGB triple to a 6x6x6 color-cube index (16..231).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | r | |||
| real(kind=wp), | intent(in) | :: | g | |||
| real(kind=wp), | intent(in) | :: | b |
Inverse of pack_rgb; returns channels in 0..1.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | packed | |||
| real(kind=wp), | intent(out) | :: | r | |||
| real(kind=wp), | intent(out) | :: | g | |||
| real(kind=wp), | intent(out) | :: | b |