Skip to content

Commit bff3d35

Browse files
ndeloofglours
authored andcommitted
render events in order they were first received
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent b80bb05 commit bff3d35

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

pkg/progress/tty.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func NewTTYWriter(out io.Writer) EventProcessor {
4444

4545
type ttyWriter struct {
4646
out io.Writer
47+
ids []string // tasks ids ordered as first event appeared
4748
tasks map[string]task
4849
repeated bool
4950
numLines int
@@ -53,6 +54,7 @@ type ttyWriter struct {
5354
skipChildEvents bool
5455
operation string
5556
ticker *time.Ticker
57+
suspended bool
5658
}
5759

5860
type task struct {
@@ -121,9 +123,12 @@ func (w *ttyWriter) On(events ...Event) {
121123
func (w *ttyWriter) event(e Event) {
122124
// Suspend print while a build is in progress, to avoid collision with buildkit Display
123125
if e.StatusText == StatusBuilding {
126+
fmt.Println("suspend during build")
124127
w.ticker.Stop()
125-
} else {
128+
w.suspended = true
129+
} else if w.suspended {
126130
w.ticker.Reset(100 * time.Millisecond)
131+
w.suspended = false
127132
}
128133

129134
if last, ok := w.tasks[e.ID]; ok {
@@ -170,6 +175,7 @@ func (w *ttyWriter) event(e Event) {
170175
t.stop()
171176
}
172177
w.tasks[e.ID] = t
178+
w.ids = append(w.ids, e.ID)
173179
}
174180
w.printEvent(e)
175181
}
@@ -235,7 +241,9 @@ func (w *ttyWriter) print() {
235241
w.skipChildEvents = true
236242
}
237243
numLines := 0
238-
for _, t := range w.tasks {
244+
245+
for _, id := range w.ids { // iterate on ids to enforce a consistent order
246+
t := w.tasks[id]
239247
if t.parentID != "" {
240248
continue
241249
}
@@ -286,7 +294,8 @@ func (w *ttyWriter) lineText(t task, pad string, terminalWidth, statusPadding in
286294

287295
// only show the aggregated progress while the root operation is in-progress
288296
if parent := t; parent.status == Working {
289-
for _, child := range w.tasks {
297+
for _, id := range w.ids {
298+
child := w.tasks[id]
290299
if child.parentID == parent.ID {
291300
if child.status == Working && child.total == 0 {
292301
// we don't have totals available for all the child events

0 commit comments

Comments
 (0)