Browse code

Don't update lines on the terminal from a previous operation

When we handle a message that isn't tracked in the "line" map (for
example, one with no ID), clear the line map. This means we won't update
lines that were part of a previous, completed set of operations when
doing something like pull -a. It also has the beneficial side effect
of avoiding terminal glitching in these types of situations, since
messages that don't get tracked in the "line" map cause the count of the
number of lines to get out of sync.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>

Aaron Lehmann authored on 2015/12/08 09:04:42
Showing 1 changed files
... ...
@@ -169,6 +169,12 @@ func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr,
169 169
 		if jm.ID != "" && (jm.Progress != nil || jm.ProgressMessage != "") {
170 170
 			line, ok := ids[jm.ID]
171 171
 			if !ok {
172
+				// NOTE: This approach of using len(id) to
173
+				// figure out the number of lines of history
174
+				// only works as long as we clear the history
175
+				// when we output something that's not
176
+				// accounted for in the map, such as a line
177
+				// with no ID.
172 178
 				line = len(ids)
173 179
 				ids[jm.ID] = line
174 180
 				if isTerminal {
... ...
@@ -182,6 +188,13 @@ func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr,
182 182
 				// <ESC>[{diff}A = move cursor up diff rows
183 183
 				fmt.Fprintf(out, "%c[%dA", 27, diff)
184 184
 			}
185
+		} else {
186
+			// When outputting something that isn't progress
187
+			// output, clear the history of previous lines. We
188
+			// don't want progress entries from some previous
189
+			// operation to be updated (for example, pull -a
190
+			// with multiple tags).
191
+			ids = make(map[string]int)
185 192
 		}
186 193
 		err := jm.Display(out, isTerminal)
187 194
 		if jm.ID != "" && isTerminal {