mirror of https://github.com/docker/docs.git
Merge pull request #18484 from aaronlehmann/progress-fixes
JSONMessage terminal display fixes
This commit is contained in:
commit
6d2130ee8e
|
@ -152,9 +152,9 @@ func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr,
|
||||||
var (
|
var (
|
||||||
dec = json.NewDecoder(in)
|
dec = json.NewDecoder(in)
|
||||||
ids = make(map[string]int)
|
ids = make(map[string]int)
|
||||||
diff = 0
|
|
||||||
)
|
)
|
||||||
for {
|
for {
|
||||||
|
diff := 0
|
||||||
var jm JSONMessage
|
var jm JSONMessage
|
||||||
if err := dec.Decode(&jm); err != nil {
|
if err := dec.Decode(&jm); err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
|
@ -169,22 +169,38 @@ func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr,
|
||||||
if jm.ID != "" && (jm.Progress != nil || jm.ProgressMessage != "") {
|
if jm.ID != "" && (jm.Progress != nil || jm.ProgressMessage != "") {
|
||||||
line, ok := ids[jm.ID]
|
line, ok := ids[jm.ID]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
// NOTE: This approach of using len(id) to
|
||||||
|
// figure out the number of lines of history
|
||||||
|
// only works as long as we clear the history
|
||||||
|
// when we output something that's not
|
||||||
|
// accounted for in the map, such as a line
|
||||||
|
// with no ID.
|
||||||
line = len(ids)
|
line = len(ids)
|
||||||
ids[jm.ID] = line
|
ids[jm.ID] = line
|
||||||
if isTerminal {
|
if isTerminal {
|
||||||
fmt.Fprintf(out, "\n")
|
fmt.Fprintf(out, "\n")
|
||||||
}
|
}
|
||||||
diff = 0
|
|
||||||
} else {
|
} else {
|
||||||
diff = len(ids) - line
|
diff = len(ids) - line
|
||||||
}
|
}
|
||||||
if jm.ID != "" && isTerminal {
|
if jm.ID != "" && isTerminal {
|
||||||
|
// NOTE: this appears to be necessary even if
|
||||||
|
// diff == 0.
|
||||||
// <ESC>[{diff}A = move cursor up diff rows
|
// <ESC>[{diff}A = move cursor up diff rows
|
||||||
fmt.Fprintf(out, "%c[%dA", 27, diff)
|
fmt.Fprintf(out, "%c[%dA", 27, diff)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// When outputting something that isn't progress
|
||||||
|
// output, clear the history of previous lines. We
|
||||||
|
// don't want progress entries from some previous
|
||||||
|
// operation to be updated (for example, pull -a
|
||||||
|
// with multiple tags).
|
||||||
|
ids = make(map[string]int)
|
||||||
}
|
}
|
||||||
err := jm.Display(out, isTerminal)
|
err := jm.Display(out, isTerminal)
|
||||||
if jm.ID != "" && isTerminal {
|
if jm.ID != "" && isTerminal {
|
||||||
|
// NOTE: this appears to be necessary even if
|
||||||
|
// diff == 0.
|
||||||
// <ESC>[{diff}B = move cursor down diff rows
|
// <ESC>[{diff}B = move cursor down diff rows
|
||||||
fmt.Fprintf(out, "%c[%dB", 27, diff)
|
fmt.Fprintf(out, "%c[%dB", 27, diff)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue