code wiki / _hdl_build / nx_browser_forms_render_gate.nx
nx_browser_forms_render_gate.nx source
↩ module page · 84 lines · 5554 B
1import "nx_gate_base.nx"
2// nx_browser_forms_render_gate.nx -- pixel-inspection proof that the Nishi browser DRAWS editable form
3// fields: bf_paint_field renders a bordered box + the typed value + a caret (focused) / no caret
4// (unfocused), and masks passwords. GREEN iff 6/6. Composes the pure form state (nx_browser_forms) with
5// the render (nx_browser_forms_paint). license_tier: ORIGINAL
6import "nx_browser_forms_paint.nx"
7import "nx_syscalls.nx"
8
9func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
10" as *u8); return ok }
11func gwn(v: i64) -> i64 { var m: i64=v; if m<0 {gw("-" as *u8);m=0-m} let t: *u8=sys_mmap(24); var k: i64=0; if m==0 {t[0]=48 as u8;k=1} while m>0 {t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} let o: *u8=sys_mmap(24); var i: i64=0; while i<k {o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 }
12func gcell(ok: i64, id: *u8, txt: *u8) -> i64 { if ok==1 {gw(" PASS " as *u8)} else {gw(" FAIL " as *u8)} gw(id); gw(" " as *u8); gw(txt); gw("\n" as *u8); return ok }
13// is the pixel dark ink? (r<120)
14func gis_dark(fb: *Framebuffer, x: i64, y: i64) -> i64 { let c: *CssColor = sys_mmap(NX_CSS_COLOR_BYTES) as *CssColor; if nx_framebuffer_get_pixel(fb, x, y, c)==0 {return 0} if c.r < 120 {return 1} return 0 }
15// is the pixel white bg?
16func gis_white(fb: *Framebuffer, x: i64, y: i64) -> i64 { let c: *CssColor = sys_mmap(NX_CSS_COLOR_BYTES) as *CssColor; if nx_framebuffer_get_pixel(fb, x, y, c)==0 {return 0} if c.r > 240 {if c.g > 240 {if c.b > 240 {return 1}}} return 0 }
17// is the pixel blue-ish (focused border)?
18func gis_blue(fb: *Framebuffer, x: i64, y: i64) -> i64 { let c: *CssColor = sys_mmap(NX_CSS_COLOR_BYTES) as *CssColor; if nx_framebuffer_get_pixel(fb, x, y, c)==0 {return 0} if c.b > 180 {if c.r < 120 {return 1}} return 0 }
19// scan a rect for ANY dark pixel
20func gany_dark(fb: *Framebuffer, x0: i64, y0: i64, x1: i64, y1: i64) -> i64 { var y: i64=y0; while y<y1 { var x: i64=x0; while x<x1 { if gis_dark(fb, x, y)==1 {return 1} x=x+1 } y=y+1 } return 0 }
21
22func main() -> i64 {
23 gw("=== NX-BROWSER-FORMS-RENDER-GATE -- does the Nishi browser DRAW editable fields? (pixels) ===\n" as *u8)
24 let W: i64 = 220
25 let H: i64 = 64
26 let px: *u8 = sys_mmap(W * H * 4 + 64)
27 let fb: *Framebuffer = sys_mmap(NX_FRAMEBUFFER_BYTES) as *Framebuffer
28 nx_framebuffer_init(fb, px, W, H)
29 // clear to a distinct NON-white, NON-dark backdrop (mid-gray) so the white field box is detectable
30 var i: i64 = 0
31 while i < W * H * 4 { px[i] = 160 as u8; i = i + 1 }
32
33 // parse the docportal login form, fill handle="elder", passphrase="secret"
34 let h1: *u8 = "<form method=post action=/admin/login><input type=hidden name=ui value=1><input name=handle><input name=passphrase type=password></form>" as *u8
35 var hl: i64 = 0
36 while h1[hl] != (0 as u8) { hl = hl + 1 }
37 let forms: *BrForm = sys_mmap(NX_BRFORM_BYTES * 4) as *BrForm
38 let fields: *BrField = sys_mmap(NX_BRFIELD_BYTES * 8) as *BrField
39 let nf: i64 = bf_parse(h1, hl, forms, 4, fields, 8)
40 let f_h: *BrField = bf_field(fields, 1)
41 let f_p: *BrField = bf_field(fields, 2)
42 bf_set(f_h, "elder" as *u8)
43 bf_set(f_p, "secret" as *u8)
44
45 var pass: i64 = 0
46
47 // ---- R1: FOCUSED handle field -> blue border at the top-left corner ----
48 bf_paint_field(fb, 10, 6, 200, 22, f_h, 1)
49 let r1: i64 = gis_blue(fb, 10, 6)
50 pass = pass + gcell(r1, "R1" as *u8, "focused field draws a BLUE border (top-left corner pixel blue)" as *u8)
51
52 // ---- R2: white field interior (a right-side empty pixel is white, not the mid-gray backdrop) ----
53 var r2: i64 = 0
54 if gis_white(fb, 200, 16) == 1 { r2 = 1 }
55 pass = pass + gcell(r2, "R2" as *u8, "field interior filled WHITE over the page backdrop" as *u8)
56
57 // ---- R3: the typed value "elder" paints INK inside the box ----
58 let r3: i64 = gany_dark(fb, 15, 8, 70, 26)
59 pass = pass + gcell(r3, "R3" as *u8, "typed value paints dark glyph ink inside the field" as *u8)
60
61 // ---- R4: caret drawn after the value (focused). "elder"=5 chars, tx=15, caret_x=15+5*6=45 ----
62 var r4: i64 = 0
63 var yy: i64 = 10
64 while yy < 24 { if gis_dark(fb, 45, yy) == 1 { r4 = 1 } yy = yy + 1 }
65 pass = pass + gcell(r4, "R4" as *u8, "focused caret drawn after the value (column x=45 has ink)" as *u8)
66
67 // ---- R5: UNFOCUSED password field -> NO caret at its caret column + GRAY (not blue) border ----
68 // "secret"=6 chars, tx=15 -> caret would be at 15+6*6=51. Dots sit at 15,21,27,33,39,45 (none at 51).
69 bf_paint_field(fb, 10, 34, 200, 22, f_p, 0)
70 var r5: i64 = 1
71 var yy2: i64 = 36
72 while yy2 < 54 { if gis_dark(fb, 51, yy2) == 1 { r5 = 0 } yy2 = yy2 + 1 } // no caret column ink
73 if gis_blue(fb, 10, 34) == 1 { r5 = 0 } // border NOT blue
74 pass = pass + gcell(r5, "R5" as *u8, "unfocused password field: NO caret + border is gray (not blue)" as *u8)
75
76 // ---- R6: password field MASKS -- filled bullet dots render (value NOT blank, and NOT plaintext) ----
77 let r6: i64 = gany_dark(fb, 15, 36, 50, 52)
78 pass = pass + gcell(r6, "R6" as *u8, "password renders masked bullet dots (not blank; secret never drawn as glyphs)" as *u8)
79
80 gw("NX-BROWSER-FORMS-RENDER-GATE pass=" as *u8); gwn(pass); gw("/6 verdict=" as *u8)
81 if pass == 6 { gw("GREEN (the Nishi browser DRAWS editable fields: border+value+caret+mask; focus-wiring composes this)\n" as *u8); sys_exit(0); return 0 }
82 gw("RED\n" as *u8); sys_exit(1)
83 return 1
84}