mirror of
https://github.com/octoleo/restic.git
synced 2024-11-12 00:06:35 +00:00
472bf5184f
The parameters are required by the implemented function signature or interface.
37 lines
918 B
Go
37 lines
918 B
Go
package termstatus
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
const (
|
|
posixControlMoveCursorHome = "\r"
|
|
posixControlMoveCursorUp = "\x1b[1A"
|
|
posixControlClearLine = "\x1b[2K"
|
|
)
|
|
|
|
// posixClearCurrentLine removes all characters from the current line and resets the
|
|
// cursor position to the first column.
|
|
func posixClearCurrentLine(wr io.Writer, _ uintptr) {
|
|
// clear current line
|
|
_, err := wr.Write([]byte(posixControlMoveCursorHome + posixControlClearLine))
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "write failed: %v\n", err)
|
|
return
|
|
}
|
|
}
|
|
|
|
// posixMoveCursorUp moves the cursor to the line n lines above the current one.
|
|
func posixMoveCursorUp(wr io.Writer, _ 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
|
|
}
|
|
}
|