2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-18 11:05:18 +00:00
restic/internal/ui/termstatus/terminal_posix.go

37 lines
920 B
Go
Raw Normal View History

2018-04-22 09:57:11 +00:00
package termstatus
import (
"bytes"
2018-04-22 09:57:11 +00:00
"fmt"
"io"
"os"
)
const (
posixControlMoveCursorHome = "\r"
posixControlMoveCursorUp = "\x1b[1A"
posixControlClearLine = "\x1b[2K"
2018-04-22 09:57:11 +00:00
)
// posixClearCurrentLine removes all characters from the current line and resets the
// cursor position to the first column.
func posixClearCurrentLine(wr io.Writer, fd uintptr) {
2018-04-22 09:57:11 +00:00
// clear current line
_, err := wr.Write([]byte(posixControlMoveCursorHome + posixControlClearLine))
2018-04-22 09:57:11 +00:00
if err != nil {
fmt.Fprintf(os.Stderr, "write failed: %v\n", err)
return
}
}
2018-04-22 09:57:11 +00:00
// posixMoveCursorUp moves the cursor to the line n lines above the current one.
func posixMoveCursorUp(wr io.Writer, fd uintptr, n int) {
data := []byte(posixControlMoveCursorHome)
data = append(data, bytes.Repeat([]byte(posixControlMoveCursorUp), n)...)
_, err := wr.Write(data)
if err != nil {
fmt.Fprintf(os.Stderr, "write failed: %v\n", err)
return
2018-04-22 09:57:11 +00:00
}
}