blob: bedf9528eee2130ac2782ad237960880eec65eb9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
package statusline
import (
"fmt"
"io"
)
type StatusLine interface {
Put(line string)
End(keep bool)
}
type statusLine struct {
out io.Writer
prevLen int
}
func New(out io.Writer) StatusLine {
return &statusLine{out: out}
}
func (sl *statusLine) Put(line string) {
fmt.Fprintf(sl.out, "\r%-[1]*[2]s", sl.prevLen, line)
sl.prevLen = len(line)
}
func (sl *statusLine) End(keep bool) {
if keep {
io.WriteString(sl.out, "\n")
} else {
fmt.Fprintf(sl.out, "\r%-[1]*[2]s\r", sl.prevLen, "")
}
}
|