2022-03-28 20:23:47 +00:00
|
|
|
//go:build !windows
|
2018-04-22 09:57:11 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package termstatus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2018-09-20 13:50:29 +00:00
|
|
|
"os"
|
2018-05-27 21:44:48 +00:00
|
|
|
|
2022-03-28 20:24:15 +00:00
|
|
|
"golang.org/x/term"
|
2018-04-22 09:57:11 +00:00
|
|
|
)
|
|
|
|
|
2018-05-07 19:40:07 +00:00
|
|
|
// clearCurrentLine removes all characters from the current line and resets the
|
|
|
|
// cursor position to the first column.
|
2023-05-18 17:30:44 +00:00
|
|
|
func clearCurrentLine(_ uintptr) func(io.Writer, uintptr) {
|
2018-05-07 19:40:07 +00:00
|
|
|
return posixClearCurrentLine
|
|
|
|
}
|
|
|
|
|
|
|
|
// moveCursorUp moves the cursor to the line n lines above the current one.
|
2023-05-18 17:30:44 +00:00
|
|
|
func moveCursorUp(_ uintptr) func(io.Writer, uintptr, int) {
|
2018-05-07 19:40:07 +00:00
|
|
|
return posixMoveCursorUp
|
2018-04-22 09:57:11 +00:00
|
|
|
}
|
|
|
|
|
2021-03-07 21:50:52 +00:00
|
|
|
// CanUpdateStatus returns true if status lines can be printed, the process
|
2018-04-22 09:57:11 +00:00
|
|
|
// output is not redirected to a file or pipe.
|
2021-03-07 21:50:52 +00:00
|
|
|
func CanUpdateStatus(fd uintptr) bool {
|
2022-03-28 20:24:15 +00:00
|
|
|
if !term.IsTerminal(int(fd)) {
|
2018-09-20 13:50:29 +00:00
|
|
|
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"
|
2018-04-22 09:57:11 +00:00
|
|
|
}
|