public Terminal and Operation in Instance

This commit is contained in:
Cheney 2015-10-03 14:11:13 +08:00
parent d173bd5ae7
commit e89699832b
1 changed files with 14 additions and 14 deletions

View File

@ -3,8 +3,8 @@ package readline
import "io" import "io"
type Instance struct { type Instance struct {
t *Terminal Terminal *Terminal
o *Operation Operation *Operation
} }
type Config struct { type Config struct {
@ -39,8 +39,8 @@ func NewEx(cfg *Config) (*Instance, error) {
} }
rl := t.Readline() rl := t.Readline()
return &Instance{ return &Instance{
t: t, Terminal: t,
o: rl, Operation: rl,
}, nil }, nil
} }
@ -49,41 +49,41 @@ func New(prompt string) (*Instance, error) {
} }
func (i *Instance) SetPrompt(s string) { func (i *Instance) SetPrompt(s string) {
i.o.SetPrompt(s) i.Operation.SetPrompt(s)
} }
func (i *Instance) Stdout() io.Writer { func (i *Instance) Stdout() io.Writer {
return i.o.Stdout() return i.Operation.Stdout()
} }
func (i *Instance) Stderr() io.Writer { func (i *Instance) Stderr() io.Writer {
return i.o.Stderr() return i.Operation.Stderr()
} }
func (i *Instance) SetVimMode(on bool) { func (i *Instance) SetVimMode(on bool) {
i.o.SetVimMode(on) i.Operation.SetVimMode(on)
} }
func (i *Instance) IsVimMode() bool { func (i *Instance) IsVimMode() bool {
return i.o.IsEnableVimMode() return i.Operation.IsEnableVimMode()
} }
func (i *Instance) ReadPassword(prompt string) ([]byte, error) { func (i *Instance) ReadPassword(prompt string) ([]byte, error) {
return i.o.Password(prompt) return i.Operation.Password(prompt)
} }
func (i *Instance) Readline() (string, error) { func (i *Instance) Readline() (string, error) {
return i.o.String() return i.Operation.String()
} }
func (i *Instance) ReadSlice() ([]byte, error) { func (i *Instance) ReadSlice() ([]byte, error) {
return i.o.Slice() return i.Operation.Slice()
} }
func (i *Instance) Close() error { func (i *Instance) Close() error {
if err := i.t.Close(); err != nil { if err := i.Terminal.Close(); err != nil {
return err return err
} }
i.o.Close() i.Operation.Close()
return nil return nil
} }