1// Package hexdumpdemo is a small gnoweb demo of the xxd-style byte dump2// provided by the [p/moul/x/daily/hexdump](/p/moul/x/daily/hexdump/v0)3// library: it shows what a rendered string hides.4//5// It contains no formatting logic of its own. Stateless, so Render is6// deterministic — which is precisely what the library is for.7package hexdumpdemo89import (10 "strconv"11 "strings"1213 "gno.land/p/moul/x/daily/hexdump/v0"14)1516// Render renders the demo for gnoweb.17func Render(path string) string {18 var b strings.Builder19 b.WriteString("# Hexdump\n\n")20 b.WriteString("Bytes in the classic `xxd -C` layout, demoing the ")21 b.WriteString("[`p/moul/x/daily/hexdump`](/p/moul/x/daily/hexdump/v0) library.\n\n")2223 b.WriteString("## A plain string\n\n")24 dump("Hello, gno.land!", &b)2526 b.WriteString("\n## Alignment on a partial line\n\n")27 b.WriteString("The last line is short, so the hex columns are padded and the ASCII ")28 b.WriteString("gutter stays put — that alignment is the whole point of the layout.\n\n")29 dump("0123456789abcdefhi", &b)3031 b.WriteString("\n## What a rendered string hides\n\n")32 b.WriteString("These two look identical in any UI:\n\n")33 b.WriteString("- `\"hi\"`\n- `\"hi \"` — one trailing space\n\n")34 dump("hi", &b)35 b.WriteString("\n")36 dump("hi ", &b)3738 b.WriteString("\n## Multi-byte UTF-8\n\n")39 b.WriteString("`\"café\"` is 5 bytes, not 4: `é` is `c3 a9`. Non-printables render as `.`.\n\n")40 dump("café", &b)4142 b.WriteString("\n## Control characters\n\n")43 b.WriteString("A NUL, a newline and a tab are invisible in text and obvious here.\n\n")44 out, n := hexdump.Dump([]byte{0x00, 0x0a, 0x09, 'o', 'k'})45 b.WriteString("```\n" + out + "```\n\n")46 b.WriteString("_" + strconv.Itoa(n) + " bytes._\n")47 return b.String()48}4950func dump(s string, b *strings.Builder) {51 out, n := hexdump.DumpString(s)52 b.WriteString("```\n" + out + "```\n")53 b.WriteString("\n_`" + s + "` → " + strconv.Itoa(n) + " bytes._\n")54}55Render(path string) string
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.
vm/qrender output, sanitized (docs/render-security.md) and displayed in an empty-sandbox iframe — scripts, forms and popups cannot run. Links stay inert in-preview; right-click to open.