readline/readline.go

37 lines
530 B
Go
Raw Normal View History

2015-09-20 18:14:29 +03:00
package readline
2015-09-21 08:30:10 +03:00
import "io"
2015-09-20 18:14:29 +03:00
2015-09-21 08:30:10 +03:00
type Instance struct {
t *Terminal
o *Operation
2015-09-20 18:14:29 +03:00
}
2015-09-21 08:30:10 +03:00
func New(prompt string) (*Instance, error) {
t, err := NewTerminal()
if err != nil {
return nil, err
2015-09-20 18:14:29 +03:00
}
2015-09-21 08:30:10 +03:00
rl := t.Readline(prompt)
return &Instance{
t: t,
o: rl,
}, nil
2015-09-20 18:14:29 +03:00
}
2015-09-21 08:30:10 +03:00
func (i *Instance) Stderr() io.Writer {
return i.o.Stderr()
2015-09-20 18:14:29 +03:00
}
2015-09-21 08:30:10 +03:00
func (i *Instance) Readline() (string, error) {
return i.o.String()
2015-09-20 18:14:29 +03:00
}
2015-09-21 08:30:10 +03:00
func (i *Instance) ReadSlice() ([]byte, error) {
return i.o.Slice()
2015-09-20 18:14:29 +03:00
}
2015-09-21 08:30:10 +03:00
func (i *Instance) Close() error {
return i.t.Close()
2015-09-20 18:14:29 +03:00
}