2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-03-30 10:13:23 +00:00

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
This commit is contained in:
TorchedSammy 2022-10-10 18:17:58 -04:00
parent 7db2a2c826
commit 308e257872
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD

View File

@ -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