nx_color.nx
buildroot/runtime/nx_color.nx
about
nx_color.nx -- ANSI terminal color escape sequences.
Compiler error rendering, log output, debugger UI all benefit
from terminal colors when stderr is a TTY. This module exposes
the standard ANSI SGR (Select Graphic Rendition) escapes as
pre-built byte sequences that callers can write directly.
Convention: callers should detect TTY-ness once at startup
(typically via isatty(2) or its sim equivalent) and gate color
output on that. This module doesn't decide; it just provides
the escapes.
No string literals as constants in NishiLang yet, so we expose
pointer-returning helpers that build the sequences in mmap'd
memory (lazy-init, single allocation per sequence).
Standard ANSI SGR escape pattern: ESC [ N m
ESC = 0x1B = '\e'
[ = 0x5B
N = digit code (e.g. 31 = red)
m = 0x6D
We produce the literal byte sequence per code (saves a snprintf-
equivalent which we don't have natively yet).
nx_safety_envelope:
intended_use: "Color primitives (RGB / HSL / Q14 lerp) --
substrate visual pipeline foundation"
sil_target: SIL1
asil_target: QM
dal_target: NONE
evidence: [Q14_fixed_point_color_arithmetic, no_FP,
sRGB_canonical_basis]
hazard_register: [bug-tape-gamma-uncorrected-output,
bug-tape-channel-overflow-via-saturation]
residual_risk: "Linear-light vs sRGB gamma is caller-
decided; substrate provides both paths."
verdict: NOT_YET_EVALUATED
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 43 | const NX_COLOR_RESET: i64 = 0 |
| 44 | const NX_COLOR_BOLD: i64 = 1 |
| 45 | const NX_COLOR_DIM: i64 = 2 |
| 46 | const NX_COLOR_UNDER: i64 = 4 |
| 47 | const NX_COLOR_RED: i64 = 31 |
| 48 | const NX_COLOR_GREEN: i64 = 32 |
| 49 | const NX_COLOR_YELLOW: i64 = 33 |
| 50 | const NX_COLOR_BLUE: i64 = 34 |
| 51 | const NX_COLOR_MAGENTA: i64 = 35 |
| 52 | const NX_COLOR_CYAN: i64 = 36 |
| 53 | const NX_COLOR_WHITE: i64 = 37 |
functions
| 58 | func nx_color_seq(code: i64, buf: *u8) -> i64 { |
| 77 | func nx_color_write(fd: i64, enable: i64, code: i64, s: *u8, n: i64) -> i64 { |
| 94 | func main() -> i64 { |