1
1
Fork 0

Does a print for the line vs per char

This commit is contained in:
sloum 2021-04-02 14:34:14 -07:00
parent 59005c5800
commit 1aa59e8f4b
1 changed files with 25 additions and 7 deletions

32
main.go
View File

@ -64,18 +64,36 @@ func (lb *Buffer) addChar(c rune, echo bool) {
if lb.cursor == len(lb.buf) {
lb.buf = append(lb.buf, c)
lb.cursor++
if echo {
fmt.Printf("%c", c)
}
// if echo {
// fmt.Printf("%c", c)
// }
} else {
lb.buf = append(lb.buf[:lb.cursor+1], lb.buf[lb.cursor:]...)
lb.buf[lb.cursor] = c
lb.cursor++
if echo {
s := string(lb.buf[lb.cursor-1:])
fmt.Printf("%s\033[%dD", s, len(s)-1)
}
// if echo {
// s := string(lb.buf[lb.cursor-1:])
// fmt.Printf("%s\033[%dD", s, len(s)-1)
// }
}
if echo {
lb.printBuf()
}
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
func (lb Buffer) printBuf() {
out := lb.buf[lb.offset:min(len(lb.buf), lb.offset+lb.maxWidth)]
if lb.cursor - 1 != 0 {
fmt.Printf("\033[%dD", lb.cursor-1)
}
fmt.Printf("%s\033[%dD\033[%dC", string(out), len(out), lb.cursor)
}
func (lb *Buffer) controlInput(c rune) {