code wiki / _hdl_build / nx_ui_kit.nx

nx_ui_kit.nx source

↩ module page · 66 lines · 4371 B

1// nx_ui_kit.nx -- ui-design-system (U2, the emitting fix for the operator #1 gap). The REUSABLE POLISHED-page 2// emitter primitive: reads the canonical sovereign design system (knowledge/registry/nishi_ds.css: tokens + 3// dual light/dark + fluid type + responsive + polish) and a body-content fragment, and emits a complete 4// scaffolded page (semantic header/nav/main/footer) with the design system inline. Any organ/session calls 5// this instead of hand-rolling dev-grade CSS -> pages START polished (score POLISHED on nx_ui_audit) not 6// DEV-GRADE 0/12. HTML uses UNQUOTED attributes (NishiLang-clean); the one required quote (viewport content) 7// is emitted as a byte. This is the systemic remedy: fix the emitter, every future surface inherits quality. 8// nx_ui_kit <bodyfile> <outfile> [titlefile] 9// exit: 0 emitted | 4 css-or-body unreadable | 2 usage. 10// license_tier: ORIGINAL expect_exit: 0 11import "nx_syscalls.nx" 12const K_MAGIC_65536: i64 = 65536 13const K_MAGIC_65000: i64 = 65000 14const K_MAGIC_262144: i64 = 262144 15const K_MAGIC_262000: i64 = 262000 16const K_MAGIC_1024: i64 = 1024 17 18func uk_wr(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } 19func uk_q(fd: i64) -> i64 { let b: *u8 = sys_mmap(8); b[0] = 34 as u8; sys_write(fd, b, 1); return 0 } 20func uk_reads(path: *u8, buf: *u8, cap: i64) -> i64 { 21 let fd: i64 = sys_openat_rd(path) 22 if fd < 0 { return 0 - 1 } 23 var n: i64 = 0 24 var go: i64 = 1 25 while go == 1 { let r: i64 = sys_read(fd, (buf as i64 + n) as *u8, cap - n); if r <= 0 { go = 0 } else { n = n + r } if n >= cap { go = 0 } } 26 sys_close(fd) 27 return n 28} 29func main(argc: i64, argv: *i64) -> i64 { 30 if argc < 3 { uk_wr(2, "usage: nx_ui_kit <bodyfile> <outfile> [titlefile]\n" as *u8); sys_exit(2); return 2 } 31 let bodyfile: *u8 = argv[1] as *u8 32 let outfile: *u8 = argv[2] as *u8 33 let cssbuf: *u8 = sys_mmap(K_MAGIC_65536) 34 let csn: i64 = uk_reads("knowledge/registry/nishi_ds.css" as *u8, cssbuf, K_MAGIC_65000) 35 if csn <= 0 { uk_wr(1, "UI-KIT verdict=NO-DESIGN-SYSTEM (knowledge/registry/nishi_ds.css unreadable)\n" as *u8); sys_exit(4); return 4 } 36 let bodybuf: *u8 = sys_mmap(K_MAGIC_262144) 37 let bn: i64 = uk_reads(bodyfile, bodybuf, K_MAGIC_262000) 38 if bn <= 0 { uk_wr(1, "UI-KIT verdict=NO-BODY\n" as *u8); sys_exit(4); return 4 } 39 let tbuf: *u8 = sys_mmap(K_MAGIC_1024) 40 var tn: i64 = 0 41 if argc >= 4 { tn = uk_reads(argv[3] as *u8, tbuf, 1000) } 42 while tn > 0 { if tbuf[tn-1] == (10 as u8) { tn = tn - 1 } else { if tbuf[tn-1] == (13 as u8) { tn = tn - 1 } else { let z: i64 = tn; tn = 0 - 1 - z } } } 43 if tn < 0 { tn = 0 - 1 - tn } 44 let tmp: *u8 = sys_mmap(512) 45 var o: i64 = 0 46 var i: i64 = 0 47 while outfile[i] != (0 as u8) { tmp[o] = outfile[i]; o = o + 1; i = i + 1 } 48 tmp[o] = 46 as u8; tmp[o+1] = 116 as u8; tmp[o+2] = 109 as u8; tmp[o+3] = 112 as u8; tmp[o+4] = 0 as u8 49 let fd: i64 = sys_openat_wr(tmp, 420) 50 if fd < 0 { uk_wr(1, "UI-KIT verdict=WRITE-FAIL\n" as *u8); sys_exit(4); return 4 } 51 uk_wr(fd, "<!doctype html><html lang=en><head><meta charset=utf-8><meta name=viewport content=" as *u8) 52 uk_q(fd); uk_wr(fd, "width=device-width,initial-scale=1" as *u8); uk_q(fd) 53 uk_wr(fd, "><title>" as *u8) 54 if tn > 0 { sys_write(fd, tbuf, tn) } else { uk_wr(fd, "Nishi Surface" as *u8) } 55 uk_wr(fd, "</title><style>" as *u8) 56 sys_write(fd, cssbuf, csn) 57 uk_wr(fd, "</style></head><body><header class=nx><div class=bar><span class=brand>Nishi<b>.</b></span><nav class=nx><a href=/>Home</a><a href=/compare>Compare</a><a href=/standup>Standup</a><a href=/frontier>Frontier</a><a href=/sheriff>Sheriff</a><a href=/pm>PM</a><a href=/uidebt>UI Debt</a></nav></div></header><main><div class=wrap>" as *u8) 58 sys_write(fd, bodybuf, bn) 59 uk_wr(fd, "</div></main><footer class=nx><div class=wrap>Sovereign Nishi surface &middot; design system <span class=mono>nishi_ds</span> &middot; emitted by nx_ui_kit</div></footer></body></html>" as *u8) 60 sys_close(fd) 61 let rr: i64 = sys_renameat(tmp, outfile) 62 if rr < 0 { uk_wr(1, "UI-KIT verdict=RENAME-FAIL\n" as *u8); sys_exit(4); return 4 } 63 uk_wr(1, "UI-KIT emitted " as *u8); uk_wr(1, outfile); uk_wr(1, " (design-system nishi_ds inline, POLISHED-by-construction)\n" as *u8) 64 sys_exit(0) 65 return 0 66}