forked from mirror/readline
remove SplitByMultiLine
This commit is contained in:
parent
b1b67f8632
commit
e5e328dcc7
10
runebuf.go
10
runebuf.go
|
@ -30,17 +30,7 @@ type RuneBuffer struct {
|
|||
}
|
||||
|
||||
func (r *RuneBuffer) OnWidthChange(newWidth int) {
|
||||
oldWidth := r.width
|
||||
if newWidth < oldWidth {
|
||||
sp := SplitByMultiLine(
|
||||
r.PromptLen(), oldWidth, newWidth, r.buf[:r.idx])
|
||||
idxLine := len(sp) - 1
|
||||
r.clean(idxLine)
|
||||
} else {
|
||||
r.Clean()
|
||||
}
|
||||
r.width = newWidth
|
||||
r.print()
|
||||
}
|
||||
|
||||
func (r *RuneBuffer) Backup() {
|
||||
|
|
23
utils.go
23
utils.go
|
@ -86,29 +86,6 @@ func escapeKey(r rune) rune {
|
|||
return r
|
||||
}
|
||||
|
||||
func SplitByMultiLine(start, oldWidth, newWidth int, rs []rune) []string {
|
||||
var ret []string
|
||||
buf := bytes.NewBuffer(nil)
|
||||
currentWidth := start
|
||||
for _, r := range rs {
|
||||
w := runes.Width(r)
|
||||
currentWidth += w
|
||||
buf.WriteRune(r)
|
||||
if currentWidth == newWidth {
|
||||
ret = append(ret, buf.String())
|
||||
buf.Reset()
|
||||
continue
|
||||
}
|
||||
if currentWidth >= oldWidth {
|
||||
ret = append(ret, buf.String())
|
||||
buf.Reset()
|
||||
currentWidth = 0
|
||||
}
|
||||
}
|
||||
ret = append(ret, buf.String())
|
||||
return ret
|
||||
}
|
||||
|
||||
func SplitByLine(start, screenWidth int, rs []rune) []string {
|
||||
var ret []string
|
||||
buf := bytes.NewBuffer(nil)
|
||||
|
|
Loading…
Reference in New Issue