From 8ce9cf6200cb95fa2c2bbb41a810f5df914192c4 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Thu, 9 May 2024 11:09:05 -0700 Subject: [PATCH] When `et` is not attached to a terminal, still split lines for status updates. (flutter/engine#52681) For illustrative purposes: ```sh $ et build | grep '.*' ``` ... should still get line-per-line status updates, but it does not without this patch. It's hard to write tests because of global state, so I've declined to do so at the moment. Closes https://github.com/flutter/flutter/issues/147903. --- .../flutter/tools/engine_tool/lib/src/logger.dart | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/tools/engine_tool/lib/src/logger.dart b/engine/src/flutter/tools/engine_tool/lib/src/logger.dart index 28bd847885a..e77fafc5187 100644 --- a/engine/src/flutter/tools/engine_tool/lib/src/logger.dart +++ b/engine/src/flutter/tools/engine_tool/lib/src/logger.dart @@ -165,10 +165,20 @@ class Logger { _emitLog(infoLevel, message, indent, newline, fit); } - /// Writes a number of spaces to stdout equal to the width of the terminal - /// and emits a carriage return. + /// Functionally ends and starts a new line. + /// + /// How that is done depends on the terminal capabilities: + /// + /// - If we are not in a terminal, just write a newline. + /// - If we are in a a terminal, any spinners are temporarily paused, the + /// current line is cleared, and spinners are resumed. If ANSI escapes are + /// supported, the cursor is moved to the start of the line and the line is + /// cleared. Otherwise, the line is cleared by writing spaces to the width + /// of the terminal, then moving the cursor back to the start of the line. void clearLine() { if (!io.stdout.hasTerminal || _test) { + // Just write a newline if we're not in a terminal. + _ioSinkWrite(io.stdout, '\n'); return; } _status?.pause();