2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-17 10:35:17 +00:00
restic/internal/ui/termstatus/terminal_posix.go
Alexander Neumann 1af96fc6dd Add termstatus
2018-04-27 21:42:15 +02:00

34 lines
751 B
Go

package termstatus
import (
"fmt"
"io"
"os"
)
const (
posixMoveCursorHome = "\r"
posixMoveCursorUp = "\x1b[1A"
posixClearLine = "\x1b[2K"
)
// posixClearLines will clear the current line and the n lines above.
// Afterwards the cursor is positioned at the start of the first cleared line.
func posixClearLines(wr io.Writer, fd uintptr, n int) {
// clear current line
_, err := wr.Write([]byte(posixMoveCursorHome + posixClearLine))
if err != nil {
fmt.Fprintf(os.Stderr, "write failed: %v\n", err)
return
}
for ; n > 0; n-- {
// clear current line and move on line up
_, err := wr.Write([]byte(posixMoveCursorUp + posixClearLine))
if err != nil {
fmt.Fprintf(os.Stderr, "write failed: %v\n", err)
return
}
}
}