Posts

Plan 9: Devanagari Input with kbmap

Image
  Note : The demo uses layer 3 for better key visualization while using Devanagari.                The PS/2 interface presents two physical layers, switched on if the input scancode is one or two bytes. This second "escaped" layer is typically generated for keys like `Home' and `Ins'. Kbdfs additionally maintains eight more virtual layers that are switched on `Shift', `Ctl', `AltGr', and `Mod4' modifier key state. Not all permutations of these modifiers are represented as layers, the exhaustive list is as follows: none Key shift Shift + Key esc Escaped Key altgr AltGr + Key ctl Ctl + Key ctlesc Ctl + Escaped Key shiftesc Shift + Escaped Key shiftaltgr Shift + AltGr + Key mod4 Mod4 + Key altgr...

Plan 9: Key Visualizer

Image
Simple key visualizer for capturing keystrokes during a screencast using kbdfs, awk and statusmsg. Note : You need a Truetype font for arbitrary large display ( /n/ttf/mine/32/font  in the example).  Also, ensure truetypefs is running if you do use Truetype font.   #!/bin/rc fn notify {     scr=`{awk '{print $4, $5}' /dev/screen}     w=200     h=60     ws=$scr(1)     hs=$scr(2)     minx=`{echo $ws - $w | bc}     warg=`{echo -w  $minx,0,$ws,$h}     font=/n/ttf/mine/32/font aux/statusmsg $warg $1 } {     tee /dev/kbdtap |     tr '\000' '\034' |     awk -v 'RS=\034' '     BEGIN {         esc   = sprintf("%c", 033)         tab   = sprintf("%c", 011)         bksp  = sprintf("%c", 010)         del   = sprintf("%c", 0177)      ...

Plan 9: Emoji

Image
  Noto Emoji Font Note:  Noto Color emoji needs Color Bitmap Data (CBDT) or COLR/CPAL support.   Four independent bugs, spanning truetypefs.c , hint.c , and head.c : 1. assert(gs[i] != nil) crash in compilesub ( truetypefs.c ) ttffindchar returning glyph 0 for a rune inside a declared cmap segment (a genuine gap, not just the NUL special-case) skipped the retry-via-notdef path entirely. If the font's own .notdef then also failed to rasterize, the assert took the whole fileserver down. Fixed by replacing the assert with a synthesized blank placeholder as the last resort in the fallback chain. 2. No bounds checking on glyph geometry before blit() ( truetypefs.c ) blit() has zero validation of its own; compilesub sized the destination strip from the font's declared ascentpx + descentpx but never checked that an individual glyph's actual rendered width/height/vertical position fit inside that buffer. A decorative font ( architectsdaughter ) reporting ink extents...

Plan 9: Dynamic HTML

Image
  Render Dynamic HTML using plot and qjs. Render a simple website   Font zoom   E-Book Reader eBook is a collection of HTML files in a ZIP archive. Follow same steps for Comic Book reader which are collection of JPG/PNG images in a ZIP/RAR archive. For columns, pure HTML solution involves column-count CSS property. However, this works only for designed screen sizes. For non-standard sizes, the first column might span multiple pages before continuing in the second column. Hence, the page mode manages the split without relying on the column-count.   Keymap t                          Table of Content -/=                     Font zoom 1,2,3                  Column s                         Toggle scroll/page mode  ...

Plan 9 Plumber

Image
Plumb Zip file   View files inside a zip compressed file via Plumber without extraction. Zip file contents are accessible at /n/tapefs. (Note: sam displays the UTF Byte-Order-Mark (BOM) as is - the garbage in the beginning of the first line). #zip file content in a new window type    is    text data    matches    '([a-zA-Z¡-ï¿¿0-9_\-.,/]+)\.zip' arg    isfile    $0 plumb    start    window fs/zipfs $file; cd /n/tapefs; ls; rc   Plumber process, usually running in the parent process, does not have visibility into the folders mounted by the child process because of namespace isolation. Hence, you need the following changes: zipfs (or 32vfs, cpiofs, tapfs, tarfs, tpfs, v6fs, v10fs etc.) must expose a service in the /srv directory. ( fs.c ) plumber must mount the zipfs for paths starting with /n/tapefs before checking for file existence. ( match.c )   

Plan 9: Tiled Map

Image
  Use plot(1) to display tiled maps. The zoom factor decides the grid dimension. osm.js: Download tile images from OpenStreetMaps using hget. Cache the images. Convert the PNG image into Plan 9 format using png. Display the images using plot. Plot script   ra 0 0 200 200 m 0 100 im /file :Note - must end the script with a newline     Plot tries to center the drawing. Hence the origin is at the bottom with a slight offset from the left. However, image uses origin at the top left.     Interactive Plotting and Maps Use plot command in server mode (-s option). plot -s a.plt  mount /srv/plot /mnt/plot echo li 0 0 100 100 > /mnt/plot/ctl echo erase > /mnt/plot/ctl Usage as an interactive map.   OSM API Tiles https://tile.openstreetmap.org/zoom/x/y.png   The World map at zoom 0 https://tile.openstreetmap.org/0/0/0.png     Geocoding (Name to geographical co-ordinates) https://nominatim.openstreetmap.org/search?q=hebba...

Browser in Javascript

Image
  A Proof-of-Concept Browser written in Javascript for minimal Web 2.0 browsing experience. This DOES NOT depend on any browser engine like Blink, Gecko or Webkit. Use an existing HTML rendering engine like netsurf or roll-out your own . This uses QuickJS-ng for JS runtime, Linkedom for DOM API and curl for network downloads. Font decoration uses Terminal ANSI escape codes . Since linkedom is an npm module, it needs to be converted to ES6 module for use with quickjs.  sudo apt install npm  npm install linkedom npx esbuild node_modules/linkedom/esm/index.js \     --bundle \     --format=esm \     --outfile= linkedom.bundle.js \     --platform=neutral \     -- main-fields = module,main           Code https://gitlab.com/atamariya/quickjs/-/blob/dev/ldom.js https://gitlab.com/atamariya/quickjs/-/blob/dev/net.js https://gitlab.com/atamariya/quickjs/-/blob/dev/render.js   Lessons Learnt st...