code wiki / (root) / nx_nishios_term.nx

nx_nishios_term.nx source

↩ module page · 97 lines · 6673 B

1// nx_nishios_term.nx -- NishiOS GUI rung-4: a TERMINAL WINDOW rendering REAL system content. 2// This is where the GUI meets the actual ecosystem: a terminal window that READS a real sovereign file 3// (the replacement-tools registry) and renders it as text using the existing full 8x8 ASCII font 4// (nx_font8x8 font8x8_table, printable 0x20..0x7E) into the framebuffer (nx_fb). Not lorem-ipsum -- 5// genuine bytes off disk, drawn glyph by glyph, with a blinking-style cursor block. 6// KAT: the terminal window is drawn, the header line renders (text pixels present), the real file is 7// read (len>0) and its lines render in the body (text pixels present), and the BMP exports. 8// HONEST SCOPE: renders a file's bytes (a `cat`); a LIVE shell (typing + running tools in the window) 9// needs the PS/2 keyboard driver + wiring the bridge in -- the next rungs. No hw writes (Rule 26). 10// expect_exit: 0 license_tier: ORIGINAL 11import "nx_fb.nx" 12import "nx_font8x8.nx" 13const K_MAGIC_192054: i64 = 192054 14 15func tm_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 16func tm_num(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); 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} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 17 18// render one ASCII glyph from font8x8 (bit ORDER: bit0 = leftmost column, the font8x8 convention) 19func term_char(fb: *u8, W: i64, H: i64, table: *u8, x: i64, y: i64, scale: i64, ch: i64, r: i64, g: i64, b: i64) -> i64 { 20 if ch<0x20 { return 0 } 21 if ch>0x7E { return 0 } 22 let gi: i64=(ch-0x20)*8 23 var row: i64=0 24 while row<8 { let bits: i64=table[gi+row] as i64; var col: i64=0; while col<8 { if ((bits>>col)&1)==1 { fb_rect(fb,W,H, x+col*scale, y+row*scale, scale,scale, r,g,b) } col=col+1 } row=row+1 } 25 return 0 26} 27func term_str(fb: *u8, W: i64, H: i64, table: *u8, x: i64, y: i64, scale: i64, s: *u8, r: i64, g: i64, b: i64) -> i64 { 28 var i: i64=0 29 while s[i]!=(0 as u8) { term_char(fb,W,H,table, x+i*8*scale, y, scale, s[i] as i64, r,g,b); i=i+1 } 30 return 0 31} 32// count text-colored pixels (green channel high) in a band -- proof that glyphs actually rendered 33func count_text(fb: *u8, W: i64, x0: i64, y0: i64, x1: i64, y1: i64) -> i64 { 34 var c: i64=0 35 var y: i64=y0 36 while y<y1 { var x: i64=x0; while x<x1 { if (fb[(y*W+x)*3+1] as i64) > 200 { c=c+1 } x=x+1 } y=y+1 } 37 return c 38} 39 40func main() -> i64 { 41 tm_puts("NishiOS GUI rung-4: a TERMINAL WINDOW rendering a REAL sovereign file (full ASCII font)\n" as *u8) 42 let W: i64 = 320 43 let H: i64 = 200 44 let fb: *u8 = sys_mmap(W*H*3) 45 let table: *u8 = font8x8_table() 46 47 fb_rect(fb,W,H, 0,0, W,H, 8,30,45) // desktop 48 fb_rect(fb,W,H, 18,26, 284,156, 60,120,80) // terminal window border (green) 49 fb_rect(fb,W,H, 19,27, 282,154, 12,16,12) // body (near-black) 50 fb_rect(fb,W,H, 19,27, 282,12, 30,90,45) // title strip 51 term_str(fb,W,H,table, 23,28, 1, "NISHIOS terminal\x00" as *u8, 220,255,220) 52 term_str(fb,W,H,table, 24,44, 1, "> cat replacement_tools.tsv\x00" as *u8, 120,255,120) 53 54 // read the REAL file and render its lines in the body 55 let lenp: *i64 = sys_mmap(8) as *i64 56 let buf: *u8 = sys_read_file("knowledge/registry/replacement_tools.tsv\x00" as *u8, lenp) 57 var flen: i64 = 0 58 if (buf as i64) != 0 { flen = lenp[0] } 59 let x0: i64 = 24 60 let y0: i64 = 56 61 let maxcols: i64 = 34 62 let maxlines: i64 = 11 63 var li: i64=0 64 var col: i64=0 65 var i: i64=0 66 while i<flen { 67 if li>=maxlines { i=flen } else { 68 let ch: i64 = buf[i] as i64 69 if ch==10 { li=li+1; col=0 } else { if ch==9 { col=col+2 } else { if col<maxcols { term_char(fb,W,H,table, x0+col*8, y0+li*11, 1, ch, 170,225,170); col=col+1 } } } 70 i=i+1 71 } 72 } 73 fb_rect(fb,W,H, x0+col*8, y0+li*11, 6,8, 120,255,120) // cursor block 74 75 let sz: i64 = fb_bmp_save(fb, W, H, "knowledge/status/nishios_term.bmp\x00" as *u8) 76 let html: *u8 = "<!doctype html><html><body style=\x27margin:0;background:#0a0a12;display:flex;align-items:center;justify-content:center;height:100vh\x27><div><img src=\x27nishios_term.bmp\x27 style=\x27image-rendering:pixelated;width:720px;border:1px solid #333\x27><div style=\x27color:#8af;font-family:monospace;text-align:center;margin-top:8px\x27>NishiOS terminal -- a window rendering a REAL sovereign file with the full 8x8 ASCII font</div></div></body></html>\x00" 77 let hd: i64 = sys_openat_wr("knowledge/status/nishios_term.html\x00" as *u8, 0x1a4) 78 if hd>0 { var hn: i64=0; while html[hn]!=(0 as u8){hn=hn+1} sys_write(hd, html, hn); sys_close(hd) } 79 80 let hdr_px: i64 = count_text(fb, W, 24, 44, 300, 52) // header band 81 let body_px: i64 = count_text(fb, W, 24, 56, 300, 170) // body band 82 tm_puts(" read replacement_tools.tsv (" as *u8); tm_num(flen); tm_puts(" bytes), rendered " as *u8); tm_num(li); tm_puts(" lines -> nishios_term.bmp + .html\n" as *u8) 83 tm_puts(" text pixels: header=" as *u8); tm_num(hdr_px); tm_puts(" body=" as *u8); tm_num(body_px); tm_puts("\n" as *u8) 84 85 var pass: i64=0 86 var ttl: i64=0 87 let p_win: i64 = (178*W+200)*3 // clean body point, below the last text line 88 ttl=ttl+1; tm_puts(" T1 terminal window drawn (dark body): " as *u8); if (fb[p_win] as i64)==12 { if (fb[p_win+1] as i64)==16 { pass=pass+1; tm_puts("PASS\n" as *u8) } else { tm_puts("FAIL\n" as *u8) } } else { tm_puts("FAIL\n" as *u8) } 89 ttl=ttl+1; tm_puts(" T2 header line rendered (text pixels>40): " as *u8); if hdr_px>40 { pass=pass+1; tm_puts("PASS\n" as *u8) } else { tm_puts("FAIL\n" as *u8) } 90 ttl=ttl+1; tm_puts(" T3 real file read (len>0): " as *u8); if flen>0 { pass=pass+1; tm_puts("PASS\n" as *u8) } else { tm_puts("FAIL\n" as *u8) } 91 ttl=ttl+1; tm_puts(" T4 file content rendered in body (text pixels>40, lines>0): " as *u8); if body_px>40 { if li>0 { pass=pass+1; tm_puts("PASS\n" as *u8) } else { tm_puts("FAIL\n" as *u8) } } else { tm_puts("FAIL\n" as *u8) } 92 ttl=ttl+1; tm_puts(" T5 BMP exported: " as *u8); if sz==K_MAGIC_192054 { pass=pass+1; tm_puts("PASS\n" as *u8) } else { tm_puts("FAIL\n" as *u8) } 93 94 tm_puts("NISHIOS-TERM-GATE passed " as *u8); tm_num(pass); tm_puts("/" as *u8); tm_num(ttl) 95 if pass==ttl { tm_puts(" verdict=GREEN (the GUI renders REAL system content via the full ASCII font; open nishios_term.html to SEE it)\n" as *u8); sys_exit(0); return 0 } 96 tm_puts(" verdict=RED\n" as *u8); sys_exit(1); return 1 97}