@@ -2,6 +2,7 @@ import 'dart:async';
2
2
import 'dart:convert' ;
3
3
import 'dart:io' ;
4
4
5
+ import 'package:cli_util/cli_logging.dart' show Ansi;
5
6
import 'package:dartdoc/src/dartdoc_options.dart' ;
6
7
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
7
8
// for details. All rights reserved. Use of this source code is governed by a
@@ -29,6 +30,10 @@ void logInfo(Object message) {
29
30
_logger.log (Level .INFO , message);
30
31
}
31
32
33
+ void logDebug (Object message) {
34
+ _logger.log (Level .FINE , message);
35
+ }
36
+
32
37
void logProgress (Object message) {
33
38
_logger.log (progressLevel, message);
34
39
}
@@ -74,41 +79,47 @@ void startLogging(LoggingContext config) {
74
79
// Used to track if we're printing `...` to show progress.
75
80
// Allows unified new-line tracking
76
81
var writingProgress = false ;
82
+ Ansi ansi = Ansi (Ansi .terminalSupportsAnsi);
83
+ int spinnerIndex = 0 ;
84
+ final List <String > spinner = ['-' , r'\' , '|' , '/' ];
77
85
78
86
Logger .root.onRecord.listen ((record) {
79
87
if (record.level == progressLevel) {
80
- if (config.showProgress && stopwatch.elapsed.inMilliseconds > 250 ) {
88
+ if (! config.quiet &&
89
+ config.showProgress &&
90
+ stopwatch.elapsed.inMilliseconds > 125 ) {
91
+ if (writingProgress = false ) {
92
+ stdout.write (' ' );
93
+ }
81
94
writingProgress = true ;
82
- stdout.write ('.' );
95
+ stdout.write ('${ansi .backspace }${spinner [spinnerIndex ]}' );
96
+ spinnerIndex = (spinnerIndex + 1 ) % spinner.length;
83
97
stopwatch.reset ();
84
98
}
85
99
return ;
86
100
}
87
101
88
102
stopwatch.reset ();
89
103
if (writingProgress) {
90
- // print a new line after progress dots...
91
- print ('' );
92
- writingProgress = false ;
104
+ stdout.write ('${ansi .backspace } ${ansi .backspace }' );
93
105
}
94
106
var message = record.message;
95
107
assert (message == message.trimRight ());
96
108
assert (message.isNotEmpty);
97
109
98
110
if (record.level < Level .WARNING ) {
99
111
if (! config.quiet) {
100
- if (config.showProgress && message.endsWith ('...' )) {
101
- // Assume there may be more progress to print, so omit the trailing
102
- // newline
103
- writingProgress = true ;
104
- stdout.write (message);
105
- } else {
106
- print (message);
107
- }
112
+ print (message);
108
113
}
109
114
} else {
110
- stderr.writeln (message);
115
+ if (writingProgress) {
116
+ // Some console implementations, like IntelliJ, apparently need
117
+ // the backspace to occur for stderr as well.
118
+ stderr.write ('${ansi .backspace } ${ansi .backspace }' );
119
+ }
120
+ stderr.write ('${message }\n ' );
111
121
}
122
+ writingProgress = false ;
112
123
});
113
124
}
114
125
}
@@ -124,9 +135,9 @@ Future<List<DartdocOption>> createLoggingOptions() async {
124
135
DartdocOptionArgOnly <bool >('json' , false ,
125
136
help: 'Prints out progress JSON maps. One entry per line.' ,
126
137
negatable: true ),
127
- DartdocOptionArgOnly <bool >('showProgress' , false ,
128
- help: 'Display progress indications to console stdout' ,
129
- negatable: false ),
138
+ DartdocOptionArgOnly <bool >('showProgress' , Ansi .terminalSupportsAnsi ,
139
+ help: 'Display progress indications to console stdout. ' ,
140
+ negatable: true ),
130
141
DartdocOptionArgSynth <bool >('quiet' ,
131
142
(DartdocSyntheticOption option, Directory dir) {
132
143
if (option.root['generateDocs' ]? .valueAt (dir) == false ) {
0 commit comments