summaryrefslogtreecommitdiff
path: root/gui/cmd/text/main.go
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@pobox.com>2026-08-22 13:16:35 -0400
committerCalvin Morrison <calvin@pobox.com>2026-08-22 13:16:35 -0400
commit9aacce8b3b54060d0037eca897856d7273e6e5e8 (patch)
treea98ea0cb151a7ded56fe681d6782986b2807dfcf /gui/cmd/text/main.go
parent5ef4699d05bc919255449a9af780f216a0589a72 (diff)
gui: a /dev/draw layer in go, with no cgo and no devdraw
9fans.net/go/draw builds for plan9 but shells out to plan9port's devdraw, which 9front does not have. This talks to /dev/draw itself: the protocol is file i/o, so a pure-go client is a few hundred lines under an already-complete idea. draw/keyboard.go opens /dev/cons and turns the console raw, as libdraw's initkeyboard does. Without it rio keeps its line editor on the window and paints what you type over the drawing. draw/snarf.go writes /dev/snarf, which is what every other program on the system means by copy. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'gui/cmd/text/main.go')
-rw-r--r--gui/cmd/text/main.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/gui/cmd/text/main.go b/gui/cmd/text/main.go
new file mode 100644
index 0000000..f1e2a9f
--- /dev/null
+++ b/gui/cmd/text/main.go
@@ -0,0 +1,66 @@
+// text: prove the font layer draws glyphs on the raw screen.
+package main
+
+import (
+ "fmt"
+ "os"
+ "time"
+
+ "9front/gui/draw"
+)
+
+const fontpath = "/lib/font/bit/lucidasans/unicode.8.font"
+
+func main() {
+ if err := run(); err != nil {
+ fmt.Fprintf(os.Stderr, "text: %v\n", err)
+ os.Exit(1)
+ }
+}
+
+func run() error {
+ d, err := draw.Init("/dev")
+ if err != nil {
+ return err
+ }
+ defer d.Close()
+ scr := d.Screen
+ r := scr.Rect()
+
+ f, err := d.OpenFont(fontpath)
+ if err != nil {
+ return err
+ }
+ fmt.Fprintf(os.Stderr, "text: font h=%d ascent=%d\n", f.Height, f.Ascent)
+
+ // acme's palette: a 25% mix over white, per allocimagemix.
+ bg, err := d.Color(0xFFFFEAFF)
+ if err != nil {
+ return err
+ }
+ ink, err := d.Color(0x000000FF)
+ if err != nil {
+ return err
+ }
+ rule, err := d.Color(0x99994CFF)
+ if err != nil {
+ return err
+ }
+
+ draw.Draw(scr, r, bg, nil, draw.ZP)
+ y := r.Min.Y + 20
+ for _, s := range []string{
+ "Go on Plan 9: glyphs from /lib/font/bit, no libdraw.",
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz",
+ "0123456789 !@#$%^&*()-=[]{};'\\:\"|,./<>?",
+ "width(\"hello\") = " + fmt.Sprint(f.Width("hello")) + " px",
+ time.Now().Format("Mon 2 Jan 2006 15:04:05"),
+ } {
+ f.String(scr, draw.Point{X: r.Min.X + 20, Y: y}, ink, s)
+ y += int32(f.Height) + 6
+ }
+ draw.Draw(scr, draw.Rect(r.Min.X+20, y+8, r.Min.X+520, y+9), rule, nil, draw.ZP)
+ d.Flush()
+ time.Sleep(90 * time.Second)
+ return nil
+}