From 0d99dde4a85ecc33eab3a4457c7be4d138d11e2a Mon Sep 17 00:00:00 2001 From: shendiaomo Date: Mon, 21 Oct 2019 12:26:54 +0800 Subject: [PATCH 1/2] Support multi-line paste --- prompt.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/prompt.go b/prompt.go index 4e3ef436..b342905d 100644 --- a/prompt.go +++ b/prompt.go @@ -254,7 +254,16 @@ func (p *Prompt) readBuffer(bufCh chan []byte, stopCh chan struct{}) { return default: if b, err := p.in.Read(); err == nil && !(len(b) == 1 && b[0] == 0) { - bufCh <- b + start := 0 + for i, e := range b { + switch GetKey([] byte{e}) { + case Enter, ControlJ, ControlM: + bufCh <- b[start:i] + bufCh <- [] byte{e} + start = i + 1 + } + } + bufCh <- b[start:] } } time.Sleep(10 * time.Millisecond) From 1d18ad61d3db9cc7d9bc15018c6d8a2446b475c0 Mon Sep 17 00:00:00 2001 From: shendiaomo Date: Tue, 22 Oct 2019 11:51:21 +0800 Subject: [PATCH 2/2] Fix style --- prompt.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prompt.go b/prompt.go index b342905d..bcb1623a 100644 --- a/prompt.go +++ b/prompt.go @@ -256,10 +256,10 @@ func (p *Prompt) readBuffer(bufCh chan []byte, stopCh chan struct{}) { if b, err := p.in.Read(); err == nil && !(len(b) == 1 && b[0] == 0) { start := 0 for i, e := range b { - switch GetKey([] byte{e}) { - case Enter, ControlJ, ControlM: + switch GetKey([]byte{e}) { + case Enter, ControlJ, ControlM: bufCh <- b[start:i] - bufCh <- [] byte{e} + bufCh <- []byte{e} start = i + 1 } }