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.
This commit is contained in:
Matan Lurey 2024-05-09 11:09:05 -07:00 committed by GitHub
parent d1b24afe05
commit 8ce9cf6200

View File

@ -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();