From 308e2578722d61d236508a35b60a744f18ab4b39 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Mon, 10 Oct 2022 18:17:58 -0400 Subject: [PATCH] fix(readline): take into account newlines when calculating amount of lines taken up by input this does not really fix the issue of multiline input being broken completely, but prevents the prompt being reprinted on input --- readline/update.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/readline/update.go b/readline/update.go index 0c2de38..8f85c6d 100644 --- a/readline/update.go +++ b/readline/update.go @@ -1,6 +1,10 @@ package readline -import "golang.org/x/text/width" +import ( + "strings" + + "golang.org/x/text/width" +) // updateHelpers is a key part of the whole refresh process: // it should coordinate reprinting the input line, any Infos and completions @@ -52,19 +56,19 @@ func (rl *Instance) updateReferences() { rl.posY = 0 rl.fullY = 0 - var fullLine, cPosLine int + var curLine []rune if len(rl.currentComp) > 0 { - fullLine = getWidth(rl.lineComp) - cPosLine = getWidth(rl.lineComp[:rl.pos]) + curLine = rl.lineComp } else { - fullLine = getWidth(rl.line) - cPosLine = getWidth(rl.line[:rl.pos]) + curLine = rl.line } + fullLine := getWidth(curLine) + cPosLine := getWidth(curLine[:rl.pos]) // We need the X offset of the whole line toEndLine := rl.promptLen + fullLine fullOffset := toEndLine / GetTermWidth() - rl.fullY = fullOffset + rl.fullY = fullOffset + strings.Count(string(curLine), "\n") fullRest := toEndLine % GetTermWidth() rl.fullX = fullRest