mirror of
https://github.com/octoleo/restic.git
synced 2024-11-05 12:57:53 +00:00
37 lines
894 B
Go
37 lines
894 B
Go
//go:build !windows
|
|
// +build !windows
|
|
|
|
package termstatus
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
|
|
"golang.org/x/term"
|
|
)
|
|
|
|
// clearCurrentLine removes all characters from the current line and resets the
|
|
// cursor position to the first column.
|
|
func clearCurrentLine(wr io.Writer, fd uintptr) func(io.Writer, uintptr) {
|
|
return posixClearCurrentLine
|
|
}
|
|
|
|
// moveCursorUp moves the cursor to the line n lines above the current one.
|
|
func moveCursorUp(wr io.Writer, fd uintptr) func(io.Writer, uintptr, int) {
|
|
return posixMoveCursorUp
|
|
}
|
|
|
|
// CanUpdateStatus returns true if status lines can be printed, the process
|
|
// output is not redirected to a file or pipe.
|
|
func CanUpdateStatus(fd uintptr) bool {
|
|
if !term.IsTerminal(int(fd)) {
|
|
return false
|
|
}
|
|
term := os.Getenv("TERM")
|
|
if term == "" {
|
|
return false
|
|
}
|
|
// TODO actually read termcap db and detect if terminal supports what we need
|
|
return term != "dumb"
|
|
}
|