summaryrefslogtreecommitdiff
path: root/vendor/github.com/vbauerster/mpb/v6/cwriter
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2021-03-15 14:52:43 -0500
committerbaude <bbaude@redhat.com>2021-03-25 08:43:51 -0500
commitb5f54a9b23e8d9418700494da9aa78d8db354c43 (patch)
tree59dfb9edf3faf6d184f6af40522f71968948133a /vendor/github.com/vbauerster/mpb/v6/cwriter
parenta861f6fd3ebe4fe0b63a1b550e6b99d7525228c0 (diff)
downloadpodman-b5f54a9b23e8d9418700494da9aa78d8db354c43.tar.gz
podman-b5f54a9b23e8d9418700494da9aa78d8db354c43.tar.bz2
podman-b5f54a9b23e8d9418700494da9aa78d8db354c43.zip
introduce podman machine
podman machine allows podman to create, manage, and interact with a vm running some form of linux (default is fcos). podman is then configured to be able to interact with the vm automatically. while this is usable on linux, the real push is to get this working on both current apple architectures in macos. Ashley Cui contributed to this PR and was a great help. [NO TESTS NEEDED] Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'vendor/github.com/vbauerster/mpb/v6/cwriter')
-rw-r--r--vendor/github.com/vbauerster/mpb/v6/cwriter/doc.go2
-rw-r--r--vendor/github.com/vbauerster/mpb/v6/cwriter/util_bsd.go7
-rw-r--r--vendor/github.com/vbauerster/mpb/v6/cwriter/util_linux.go7
-rw-r--r--vendor/github.com/vbauerster/mpb/v6/cwriter/util_solaris.go7
-rw-r--r--vendor/github.com/vbauerster/mpb/v6/cwriter/writer.go84
-rw-r--r--vendor/github.com/vbauerster/mpb/v6/cwriter/writer_posix.go26
-rw-r--r--vendor/github.com/vbauerster/mpb/v6/cwriter/writer_windows.go73
7 files changed, 206 insertions, 0 deletions
diff --git a/vendor/github.com/vbauerster/mpb/v6/cwriter/doc.go b/vendor/github.com/vbauerster/mpb/v6/cwriter/doc.go
new file mode 100644
index 000000000..93c8f8268
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v6/cwriter/doc.go
@@ -0,0 +1,2 @@
+// Package cwriter is a console writer abstraction for the underlying OS.
+package cwriter
diff --git a/vendor/github.com/vbauerster/mpb/v6/cwriter/util_bsd.go b/vendor/github.com/vbauerster/mpb/v6/cwriter/util_bsd.go
new file mode 100644
index 000000000..4e3564ece
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v6/cwriter/util_bsd.go
@@ -0,0 +1,7 @@
+// +build darwin dragonfly freebsd netbsd openbsd
+
+package cwriter
+
+import "golang.org/x/sys/unix"
+
+const ioctlReadTermios = unix.TIOCGETA
diff --git a/vendor/github.com/vbauerster/mpb/v6/cwriter/util_linux.go b/vendor/github.com/vbauerster/mpb/v6/cwriter/util_linux.go
new file mode 100644
index 000000000..253f12dd2
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v6/cwriter/util_linux.go
@@ -0,0 +1,7 @@
+// +build aix linux
+
+package cwriter
+
+import "golang.org/x/sys/unix"
+
+const ioctlReadTermios = unix.TCGETS
diff --git a/vendor/github.com/vbauerster/mpb/v6/cwriter/util_solaris.go b/vendor/github.com/vbauerster/mpb/v6/cwriter/util_solaris.go
new file mode 100644
index 000000000..4b29ff5c0
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v6/cwriter/util_solaris.go
@@ -0,0 +1,7 @@
+// +build solaris
+
+package cwriter
+
+import "golang.org/x/sys/unix"
+
+const ioctlReadTermios = unix.TCGETA
diff --git a/vendor/github.com/vbauerster/mpb/v6/cwriter/writer.go b/vendor/github.com/vbauerster/mpb/v6/cwriter/writer.go
new file mode 100644
index 000000000..1ade54761
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v6/cwriter/writer.go
@@ -0,0 +1,84 @@
+package cwriter
+
+import (
+ "bytes"
+ "errors"
+ "io"
+ "os"
+ "strconv"
+)
+
+// ErrNotTTY not a TeleTYpewriter error.
+var ErrNotTTY = errors.New("not a terminal")
+
+// http://ascii-table.com/ansi-escape-sequences.php
+const (
+ escOpen = "\x1b["
+ cuuAndEd = "A\x1b[J"
+)
+
+// Writer is a buffered the writer that updates the terminal. The
+// contents of writer will be flushed when Flush is called.
+type Writer struct {
+ out io.Writer
+ buf bytes.Buffer
+ lineCount int
+ fd int
+ isTerminal bool
+}
+
+// New returns a new Writer with defaults.
+func New(out io.Writer) *Writer {
+ w := &Writer{out: out}
+ if f, ok := out.(*os.File); ok {
+ w.fd = int(f.Fd())
+ w.isTerminal = IsTerminal(w.fd)
+ }
+ return w
+}
+
+// Flush flushes the underlying buffer.
+func (w *Writer) Flush(lineCount int) (err error) {
+ // some terminals interpret 'cursor up 0' as 'cursor up 1'
+ if w.lineCount > 0 {
+ err = w.clearLines()
+ if err != nil {
+ return
+ }
+ }
+ w.lineCount = lineCount
+ _, err = w.buf.WriteTo(w.out)
+ return
+}
+
+// Write appends the contents of p to the underlying buffer.
+func (w *Writer) Write(p []byte) (n int, err error) {
+ return w.buf.Write(p)
+}
+
+// WriteString writes string to the underlying buffer.
+func (w *Writer) WriteString(s string) (n int, err error) {
+ return w.buf.WriteString(s)
+}
+
+// ReadFrom reads from the provided io.Reader and writes to the
+// underlying buffer.
+func (w *Writer) ReadFrom(r io.Reader) (n int64, err error) {
+ return w.buf.ReadFrom(r)
+}
+
+// GetWidth returns width of underlying terminal.
+func (w *Writer) GetWidth() (int, error) {
+ if !w.isTerminal {
+ return -1, ErrNotTTY
+ }
+ tw, _, err := GetSize(w.fd)
+ return tw, err
+}
+
+func (w *Writer) ansiCuuAndEd() (err error) {
+ buf := make([]byte, 8)
+ buf = strconv.AppendInt(buf[:copy(buf, escOpen)], int64(w.lineCount), 10)
+ _, err = w.out.Write(append(buf, cuuAndEd...))
+ return
+}
diff --git a/vendor/github.com/vbauerster/mpb/v6/cwriter/writer_posix.go b/vendor/github.com/vbauerster/mpb/v6/cwriter/writer_posix.go
new file mode 100644
index 000000000..f54a5d06b
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v6/cwriter/writer_posix.go
@@ -0,0 +1,26 @@
+// +build !windows
+
+package cwriter
+
+import (
+ "golang.org/x/sys/unix"
+)
+
+func (w *Writer) clearLines() error {
+ return w.ansiCuuAndEd()
+}
+
+// GetSize returns the dimensions of the given terminal.
+func GetSize(fd int) (width, height int, err error) {
+ ws, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ)
+ if err != nil {
+ return -1, -1, err
+ }
+ return int(ws.Col), int(ws.Row), nil
+}
+
+// IsTerminal returns whether the given file descriptor is a terminal.
+func IsTerminal(fd int) bool {
+ _, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
+ return err == nil
+}
diff --git a/vendor/github.com/vbauerster/mpb/v6/cwriter/writer_windows.go b/vendor/github.com/vbauerster/mpb/v6/cwriter/writer_windows.go
new file mode 100644
index 000000000..1a69c81ac
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v6/cwriter/writer_windows.go
@@ -0,0 +1,73 @@
+// +build windows
+
+package cwriter
+
+import (
+ "unsafe"
+
+ "golang.org/x/sys/windows"
+)
+
+var kernel32 = windows.NewLazySystemDLL("kernel32.dll")
+
+var (
+ procSetConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition")
+ procFillConsoleOutputCharacter = kernel32.NewProc("FillConsoleOutputCharacterW")
+)
+
+func (w *Writer) clearLines() error {
+ if !w.isTerminal {
+ // hope it's cygwin or similar
+ return w.ansiCuuAndEd()
+ }
+
+ var info windows.ConsoleScreenBufferInfo
+ if err := windows.GetConsoleScreenBufferInfo(windows.Handle(w.fd), &info); err != nil {
+ return err
+ }
+
+ info.CursorPosition.Y -= int16(w.lineCount)
+ if info.CursorPosition.Y < 0 {
+ info.CursorPosition.Y = 0
+ }
+ _, _, _ = procSetConsoleCursorPosition.Call(
+ uintptr(w.fd),
+ uintptr(uint32(uint16(info.CursorPosition.Y))<<16|uint32(uint16(info.CursorPosition.X))),
+ )
+
+ // clear the lines
+ cursor := &windows.Coord{
+ X: info.Window.Left,
+ Y: info.CursorPosition.Y,
+ }
+ count := uint32(info.Size.X) * uint32(w.lineCount)
+ _, _, _ = procFillConsoleOutputCharacter.Call(
+ uintptr(w.fd),
+ uintptr(' '),
+ uintptr(count),
+ *(*uintptr)(unsafe.Pointer(cursor)),
+ uintptr(unsafe.Pointer(new(uint32))),
+ )
+ return nil
+}
+
+// GetSize returns the visible dimensions of the given terminal.
+//
+// These dimensions don't include any scrollback buffer height.
+func GetSize(fd int) (width, height int, err error) {
+ var info windows.ConsoleScreenBufferInfo
+ if err := windows.GetConsoleScreenBufferInfo(windows.Handle(fd), &info); err != nil {
+ return 0, 0, err
+ }
+ // terminal.GetSize from crypto/ssh adds "+ 1" to both width and height:
+ // https://go.googlesource.com/crypto/+/refs/heads/release-branch.go1.14/ssh/terminal/util_windows.go#75
+ // but looks like this is a root cause of issue #66, so removing both "+ 1" have fixed it.
+ return int(info.Window.Right - info.Window.Left), int(info.Window.Bottom - info.Window.Top), nil
+}
+
+// IsTerminal returns whether the given file descriptor is a terminal.
+func IsTerminal(fd int) bool {
+ var st uint32
+ err := windows.GetConsoleMode(windows.Handle(fd), &st)
+ return err == nil
+}