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
builtins
TorchedSammy 2022-10-10 18:17:58 -04:00
parent 7db2a2c826
commit 308e257872
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 11 additions and 7 deletions

View File

@ -1,6 +1,10 @@
package readline 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: // updateHelpers is a key part of the whole refresh process:
// it should coordinate reprinting the input line, any Infos and completions // it should coordinate reprinting the input line, any Infos and completions
@ -52,19 +56,19 @@ func (rl *Instance) updateReferences() {
rl.posY = 0 rl.posY = 0
rl.fullY = 0 rl.fullY = 0
var fullLine, cPosLine int var curLine []rune
if len(rl.currentComp) > 0 { if len(rl.currentComp) > 0 {
fullLine = getWidth(rl.lineComp) curLine = rl.lineComp
cPosLine = getWidth(rl.lineComp[:rl.pos])
} else { } else {
fullLine = getWidth(rl.line) curLine = rl.line
cPosLine = getWidth(rl.line[:rl.pos])
} }
fullLine := getWidth(curLine)
cPosLine := getWidth(curLine[:rl.pos])
// We need the X offset of the whole line // We need the X offset of the whole line
toEndLine := rl.promptLen + fullLine toEndLine := rl.promptLen + fullLine
fullOffset := toEndLine / GetTermWidth() fullOffset := toEndLine / GetTermWidth()
rl.fullY = fullOffset rl.fullY = fullOffset + strings.Count(string(curLine), "\n")
fullRest := toEndLine % GetTermWidth() fullRest := toEndLine % GetTermWidth()
rl.fullX = fullRest rl.fullX = fullRest