Add two API methods to set RuneBuffer state before prompting the user (#105)

* Expose RuneBuffer.Set through Operation's API

This allows a user to prefill a line before the user is given a prompt,
so that you can provide a default, user-editable input line.

* Add a Instance.ReadlineWithDefault API method

This will pre-fill the Operation.RuneBuffer with text before prompting
the user, and provide her with a method to edit the provided default.
This commit is contained in:
Paul Tagliamonte 2017-03-13 19:49:21 -04:00 committed by chzyer
parent 8a1389155f
commit 41eea22f71
2 changed files with 9 additions and 0 deletions

View File

@ -32,6 +32,10 @@ type Operation struct {
*opVim
}
func (o *Operation) SetBuffer(what string) {
o.buf.Set([]rune(what))
}
type wrapWriter struct {
r *Operation
t *Terminal

View File

@ -242,6 +242,11 @@ func (i *Instance) Readline() (string, error) {
return i.Operation.String()
}
func (i *Instance) ReadlineWithDefault(what string) (string, error) {
i.Operation.SetBuffer(what)
return i.Operation.String()
}
func (i *Instance) SaveHistory(content string) error {
return i.Operation.SaveHistory(content)
}