@@ -2,6 +2,7 @@ import 'dart:async';
22import 'dart:convert' ;
33import 'dart:io' ;
44
5+ import 'package:cli_util/cli_logging.dart' show Ansi;
56import 'package:dartdoc/src/dartdoc_options.dart' ;
67// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
78// for details. All rights reserved. Use of this source code is governed by a
@@ -29,6 +30,10 @@ void logInfo(Object message) {
2930 _logger.log (Level .INFO , message);
3031}
3132
33+ void logDebug (Object message) {
34+ _logger.log (Level .FINE , message);
35+ }
36+
3237void logProgress (Object message) {
3338 _logger.log (progressLevel, message);
3439}
@@ -74,41 +79,47 @@ void startLogging(LoggingContext config) {
7479 // Used to track if we're printing `...` to show progress.
7580 // Allows unified new-line tracking
7681 var writingProgress = false ;
82+ Ansi ansi = Ansi (Ansi .terminalSupportsAnsi);
83+ int spinnerIndex = 0 ;
84+ final List <String > spinner = ['-' , r'\' , '|' , '/' ];
7785
7886 Logger .root.onRecord.listen ((record) {
7987 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+ }
8194 writingProgress = true ;
82- stdout.write ('.' );
95+ stdout.write ('${ansi .backspace }${spinner [spinnerIndex ]}' );
96+ spinnerIndex = (spinnerIndex + 1 ) % spinner.length;
8397 stopwatch.reset ();
8498 }
8599 return ;
86100 }
87101
88102 stopwatch.reset ();
89103 if (writingProgress) {
90- // print a new line after progress dots...
91- print ('' );
92- writingProgress = false ;
104+ stdout.write ('${ansi .backspace } ${ansi .backspace }' );
93105 }
94106 var message = record.message;
95107 assert (message == message.trimRight ());
96108 assert (message.isNotEmpty);
97109
98110 if (record.level < Level .WARNING ) {
99111 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);
108113 }
109114 } 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 ' );
111121 }
122+ writingProgress = false ;
112123 });
113124 }
114125}
@@ -124,9 +135,9 @@ Future<List<DartdocOption>> createLoggingOptions() async {
124135 DartdocOptionArgOnly <bool >('json' , false ,
125136 help: 'Prints out progress JSON maps. One entry per line.' ,
126137 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 ),
130141 DartdocOptionArgSynth <bool >('quiet' ,
131142 (DartdocSyntheticOption option, Directory dir) {
132143 if (option.root['generateDocs' ]? .valueAt (dir) == false ) {
0 commit comments