code wiki / (root) / nx_ui_serve.nx

nx_ui_serve.nx source

↩ module page · 74 lines · 3299 B

1// nx_ui_serve.nx -- serve the sovereign interactive UI LIVE, now STATEFUL. 2// 3// Composes THREE reused cores (no one-offs): 4// - nx_http_server.nx -- listen / accept / read-request (the search site's core) 5// - nx_ui_lib.nx -- the fd-based interactive render (composable open/close) 6// - nx_recordlog.nx -- the reusable append-only record store 7// 8// A click GETs /?region=N&zoom=Z -> we LOG the pain spot (recordlog_append) and 9// re-render the map PLUS a running tally (recordlog_count). So the body-map is a 10// real tracker: click where it hurts, it persists, you see your history. Sovereign 11// round-trip, ZERO JS, loopback-bound. license_tier: ORIGINAL 12 13import "nx_http_server.nx" 14import "nx_ui_lib.nx" 15import "nx_recordlog.nx" 16const UI_MAGIC_8192: i64 = 8192 17const UI_MAGIC_1024: i64 = 1024 18 19const UI_PORT: i64 = 8181 20const PAINLOG: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/_offc/nx_painlog.tsv" 21 22func main() -> i64 { 23 let addr: *u8 = sys_mmap(16) 24 nx_http_server_addr_loopback(addr, UI_PORT) 25 let vbox: *i64 = sys_mmap(8) as *i64 26 let lfd: i64 = nx_http_server_listen(addr, 16, vbox) 27 if lfd < 0 { ui_w(1, "listen failed (verdict "); ui_wn(1, vbox[0]); ui_w(1, ")\n"); return 2 } 28 ui_w(1, "Nishi interactive UI LIVE -> http://127.0.0.1:8181/ (sovereign, no JS, stateful)\n") 29 30 let reqcap: i64 = UI_MAGIC_8192 31 var serving: i64 = 1 32 while serving == 1 { 33 let cfd: i64 = nx_http_server_accept_one(lfd, vbox) 34 if cfd >= 0 { 35 let req: *u8 = sys_mmap(reqcap) 36 let m: *i64 = sys_mmap(8) as *i64 37 let po: *i64 = sys_mmap(8) as *i64 38 let pl: *i64 = sys_mmap(8) as *i64 39 let cl: *i64 = sys_mmap(8) as *i64 40 let bo: *i64 = sys_mmap(8) as *i64 41 let rn: *i64 = sys_mmap(8) as *i64 42 let rc: i64 = nx_http_server_read_request(cfd, req, reqcap, m, po, pl, cl, bo, rn) 43 44 let qbuf: *u8 = sys_mmap(UI_MAGIC_1024) 45 var region: i64 = 1 46 var zoom: i64 = 1 47 var is_click: i64 = 0 48 if rc == NXS_OK { 49 var n: i64 = pl[0] 50 if n > 1023 { n = 1023 } 51 var i: i64 = 0 52 while i < n { qbuf[i] = req[po[0] + i]; i = i + 1 } 53 qbuf[n] = 0 as u8 54 region = ui_qval(qbuf, "region=" as *u8, 1) 55 zoom = ui_qval(qbuf, "zoom=" as *u8, 1) 56 is_click = ui_qhas(qbuf, "region=" as *u8) 57 } 58 59 // a real click on a region = a pain report -> LOG it (timestamped). 60 if is_click == 1 { recordlog_append(PAINLOG, region) } 61 62 // HTTP headers + the interactive map + the server-injected tally + close. 63 ui_w(cfd, "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nConnection: close\r\n\r\n") 64 ui_emit_region_map_open(cfd, region, zoom) 65 ui_w(cfd, "<p>You've logged <b>"); ui_w(cfd, ui_label(region)) 66 ui_w(cfd, "</b> as a pain spot <b>"); ui_wn(cfd, recordlog_count(PAINLOG, region)) 67 ui_w(cfd, "</b> time(s) &nbsp;&middot;&nbsp; total reports: "); ui_wn(cfd, recordlog_total(PAINLOG)) 68 ui_w(cfd, "</p>\n") 69 ui_emit_page_close(cfd) 70 sys_close(cfd) 71 } 72 } 73 return 0 74}