Closed ERnsTL closed 6 years ago
It's a cursor position, so length in runes is correct. You can't place the cursor half way though a rune. Actually, it really should ignore combining code points (and maybe even count doublewidth runes twice), but it's too late to fix that now (it would be an incompatible change to the API).
With all that said, it shouldn't crash. Especially since larger-than-string-length is documented to work.
So if I understand correctly: Avoiding the string-to-[]rune conversion would only be possible with a breaking API change?
Thus to avoid breaking the API, the string-to-[]rune conversion is neccessary and cannot be avoided?
While true, that's not quite what I was trying to say. Allow me to try again:
Thanks Peter for taking the time for the detailed response and the fix in 8c1271fcf47f341a9e6771872262870e1ad7650c - now everything makes sense :-)
Learned a bit about terminal design (screen-space vs. Unicode).
Also thanks for the -1
special case - I will use that.
I didn't know about utf8.RuneCountInString(str)
- thanks for the optimization pointer as well!
Great library of yours 👍 Looking forward to using it more projects. All the best!
goroutine 1 [running]: github.com/peterh/liner.(State).refreshSingleLine(0xc4200c4640, 0xc4201492d8, 0x7, 0x20, 0xc4201ae000, 0x50, 0x50, 0x52, 0x0, 0xc4201490d0) /home/x/code/go/src/github.com/peterh/liner/line.go:109 +0x632 github.com/peterh/liner.(State).refresh(0xc4200c4640, 0xc4201492d8, 0x7, 0x20, 0xc4201ae000, 0x50, 0x50, 0x52, 0x4ad03c, 0xc4200173a2) /home/x/code/go/src/github.com/peterh/liner/line.go:96 +0x108 github.com/peterh/liner.(*State).PromptWithSuggestion(0xc4200c4640, 0x6f6d00, 0x7, 0xc42006e2a0, 0x52, 0x52, 0x0, 0x0, 0x0, 0x0) /home/x/code/go/src/github.com/peterh/liner/line.go:601 +0x3c49 main.edittaskHandler(0xc4201a2180, 0x4, 0x4) [...]
package main
import ( "fmt" "io"
)
func main() { // open terminal line := liner.NewLiner() if !liner.TerminalSupported() { fmt.Println("WARNING: terminal not supported") } defer line.Close()
}