From 41eea22f717c616615e1e59aa06cf831f9901f35 Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Mon, 13 Mar 2017 19:49:21 -0400 Subject: [PATCH] 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. --- operation.go | 4 ++++ readline.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/operation.go b/operation.go index 14ade31..2c93561 100644 --- a/operation.go +++ b/operation.go @@ -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 diff --git a/readline.go b/readline.go index 3f02a83..b0242f7 100644 --- a/readline.go +++ b/readline.go @@ -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) }