hide members where possible (#158492)
I was poking around in logger.dart when I noticed a few classes have unnecessary exposed member variables. This PR reduces visibility of these in the pursuit of making these classes slightly easier to grok. <details> <summary> Pre-launch checklist </summary> </details>
This commit is contained in:
parent
21144362f8
commit
a1a7409092
@ -1145,27 +1145,26 @@ typedef SlowWarningCallback = String Function();
|
|||||||
/// a [Status] or one of its subclasses.
|
/// a [Status] or one of its subclasses.
|
||||||
abstract class Status {
|
abstract class Status {
|
||||||
Status({
|
Status({
|
||||||
this.onFinish,
|
VoidCallback? onFinish,
|
||||||
required Stopwatch stopwatch,
|
required Stopwatch stopwatch,
|
||||||
this.timeout,
|
Duration? timeout,
|
||||||
}) : _stopwatch = stopwatch;
|
}) : _timeout = timeout,
|
||||||
|
_onFinish = onFinish,
|
||||||
|
_stopwatch = stopwatch;
|
||||||
|
|
||||||
final VoidCallback? onFinish;
|
final VoidCallback? _onFinish;
|
||||||
final Duration? timeout;
|
final Duration? _timeout;
|
||||||
|
|
||||||
@protected
|
|
||||||
final Stopwatch _stopwatch;
|
final Stopwatch _stopwatch;
|
||||||
|
|
||||||
@protected
|
String get _elapsedTime {
|
||||||
String get elapsedTime {
|
|
||||||
if (_stopwatch.elapsed.inSeconds > 2) {
|
if (_stopwatch.elapsed.inSeconds > 2) {
|
||||||
return getElapsedAsSeconds(_stopwatch.elapsed);
|
return getElapsedAsSeconds(_stopwatch.elapsed);
|
||||||
}
|
}
|
||||||
return getElapsedAsMilliseconds(_stopwatch.elapsed);
|
return getElapsedAsMilliseconds(_stopwatch.elapsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@visibleForTesting
|
bool get seemsSlow => _timeout != null && _stopwatch.elapsed > _timeout;
|
||||||
bool get seemsSlow => timeout != null && _stopwatch.elapsed > timeout!;
|
|
||||||
|
|
||||||
/// Call to start spinning.
|
/// Call to start spinning.
|
||||||
void start() {
|
void start() {
|
||||||
@ -1193,7 +1192,7 @@ abstract class Status {
|
|||||||
void finish() {
|
void finish() {
|
||||||
assert(_stopwatch.isRunning);
|
assert(_stopwatch.isRunning);
|
||||||
_stopwatch.stop();
|
_stopwatch.stop();
|
||||||
onFinish?.call();
|
_onFinish?.call();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1206,7 +1205,7 @@ class SilentStatus extends Status {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void finish() {
|
void finish() {
|
||||||
onFinish?.call();
|
_onFinish?.call();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1216,15 +1215,17 @@ const int _kTimePadding = 8; // should fit "99,999ms"
|
|||||||
/// [onFinish]. On [stop], will additionally print out summary information.
|
/// [onFinish]. On [stop], will additionally print out summary information.
|
||||||
class SummaryStatus extends Status {
|
class SummaryStatus extends Status {
|
||||||
SummaryStatus({
|
SummaryStatus({
|
||||||
this.message = '',
|
String message = '',
|
||||||
required super.stopwatch,
|
required super.stopwatch,
|
||||||
this.padding = kDefaultStatusPadding,
|
int padding = kDefaultStatusPadding,
|
||||||
super.onFinish,
|
super.onFinish,
|
||||||
required Stdio stdio,
|
required Stdio stdio,
|
||||||
}) : _stdio = stdio;
|
}) : _padding = padding,
|
||||||
|
_message = message,
|
||||||
|
_stdio = stdio;
|
||||||
|
|
||||||
final String message;
|
final String _message;
|
||||||
final int padding;
|
final int _padding;
|
||||||
final Stdio _stdio;
|
final Stdio _stdio;
|
||||||
|
|
||||||
bool _messageShowingOnCurrentLine = false;
|
bool _messageShowingOnCurrentLine = false;
|
||||||
@ -1239,7 +1240,7 @@ class SummaryStatus extends Status {
|
|||||||
|
|
||||||
void _printMessage() {
|
void _printMessage() {
|
||||||
assert(!_messageShowingOnCurrentLine);
|
assert(!_messageShowingOnCurrentLine);
|
||||||
_writeToStdOut('${message.padRight(padding)} ');
|
_writeToStdOut('${_message.padRight(_padding)} ');
|
||||||
_messageShowingOnCurrentLine = true;
|
_messageShowingOnCurrentLine = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1250,7 +1251,7 @@ class SummaryStatus extends Status {
|
|||||||
}
|
}
|
||||||
super.stop();
|
super.stop();
|
||||||
assert(_messageShowingOnCurrentLine);
|
assert(_messageShowingOnCurrentLine);
|
||||||
_writeToStdOut(elapsedTime.padLeft(_kTimePadding));
|
_writeToStdOut(_elapsedTime.padLeft(_kTimePadding));
|
||||||
_writeToStdOut('\n');
|
_writeToStdOut('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1281,18 +1282,20 @@ class AnonymousSpinnerStatus extends Status {
|
|||||||
required super.stopwatch,
|
required super.stopwatch,
|
||||||
required Stdio stdio,
|
required Stdio stdio,
|
||||||
required Terminal terminal,
|
required Terminal terminal,
|
||||||
this.slowWarningCallback,
|
SlowWarningCallback? slowWarningCallback,
|
||||||
this.warningColor,
|
TerminalColor? warningColor,
|
||||||
super.timeout,
|
super.timeout,
|
||||||
}) : _stdio = stdio,
|
}) : _warningColor = warningColor,
|
||||||
|
_slowWarningCallback = slowWarningCallback,
|
||||||
|
_stdio = stdio,
|
||||||
_terminal = terminal,
|
_terminal = terminal,
|
||||||
_animation = _selectAnimation(terminal);
|
_animation = _selectAnimation(terminal);
|
||||||
|
|
||||||
final Stdio _stdio;
|
final Stdio _stdio;
|
||||||
final Terminal _terminal;
|
final Terminal _terminal;
|
||||||
String _slowWarning = '';
|
String _slowWarning = '';
|
||||||
final SlowWarningCallback? slowWarningCallback;
|
final SlowWarningCallback? _slowWarningCallback;
|
||||||
final TerminalColor? warningColor;
|
final TerminalColor? _warningColor;
|
||||||
|
|
||||||
static const String _backspaceChar = '\b';
|
static const String _backspaceChar = '\b';
|
||||||
static const String _clearChar = ' ';
|
static const String _clearChar = ' ';
|
||||||
@ -1333,10 +1336,14 @@ class AnonymousSpinnerStatus extends Status {
|
|||||||
|
|
||||||
final List<String> _animation;
|
final List<String> _animation;
|
||||||
|
|
||||||
Timer? timer;
|
Timer? _timer;
|
||||||
int ticks = 0;
|
|
||||||
|
int _ticks = 0;
|
||||||
|
@visibleForTesting
|
||||||
|
int get ticks => _ticks;
|
||||||
|
|
||||||
int _lastAnimationFrameLength = 0;
|
int _lastAnimationFrameLength = 0;
|
||||||
bool timedOut = false;
|
bool _timedOut = false;
|
||||||
|
|
||||||
String get _currentAnimationFrame => _animation[ticks % _animation.length];
|
String get _currentAnimationFrame => _animation[ticks % _animation.length];
|
||||||
int get _currentLineLength => _lastAnimationFrameLength + _slowWarning.length;
|
int get _currentLineLength => _lastAnimationFrameLength + _slowWarning.length;
|
||||||
@ -1354,30 +1361,30 @@ class AnonymousSpinnerStatus extends Status {
|
|||||||
@override
|
@override
|
||||||
void start() {
|
void start() {
|
||||||
super.start();
|
super.start();
|
||||||
assert(timer == null);
|
assert(_timer == null);
|
||||||
_startSpinner();
|
_startSpinner();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _startSpinner() {
|
void _startSpinner() {
|
||||||
timer = Timer.periodic(const Duration(milliseconds: 100), _callback);
|
_timer = Timer.periodic(const Duration(milliseconds: 100), _callback);
|
||||||
_callback(timer!);
|
_callback(_timer!);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _callback(Timer timer) {
|
void _callback(Timer timer) {
|
||||||
assert(this.timer == timer);
|
assert(_timer == timer);
|
||||||
assert(timer.isActive);
|
assert(timer.isActive);
|
||||||
_writeToStdOut(_backspaceChar * _lastAnimationFrameLength);
|
_writeToStdOut(_backspaceChar * _lastAnimationFrameLength);
|
||||||
ticks += 1;
|
_ticks += 1;
|
||||||
if (seemsSlow) {
|
if (seemsSlow) {
|
||||||
if (!timedOut) {
|
if (!_timedOut) {
|
||||||
timedOut = true;
|
_timedOut = true;
|
||||||
if (_currentLineLength > _lastAnimationFrameLength) {
|
if (_currentLineLength > _lastAnimationFrameLength) {
|
||||||
_clear(_currentLineLength - _lastAnimationFrameLength);
|
_clear(_currentLineLength - _lastAnimationFrameLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final SlowWarningCallback? callback = slowWarningCallback;
|
final SlowWarningCallback? callback = _slowWarningCallback;
|
||||||
if (_slowWarning.isEmpty && callback != null) {
|
if (_slowWarning.isEmpty && callback != null) {
|
||||||
final TerminalColor? color = warningColor;
|
final TerminalColor? color = _warningColor;
|
||||||
if (color != null) {
|
if (color != null) {
|
||||||
_slowWarning = _terminal.color(callback(), color);
|
_slowWarning = _terminal.color(callback(), color);
|
||||||
} else {
|
} else {
|
||||||
@ -1394,30 +1401,30 @@ class AnonymousSpinnerStatus extends Status {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void pause() {
|
void pause() {
|
||||||
assert(timer != null);
|
assert(_timer != null);
|
||||||
assert(timer!.isActive);
|
assert(_timer!.isActive);
|
||||||
if (_terminal.supportsColor) {
|
if (_terminal.supportsColor) {
|
||||||
_writeToStdOut('\r\x1B[K'); // go to start of line and clear line
|
_writeToStdOut('\r\x1B[K'); // go to start of line and clear line
|
||||||
} else {
|
} else {
|
||||||
_clear(_currentLineLength);
|
_clear(_currentLineLength);
|
||||||
}
|
}
|
||||||
_lastAnimationFrameLength = 0;
|
_lastAnimationFrameLength = 0;
|
||||||
timer?.cancel();
|
_timer?.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void resume() {
|
void resume() {
|
||||||
assert(timer != null);
|
assert(_timer != null);
|
||||||
assert(!timer!.isActive);
|
assert(!_timer!.isActive);
|
||||||
_startSpinner();
|
_startSpinner();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void finish() {
|
void finish() {
|
||||||
assert(timer != null);
|
assert(_timer != null);
|
||||||
assert(timer!.isActive);
|
assert(_timer!.isActive);
|
||||||
timer?.cancel();
|
_timer?.cancel();
|
||||||
timer = null;
|
_timer = null;
|
||||||
_clear(_lastAnimationFrameLength + _slowWarning.length);
|
_clear(_lastAnimationFrameLength + _slowWarning.length);
|
||||||
_slowWarning = '';
|
_slowWarning = '';
|
||||||
_lastAnimationFrameLength = 0;
|
_lastAnimationFrameLength = 0;
|
||||||
@ -1436,16 +1443,17 @@ class AnonymousSpinnerStatus extends Status {
|
|||||||
/// Call [pause] before outputting any text while this is running.
|
/// Call [pause] before outputting any text while this is running.
|
||||||
class SpinnerStatus extends AnonymousSpinnerStatus {
|
class SpinnerStatus extends AnonymousSpinnerStatus {
|
||||||
SpinnerStatus({
|
SpinnerStatus({
|
||||||
required this.message,
|
required String message,
|
||||||
this.padding = kDefaultStatusPadding,
|
int padding = kDefaultStatusPadding,
|
||||||
super.onFinish,
|
super.onFinish,
|
||||||
required super.stopwatch,
|
required super.stopwatch,
|
||||||
required super.stdio,
|
required super.stdio,
|
||||||
required super.terminal,
|
required super.terminal,
|
||||||
});
|
}) : _padding = padding,
|
||||||
|
_message = message;
|
||||||
|
|
||||||
final String message;
|
final String _message;
|
||||||
final int padding;
|
final int _padding;
|
||||||
|
|
||||||
static final String _margin = AnonymousSpinnerStatus._clearChar * (5 + _kTimePadding - 1);
|
static final String _margin = AnonymousSpinnerStatus._clearChar * (5 + _kTimePadding - 1);
|
||||||
|
|
||||||
@ -1461,7 +1469,7 @@ class SpinnerStatus extends AnonymousSpinnerStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _printStatus() {
|
void _printStatus() {
|
||||||
final String line = '${message.padRight(padding)}$_margin';
|
final String line = '${_message.padRight(_padding)}$_margin';
|
||||||
_totalMessageLength = line.length;
|
_totalMessageLength = line.length;
|
||||||
_writeToStdOut(line);
|
_writeToStdOut(line);
|
||||||
}
|
}
|
||||||
@ -1483,7 +1491,7 @@ class SpinnerStatus extends AnonymousSpinnerStatus {
|
|||||||
super.stop(); // calls finish, which clears the spinner
|
super.stop(); // calls finish, which clears the spinner
|
||||||
assert(_totalMessageLength > _kTimePadding);
|
assert(_totalMessageLength > _kTimePadding);
|
||||||
_writeToStdOut(AnonymousSpinnerStatus._backspaceChar * (_kTimePadding - 1));
|
_writeToStdOut(AnonymousSpinnerStatus._backspaceChar * (_kTimePadding - 1));
|
||||||
_writeToStdOut(elapsedTime.padLeft(_kTimePadding));
|
_writeToStdOut(_elapsedTime.padLeft(_kTimePadding));
|
||||||
_writeToStdOut('\n');
|
_writeToStdOut('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user