summaryrefslogtreecommitdiff
path: root/vendor/github.com/vbauerster/mpb/v4/cwriter
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2019-12-19 13:29:25 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2019-12-20 09:30:47 -0500
commit50ece79387dcf6c748e3ae1bd6a7067059c0dfe3 (patch)
tree6b30c4f66f7be315ff2257447be3818be98fb50f /vendor/github.com/vbauerster/mpb/v4/cwriter
parenta359ca0d1825859dd8b7c1384f11d703ec6625b4 (diff)
downloadpodman-50ece79387dcf6c748e3ae1bd6a7067059c0dfe3.tar.gz
podman-50ece79387dcf6c748e3ae1bd6a7067059c0dfe3.tar.bz2
podman-50ece79387dcf6c748e3ae1bd6a7067059c0dfe3.zip
build(deps): bump github.com/containers/image/v5 from 5.0.0 to 5.1.0
Bumps [github.com/containers/image/v5](https://github.com/containers/image) from 5.0.0 to 5.1.0. - [Release notes](https://github.com/containers/image/releases) - [Commits](https://github.com/containers/image/compare/v5.0.0...v5.1.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'vendor/github.com/vbauerster/mpb/v4/cwriter')
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/cwriter/writer.go71
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/cwriter/writer_posix.go9
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/cwriter/writer_windows.go60
3 files changed, 140 insertions, 0 deletions
diff --git a/vendor/github.com/vbauerster/mpb/v4/cwriter/writer.go b/vendor/github.com/vbauerster/mpb/v4/cwriter/writer.go
new file mode 100644
index 000000000..9ec1ec66b
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/cwriter/writer.go
@@ -0,0 +1,71 @@
+package cwriter
+
+import (
+ "bytes"
+ "errors"
+ "fmt"
+ "io"
+ "os"
+
+ "golang.org/x/crypto/ssh/terminal"
+)
+
+// NotATTY not a TeleTYpewriter error.
+var NotATTY = errors.New("not a terminal")
+
+var cuuAndEd = fmt.Sprintf("%c[%%dA%[1]c[J", 27)
+
+// 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 uintptr
+ 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 = f.Fd()
+ w.isTerminal = terminal.IsTerminal(int(w.fd))
+ }
+ return w
+}
+
+// Flush flushes the underlying buffer.
+func (w *Writer) Flush(lineCount int) (err error) {
+ if w.lineCount > 0 {
+ w.clearLines()
+ }
+ 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 {
+ tw, _, err := terminal.GetSize(int(w.fd))
+ return tw, err
+ }
+ return -1, NotATTY
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/cwriter/writer_posix.go b/vendor/github.com/vbauerster/mpb/v4/cwriter/writer_posix.go
new file mode 100644
index 000000000..3fb8b7d75
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/cwriter/writer_posix.go
@@ -0,0 +1,9 @@
+// +build !windows
+
+package cwriter
+
+import "fmt"
+
+func (w *Writer) clearLines() {
+ fmt.Fprintf(w.out, cuuAndEd, w.lineCount)
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/cwriter/writer_windows.go b/vendor/github.com/vbauerster/mpb/v4/cwriter/writer_windows.go
new file mode 100644
index 000000000..712528900
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/cwriter/writer_windows.go
@@ -0,0 +1,60 @@
+// +build windows
+
+package cwriter
+
+import (
+ "fmt"
+ "syscall"
+ "unsafe"
+)
+
+var kernel32 = syscall.NewLazyDLL("kernel32.dll")
+
+var (
+ procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo")
+ procSetConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition")
+ procFillConsoleOutputCharacter = kernel32.NewProc("FillConsoleOutputCharacterW")
+ procFillConsoleOutputAttribute = kernel32.NewProc("FillConsoleOutputAttribute")
+)
+
+type coord struct {
+ x int16
+ y int16
+}
+
+type smallRect struct {
+ left int16
+ top int16
+ right int16
+ bottom int16
+}
+
+type consoleScreenBufferInfo struct {
+ size coord
+ cursorPosition coord
+ attributes uint16
+ window smallRect
+ maximumWindowSize coord
+}
+
+func (w *Writer) clearLines() {
+ if !w.isTerminal {
+ fmt.Fprintf(w.out, cuuAndEd, w.lineCount)
+ }
+ var info consoleScreenBufferInfo
+ procGetConsoleScreenBufferInfo.Call(w.fd, uintptr(unsafe.Pointer(&info)))
+
+ info.cursorPosition.y -= int16(w.lineCount)
+ if info.cursorPosition.y < 0 {
+ info.cursorPosition.y = 0
+ }
+ procSetConsoleCursorPosition.Call(w.fd, uintptr(uint32(uint16(info.cursorPosition.y))<<16|uint32(uint16(info.cursorPosition.x))))
+
+ // clear the lines
+ cursor := coord{
+ x: info.window.left,
+ y: info.cursorPosition.y,
+ }
+ count := uint32(info.size.x) * uint32(w.lineCount)
+ procFillConsoleOutputCharacter.Call(w.fd, uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(new(uint32))))
+}