forked from mirror/readline
fix runebuf
This commit is contained in:
parent
c9aba7b858
commit
f8c012aa53
32
runebuf.go
32
runebuf.go
|
@ -178,37 +178,25 @@ func (r *RuneBuffer) RefreshSet(originLength, originIdx int) {
|
||||||
|
|
||||||
func (r *RuneBuffer) Output(originLength, originIdx int, prompt bool) []byte {
|
func (r *RuneBuffer) Output(originLength, originIdx int, prompt bool) []byte {
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
buf.Write(bytes.Repeat([]byte{'\b'}, originIdx))
|
buf.Write(r.CleanOutput())
|
||||||
if prompt {
|
|
||||||
if r.hasPrompt {
|
|
||||||
buf.Write(bytes.Repeat([]byte{'\b'}, len(r.prompt)))
|
|
||||||
}
|
|
||||||
buf.Write(r.prompt)
|
buf.Write(r.prompt)
|
||||||
}
|
|
||||||
r.hasPrompt = prompt
|
r.hasPrompt = prompt
|
||||||
buf.Write([]byte(string(r.buf)))
|
buf.Write([]byte(string(r.buf)))
|
||||||
if originLength > len(r.buf) {
|
|
||||||
buf.Write(bytes.Repeat([]byte{' '}, originLength-len(r.buf)))
|
|
||||||
buf.Write(bytes.Repeat([]byte{'\b'}, originLength-len(r.buf)))
|
|
||||||
}
|
|
||||||
buf.Write(bytes.Repeat([]byte{'\b'}, len(r.buf)-r.idx))
|
buf.Write(bytes.Repeat([]byte{'\b'}, len(r.buf)-r.idx))
|
||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RuneBuffer) Clean() {
|
func (r *RuneBuffer) CleanOutput() []byte {
|
||||||
moveToFirst := r.idx
|
buf := bytes.NewBuffer(nil)
|
||||||
if r.hasPrompt {
|
buf.Write([]byte("\033[J"))
|
||||||
moveToFirst += len(r.prompt)
|
for i := 0; i <= 100; i++ {
|
||||||
|
buf.WriteString("\033[2K\r\b")
|
||||||
}
|
}
|
||||||
r.w.Write(bytes.Repeat([]byte{'\b'}, moveToFirst))
|
return buf.Bytes()
|
||||||
length := len(r.buf)
|
}
|
||||||
if r.hasPrompt {
|
|
||||||
length += len(r.prompt)
|
|
||||||
}
|
|
||||||
r.w.Write(bytes.Repeat([]byte{' '}, length))
|
|
||||||
|
|
||||||
r.w.Write(bytes.Repeat([]byte{'\b'}, length))
|
func (r *RuneBuffer) Clean() {
|
||||||
r.hasPrompt = false
|
r.w.Write(r.CleanOutput())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RuneBuffer) ResetScreen() {
|
func (r *RuneBuffer) ResetScreen() {
|
||||||
|
|
Loading…
Reference in New Issue