code wiki / (root) / nx_color.nx

nx_color.nx

buildroot/runtime/nx_color.nx

4524 B120 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic color
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_color.nx

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

main sys_mmap nx_color_seq

structs

none

consts

43const NX_COLOR_RESET: i64 = 0
44const NX_COLOR_BOLD: i64 = 1
45const NX_COLOR_DIM: i64 = 2
46const NX_COLOR_UNDER: i64 = 4
47const NX_COLOR_RED: i64 = 31
48const NX_COLOR_GREEN: i64 = 32
49const NX_COLOR_YELLOW: i64 = 33
50const NX_COLOR_BLUE: i64 = 34
51const NX_COLOR_MAGENTA: i64 = 35
52const NX_COLOR_CYAN: i64 = 36
53const NX_COLOR_WHITE: i64 = 37

functions

58func nx_color_seq(code: i64, buf: *u8) -> i64 {
called by 2: nx_color_writemain
77func nx_color_write(fd: i64, enable: i64, code: i64, s: *u8, n: i64) -> i64 {
94func main() -> i64 {