From 30ec85bccf28e38f25caba3f909e7e1046f751a8 Mon Sep 17 00:00:00 2001 From: Satoshi Kinoshita Date: Wed, 13 Mar 2019 15:40:38 +0900 Subject: [PATCH 1/5] fix issule #169 for single line case --- runebuf.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runebuf.go b/runebuf.go index 81d2da5..1e054c0 100644 --- a/runebuf.go +++ b/runebuf.go @@ -597,8 +597,8 @@ func (r *RuneBuffer) cleanOutput(w io.Writer, idxLine int) { } else { buf.Write([]byte("\033[J")) // just like ^k :) if idxLine == 0 { - buf.WriteString("\033[2K") - buf.WriteString("\r") + buf.WriteString(strings.Repeat("\033[D", r.idx + r.promptLen())) + buf.Write([]byte("\033[J")) } else { for i := 0; i < idxLine; i++ { io.WriteString(buf, "\033[2K\r\033[A") From 4ef58bee6015eec1c8099e3dc2d2c131db56a665 Mon Sep 17 00:00:00 2001 From: Satoshi Kinoshita Date: Wed, 13 Mar 2019 16:15:41 +0900 Subject: [PATCH 2/5] fix issule #169 for single line case --- operation.go | 2 +- runebuf.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/operation.go b/operation.go index 4c31624..a5f32fa 100644 --- a/operation.go +++ b/operation.go @@ -385,7 +385,7 @@ func (o *Operation) Runes() ([]rune, error) { listener.OnChange(nil, 0, 0) } - o.buf.Refresh(nil) // print prompt + o.buf.PrintPrompt() // print prompt o.t.KickRead() select { case r := <-o.outchan: diff --git a/runebuf.go b/runebuf.go index 1e054c0..4e4627c 100644 --- a/runebuf.go +++ b/runebuf.go @@ -471,6 +471,12 @@ func (r *RuneBuffer) SetOffset(offset string) { r.Unlock() } +func (r *RuneBuffer) PrintPrompt() { + r.Lock() + r.print() + r.Unlock() +} + func (r *RuneBuffer) print() { r.w.Write(r.output()) r.hadClean = false From 779fc2ceca3d51e25e3efe975d51e8aea3382ced Mon Sep 17 00:00:00 2001 From: Satoshi Kinoshita Date: Thu, 14 Mar 2019 09:44:37 +0900 Subject: [PATCH 3/5] fix issule #169 for single line case --- operation.go | 2 +- runebuf.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/operation.go b/operation.go index a5f32fa..c357f40 100644 --- a/operation.go +++ b/operation.go @@ -385,7 +385,7 @@ func (o *Operation) Runes() ([]rune, error) { listener.OnChange(nil, 0, 0) } - o.buf.PrintPrompt() // print prompt + o.buf.Print() // print prompt o.t.KickRead() select { case r := <-o.outchan: diff --git a/runebuf.go b/runebuf.go index 4e4627c..6059b22 100644 --- a/runebuf.go +++ b/runebuf.go @@ -471,7 +471,7 @@ func (r *RuneBuffer) SetOffset(offset string) { r.Unlock() } -func (r *RuneBuffer) PrintPrompt() { +func (r *RuneBuffer) Print() { r.Lock() r.print() r.Unlock() From 45cb5208e8ff42601523ad6ac0ae3408801dcf8d Mon Sep 17 00:00:00 2001 From: Satoshi Kinoshita Date: Thu, 14 Mar 2019 16:47:47 +0900 Subject: [PATCH 4/5] use shorter escape sequence --- runebuf.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runebuf.go b/runebuf.go index 6059b22..432ab59 100644 --- a/runebuf.go +++ b/runebuf.go @@ -603,7 +603,8 @@ func (r *RuneBuffer) cleanOutput(w io.Writer, idxLine int) { } else { buf.Write([]byte("\033[J")) // just like ^k :) if idxLine == 0 { - buf.WriteString(strings.Repeat("\033[D", r.idx + r.promptLen())) + num := strconv.Itoa(r.idx + r.promptLen()) + buf.WriteString("\033[" + num + "D") buf.Write([]byte("\033[J")) } else { for i := 0; i < idxLine; i++ { From 5407ea7a3c42d5b0d89f3889d4368e51dc941566 Mon Sep 17 00:00:00 2001 From: Thomas O'Dowd Date: Wed, 16 Mar 2022 11:59:53 +0900 Subject: [PATCH 5/5] Fix for non-interactive mode when there is no terminal Originally the code called Refresh(nil). This had handling for non-interactive mode where the code would return without printing a prompt. When issue169 was initially fixed, the interactive part of this was mistakenly dropped. This puts the interactive check back into the flow. --- runebuf.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runebuf.go b/runebuf.go index 432ab59..5b63955 100644 --- a/runebuf.go +++ b/runebuf.go @@ -472,9 +472,12 @@ func (r *RuneBuffer) SetOffset(offset string) { } func (r *RuneBuffer) Print() { + if !r.interactive { + return + } r.Lock() + defer r.Unlock() r.print() - r.Unlock() } func (r *RuneBuffer) print() {