summaryrefslogtreecommitdiff
path: root/gui/draw/snarf.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/draw/snarf.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/draw/snarf.go')
-rw-r--r--gui/draw/snarf.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/gui/draw/snarf.go b/gui/draw/snarf.go
new file mode 100644
index 0000000..ae26edd
--- /dev/null
+++ b/gui/draw/snarf.go
@@ -0,0 +1,15 @@
+package draw
+
+import "os"
+
+// Snarf puts text on the system snarf buffer, which is what every other
+// program on the system means by "copy".
+func Snarf(dev, text string) error {
+ f, err := os.OpenFile(dev+"/snarf", os.O_WRONLY|os.O_TRUNC, 0)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+ _, err = f.WriteString(text)
+ return err
+}