summaryrefslogtreecommitdiff
path: root/vendor/github.com/chzyer/readline/utils_unix.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-10-07 16:58:53 +0200
committerValentin Rothberg <rothberg@redhat.com>2020-11-13 15:40:06 +0100
commit8e4a42aa429c6dec0d5face7c69554d8a0677e96 (patch)
treebbfff77e7b32a8b46af6f57d42965a7751bec18e /vendor/github.com/chzyer/readline/utils_unix.go
parent0b1a60ec27928a40ac827148c1517098612616bd (diff)
downloadpodman-8e4a42aa429c6dec0d5face7c69554d8a0677e96.tar.gz
podman-8e4a42aa429c6dec0d5face7c69554d8a0677e96.tar.bz2
podman-8e4a42aa429c6dec0d5face7c69554d8a0677e96.zip
short-name aliasing
Add support for short-name aliasing. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/github.com/chzyer/readline/utils_unix.go')
-rw-r--r--vendor/github.com/chzyer/readline/utils_unix.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/vendor/github.com/chzyer/readline/utils_unix.go b/vendor/github.com/chzyer/readline/utils_unix.go
new file mode 100644
index 000000000..f88dac97b
--- /dev/null
+++ b/vendor/github.com/chzyer/readline/utils_unix.go
@@ -0,0 +1,83 @@
+// +build darwin dragonfly freebsd linux,!appengine netbsd openbsd solaris
+
+package readline
+
+import (
+ "io"
+ "os"
+ "os/signal"
+ "sync"
+ "syscall"
+)
+
+type winsize struct {
+ Row uint16
+ Col uint16
+ Xpixel uint16
+ Ypixel uint16
+}
+
+// SuspendMe use to send suspend signal to myself, when we in the raw mode.
+// For OSX it need to send to parent's pid
+// For Linux it need to send to myself
+func SuspendMe() {
+ p, _ := os.FindProcess(os.Getppid())
+ p.Signal(syscall.SIGTSTP)
+ p, _ = os.FindProcess(os.Getpid())
+ p.Signal(syscall.SIGTSTP)
+}
+
+// get width of the terminal
+func getWidth(stdoutFd int) int {
+ cols, _, err := GetSize(stdoutFd)
+ if err != nil {
+ return -1
+ }
+ return cols
+}
+
+func GetScreenWidth() int {
+ w := getWidth(syscall.Stdout)
+ if w < 0 {
+ w = getWidth(syscall.Stderr)
+ }
+ return w
+}
+
+// ClearScreen clears the console screen
+func ClearScreen(w io.Writer) (int, error) {
+ return w.Write([]byte("\033[H"))
+}
+
+func DefaultIsTerminal() bool {
+ return IsTerminal(syscall.Stdin) && (IsTerminal(syscall.Stdout) || IsTerminal(syscall.Stderr))
+}
+
+func GetStdin() int {
+ return syscall.Stdin
+}
+
+// -----------------------------------------------------------------------------
+
+var (
+ widthChange sync.Once
+ widthChangeCallback func()
+)
+
+func DefaultOnWidthChanged(f func()) {
+ widthChangeCallback = f
+ widthChange.Do(func() {
+ ch := make(chan os.Signal, 1)
+ signal.Notify(ch, syscall.SIGWINCH)
+
+ go func() {
+ for {
+ _, ok := <-ch
+ if !ok {
+ break
+ }
+ widthChangeCallback()
+ }
+ }()
+ })
+}