diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2019-06-24 11:29:13 +0200 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2019-06-24 13:20:59 +0200 |
commit | d697456dc90adbaf68224ed7c115b38d5855e582 (patch) | |
tree | 5fd88c48b34e7bead0028fa97e39f43f03880642 /vendor/github.com/fsouza/go-dockerclient/internal/jsonmessage | |
parent | a3211b73c62a9fcc13f09305bf629ef507b26d34 (diff) | |
download | podman-d697456dc90adbaf68224ed7c115b38d5855e582.tar.gz podman-d697456dc90adbaf68224ed7c115b38d5855e582.tar.bz2 podman-d697456dc90adbaf68224ed7c115b38d5855e582.zip |
migrate to go-modules
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/github.com/fsouza/go-dockerclient/internal/jsonmessage')
-rw-r--r-- | vendor/github.com/fsouza/go-dockerclient/internal/jsonmessage/jsonmessage.go | 125 |
1 files changed, 94 insertions, 31 deletions
diff --git a/vendor/github.com/fsouza/go-dockerclient/internal/jsonmessage/jsonmessage.go b/vendor/github.com/fsouza/go-dockerclient/internal/jsonmessage/jsonmessage.go index 71b3395ce..99a32ae05 100644 --- a/vendor/github.com/fsouza/go-dockerclient/internal/jsonmessage/jsonmessage.go +++ b/vendor/github.com/fsouza/go-dockerclient/internal/jsonmessage/jsonmessage.go @@ -12,9 +12,9 @@ import ( "strings" "time" - "github.com/Nvveen/Gotty" - "github.com/docker/go-units" + units "github.com/docker/go-units" "github.com/fsouza/go-dockerclient/internal/term" + gotty "github.com/ijc/Gotty" ) // RFC3339NanoFixed is time.RFC3339Nano with nanoseconds padded using zeros to @@ -144,13 +144,13 @@ type JSONMessage struct { Stream string `json:"stream,omitempty"` Status string `json:"status,omitempty"` Progress *JSONProgress `json:"progressDetail,omitempty"` - ProgressMessage string `json:"progress,omitempty"` //deprecated + ProgressMessage string `json:"progress,omitempty"` // deprecated ID string `json:"id,omitempty"` From string `json:"from,omitempty"` Time int64 `json:"time,omitempty"` TimeNano int64 `json:"timeNano,omitempty"` Error *JSONError `json:"errorDetail,omitempty"` - ErrorMessage string `json:"error,omitempty"` //deprecated + ErrorMessage string `json:"error,omitempty"` // deprecated // Aux contains out-of-band data, such as digests for push signing and image id after building. Aux *json.RawMessage `json:"aux,omitempty"` } @@ -166,43 +166,72 @@ func (ti *noTermInfo) Parse(attr string, params ...interface{}) (string, error) return "", fmt.Errorf("noTermInfo") } -func clearLine(out io.Writer, ti termInfo) { +func clearLine(out io.Writer, ti termInfo) error { // el2 (clear whole line) is not exposed by terminfo. // First clear line from beginning to cursor if attr, err := ti.Parse("el1"); err == nil { - fmt.Fprintf(out, "%s", attr) + _, err = fmt.Fprintf(out, "%s", attr) + if err != nil { + return err + } } else { - fmt.Fprintf(out, "\x1b[1K") + _, err := fmt.Fprintf(out, "\x1b[1K") + if err != nil { + return err + } } // Then clear line from cursor to end if attr, err := ti.Parse("el"); err == nil { - fmt.Fprintf(out, "%s", attr) + _, err = fmt.Fprintf(out, "%s", attr) + if err != nil { + return err + } } else { - fmt.Fprintf(out, "\x1b[K") + _, err := fmt.Fprintf(out, "\x1b[K") + if err != nil { + return err + } } + + return nil } -func cursorUp(out io.Writer, ti termInfo, l int) { +func cursorUp(out io.Writer, ti termInfo, l int) error { if l == 0 { // Should never be the case, but be tolerant - return + return nil } if attr, err := ti.Parse("cuu", l); err == nil { - fmt.Fprintf(out, "%s", attr) + _, err = fmt.Fprintf(out, "%s", attr) + if err != nil { + return err + } } else { - fmt.Fprintf(out, "\x1b[%dA", l) + _, err := fmt.Fprintf(out, "\x1b[%dA", l) + if err != nil { + return err + } } + return nil } -func cursorDown(out io.Writer, ti termInfo, l int) { +func cursorDown(out io.Writer, ti termInfo, l int) error { if l == 0 { // Should never be the case, but be tolerant - return + return nil } if attr, err := ti.Parse("cud", l); err == nil { - fmt.Fprintf(out, "%s", attr) + _, err = fmt.Fprintf(out, "%s", attr) + if err != nil { + return err + } } else { - fmt.Fprintf(out, "\x1b[%dB", l) + _, err := fmt.Fprintf(out, "\x1b[%dB", l) + if err != nil { + return err + } } + + return nil } // Display displays the JSONMessage to `out`. `termInfo` is non-nil if `out` @@ -219,29 +248,56 @@ func (jm *JSONMessage) Display(out io.Writer, termInfo termInfo) error { if termInfo != nil && jm.Stream == "" && jm.Progress != nil { clearLine(out, termInfo) endl = "\r" - fmt.Fprintf(out, endl) - } else if jm.Progress != nil && jm.Progress.String() != "" { //disable progressbar in non-terminal + _, err := fmt.Fprint(out, endl) + if err != nil { + return err + } + } else if jm.Progress != nil && jm.Progress.String() != "" { // disable progressbar in non-terminal return nil } if jm.TimeNano != 0 { - fmt.Fprintf(out, "%s ", time.Unix(0, jm.TimeNano).Format(RFC3339NanoFixed)) + _, err := fmt.Fprintf(out, "%s ", time.Unix(0, jm.TimeNano).Format(RFC3339NanoFixed)) + if err != nil { + return err + } } else if jm.Time != 0 { - fmt.Fprintf(out, "%s ", time.Unix(jm.Time, 0).Format(RFC3339NanoFixed)) + _, err := fmt.Fprintf(out, "%s ", time.Unix(jm.Time, 0).Format(RFC3339NanoFixed)) + if err != nil { + return err + } } if jm.ID != "" { - fmt.Fprintf(out, "%s: ", jm.ID) + _, err := fmt.Fprintf(out, "%s: ", jm.ID) + if err != nil { + return err + } } if jm.From != "" { - fmt.Fprintf(out, "(from %s) ", jm.From) + _, err := fmt.Fprintf(out, "(from %s) ", jm.From) + if err != nil { + return err + } } if jm.Progress != nil && termInfo != nil { - fmt.Fprintf(out, "%s %s%s", jm.Status, jm.Progress.String(), endl) - } else if jm.ProgressMessage != "" { //deprecated - fmt.Fprintf(out, "%s %s%s", jm.Status, jm.ProgressMessage, endl) + _, err := fmt.Fprintf(out, "%s %s%s", jm.Status, jm.Progress.String(), endl) + if err != nil { + return err + } + } else if jm.ProgressMessage != "" { // deprecated + _, err := fmt.Fprintf(out, "%s %s%s", jm.Status, jm.ProgressMessage, endl) + if err != nil { + return err + } } else if jm.Stream != "" { - fmt.Fprintf(out, "%s%s", jm.Stream, endl) + _, err := fmt.Fprintf(out, "%s%s", jm.Stream, endl) + if err != nil { + return err + } } else { - fmt.Fprintf(out, "%s%s\n", jm.Status, endl) + _, err := fmt.Fprintf(out, "%s%s\n", jm.Status, endl) + if err != nil { + return err + } } return nil } @@ -301,12 +357,17 @@ func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr, line = len(ids) ids[jm.ID] = line if termInfo != nil { - fmt.Fprintf(out, "\n") + _, err := fmt.Fprintf(out, "\n") + if err != nil { + return err + } } } diff = len(ids) - line if termInfo != nil { - cursorUp(out, termInfo, diff) + if err := cursorUp(out, termInfo, diff); err != nil { + return err + } } } else { // When outputting something that isn't progress @@ -318,7 +379,9 @@ func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr, } err := jm.Display(out, termInfo) if jm.ID != "" && termInfo != nil { - cursorDown(out, termInfo, diff) + if err := cursorDown(out, termInfo, diff); err != nil { + return err + } } if err != nil { return err |