ref: 2e227c64c1ee0662383ae4806251e74e1931a953
parent: ec63ec1b6056822aace571109c568921ff239ee3
author: penny <penny@limitedideas.org>
date: Sun Oct 19 15:10:25 EDT 2025
actually commit the platform code
--- /dev/null
+++ b/readline.go
@@ -1,0 +1,30 @@
+//go:build !plan9
+package main
+
+import (
+ native "github.com/ergochat/readline"
+)
+
+type readline struct {+ *native.Instance
+}
+
+var (
+ ErrInterrupt = native.ErrInterrupt
+)
+
+type Config = native.Config
+
+const (
+ CharCtrlJ = native.CharCtrlJ
+ CharInterrupt = native.CharInterrupt
+ CharEnter = native.CharEnter
+)
+
+func NewReadline(config *Config) (*readline, error) {+ instance, err := native.NewEx(config)
+ if err != nil {+ return nil, err
+ }
+ return &readline{instance}, nil+}
--- /dev/null
+++ b/readline_plan9.go
@@ -1,0 +1,70 @@
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "io"
+ "os"
+ "strings"
+)
+
+//not relevant
+const (
+ CharCtrlJ = 0
+ CharInterrupt = 0
+ CharEnter = 0
+)
+
+type readline struct {+ config Config
+}
+
+type Config struct {+ Prompt string
+
+ //These are unused on Plan 9
+ FuncFilterInputRune func(rune) (rune, bool)
+ Listener func(line []rune, pos int, key rune) (newLine []rune, newPos int, ok bool)
+}
+
+func (rl *readline) GetConfig() *Config {+ return &Config{Prompt: rl.config.Prompt}+}
+
+func NewReadline(config *Config) (*readline, error) {+ return &readline{config: *config}, nil+}
+
+func (rl *readline) ReadLineWithConfig(cfg *Config) (string, error) {+ fmt.Print(cfg.Prompt)
+ scanner := bufio.NewScanner(os.Stdin)
+
+ // Scan for the next token (by default, a line)
+ scanner.Scan()
+
+ // Get the text of the scanned line
+ input := scanner.Text()
+ if err != nil {+ return "", err
+ }
+ return strings.TrimSpace(line), nil
+}
+
+func (rl *readline) Stdout() io.Writer {+ return os.Stdout
+}
+
+func (rl *readline) Close() {+ return
+}
+
+func (rl *readline) SetPrompt(prompt string) {+ rl.config.Prompt = prompt
+}
+
+func (rl *readline) SetDefault(string) {+}
+
+func (rl *readline) Readline() (string, error) {+ return rl.ReadLineWithConfig(&rl.config)
+}
--
⑨