mirror of
https://github.com/restic/restic.git
synced 2025-10-26 13:50:58 +00:00
Add termstatus
This commit is contained in:
33
internal/ui/termstatus/terminal_posix.go
Normal file
33
internal/ui/termstatus/terminal_posix.go
Normal file
@@ -0,0 +1,33 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user