ref: 4d18579f8c4bfe20dbd00aed0e370b4e7f1961ac
dir: /readline_plan9.go/
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()
return strings.TrimSpace(input), 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)
}
func enablePipeHack(rl *readline) {
}