File tree Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class AnsiBuffer {
21
21
final List <String > lines = [];
22
22
23
23
/// The width that the buffer wraps to.
24
- int get width =>
24
+ static int get width =>
25
25
buildLog.configuration.forceConsoleWidthForTesting ??
26
26
(stdout.hasTerminal ? stdout.terminalColumns : 80 );
27
27
@@ -40,7 +40,7 @@ class AnsiBuffer {
40
40
/// In addition to ANSI codes, [nbsp] is a non-breaking space which will not
41
41
/// be used for wrapping. In the buffer it is replaced with a normal space.
42
42
void writeLine (List <String > items, {int indent = 0 , int ? hangingIndent}) {
43
- final width = this .width;
43
+ final width = AnsiBuffer .width;
44
44
hangingIndent ?? = indent;
45
45
indent = min (indent, width ~ / 2 );
46
46
hangingIndent = min (hangingIndent, width ~ / 2 );
Original file line number Diff line number Diff line change @@ -60,8 +60,13 @@ class LogDisplay {
60
60
// https://en.wikipedia.org/wiki/ANSI_escape_code#:~:text=Cursor%20Previous
61
61
// Moves cursor to the beginning of the line n lines up.
62
62
final moveCursor = _displayedLines == 0 ? '' : '\x 1b[${_displayedLines }F' ;
63
- _displayedLines = lines.length;
64
63
stdout.writeln ('$moveCursor ${lines .join ('\n ' )}' );
64
+ if (_displayedLines > lines.length) {
65
+ // If the block is smaller than last time, erase the rest of the display.
66
+ // https://en.wikipedia.org/wiki/ANSI_escape_code#:~:text=Erase%20in%20Display
67
+ stdout.write ('\x 1b[J' );
68
+ }
69
+ _displayedLines = lines.length;
65
70
66
71
if (block.overflowsConsole) {
67
72
prompt ('Log overflowed the console, switching to line-by-line logging.' );
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2
+ // for details. All rights reserved. Use of this source code is governed by a
3
+ // BSD-style license that can be found in the LICENSE file.
4
+
5
+ import 'package:build_runner_core/src/logging/ansi_buffer.dart' ;
6
+ import 'package:build_runner_core/src/logging/log_display.dart' ;
7
+
8
+ // TODO(davidmorgan): figure out how to make this a test.
9
+ void main () async {
10
+ final display = LogDisplay ();
11
+ display.block (
12
+ AnsiBuffer ()
13
+ ..writeLine (['start with' ])
14
+ ..writeLine (['two lines' ]),
15
+ );
16
+ await Future <void >.delayed (const Duration (seconds: 2 ));
17
+ display.block (AnsiBuffer ()..writeLine (['now there should be one line' ]));
18
+ await Future <void >.delayed (const Duration (seconds: 2 ));
19
+ display.block (
20
+ AnsiBuffer ()
21
+ ..writeLine (['now' ])
22
+ ..writeLine (['three' ])
23
+ ..writeLine (['lines' ]),
24
+ );
25
+ await Future <void >.delayed (const Duration (seconds: 2 ));
26
+ display.block (AnsiBuffer ()..writeLine (['finally one line again' ]));
27
+ }
You can’t perform that action at this time.
0 commit comments