@@ -287,16 +287,16 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
287287 }
288288 }
289289
290- // Buffer to store formatted stats text .
291- // Once formatted, it will be printed in one write to avoid screen flickering .
292- var statsTextBuffer bytes.Buffer
290+ // renderBuf holds the formatted stats output produced by statsFormatWrite .
291+ // It does not include any terminal control sequences .
292+ var renderBuf bytes.Buffer
293293
294294 // frameBuf holds the final terminal frame, including cursor movement and
295295 // line-clearing escape sequences, written in a single pass to avoid flicker.
296296 var frameBuf bytes.Buffer
297297
298298 statsCtx := formatter.Context {
299- Output : & statsTextBuffer ,
299+ Output : & renderBuf ,
300300 Format : NewStatsFormat (format , daemonOSType ),
301301 }
302302
@@ -312,7 +312,7 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
312312 if err := statsFormatWrite (statsCtx , ccStats , daemonOSType , ! options .NoTrunc ); err != nil {
313313 return err
314314 }
315- _ , _ = fmt .Fprint (dockerCLI .Out (), statsTextBuffer .String ())
315+ _ , _ = fmt .Fprint (dockerCLI .Out (), renderBuf .String ())
316316 return nil
317317 }
318318
@@ -321,7 +321,7 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
321321 for {
322322 select {
323323 case <- ticker .C :
324- statsTextBuffer .Reset ()
324+ renderBuf .Reset ()
325325 frameBuf .Reset ()
326326 statsList := cStats .snapshot ()
327327 if len (statsList ) == 0 && ! showAll {
@@ -341,7 +341,7 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
341341 // Start by moving the cursor to the top-left
342342 _ , _ = fmt .Fprint (& frameBuf , "\033 [H" )
343343
344- for line := range strings .SplitSeq (statsTextBuffer .String (), "\n " ) {
344+ for line := range strings .SplitSeq (renderBuf .String (), "\n " ) {
345345 // In case the new text is shorter than the one we are writing over,
346346 // we'll append the "erase line" escape sequence to clear the remaining text.
347347 _ , _ = fmt .Fprintln (& frameBuf , line , "\033 [K" )
0 commit comments