forked from mirror/readline
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:
parent
8a1389155f
commit
41eea22f71
|
@ -32,6 +32,10 @@ type Operation struct {
|
||||||
*opVim
|
*opVim
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *Operation) SetBuffer(what string) {
|
||||||
|
o.buf.Set([]rune(what))
|
||||||
|
}
|
||||||
|
|
||||||
type wrapWriter struct {
|
type wrapWriter struct {
|
||||||
r *Operation
|
r *Operation
|
||||||
t *Terminal
|
t *Terminal
|
||||||
|
|
|
@ -242,6 +242,11 @@ func (i *Instance) Readline() (string, error) {
|
||||||
return i.Operation.String()
|
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 {
|
func (i *Instance) SaveHistory(content string) error {
|
||||||
return i.Operation.SaveHistory(content)
|
return i.Operation.SaveHistory(content)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue