forked from firka/flutter
[flutter_tools] Print emojis in Windows Terminal (#50446)
This commit is contained in:
@@ -36,58 +36,122 @@ class CommandHelp {
|
||||
final OutputPreferences _outputPreferences;
|
||||
|
||||
CommandHelpOption _L;
|
||||
CommandHelpOption get L => _L ??= _makeOption('L', 'Dump layer tree to the console.', 'debugDumpLayerTree');
|
||||
CommandHelpOption get L => _L ??= _makeOption(
|
||||
'L',
|
||||
'Dump layer tree to the console.',
|
||||
'debugDumpLayerTree',
|
||||
);
|
||||
|
||||
CommandHelpOption _P;
|
||||
CommandHelpOption get P => _P ??= _makeOption('P', 'Toggle performance overlay.', 'WidgetsApp.showPerformanceOverlay');
|
||||
CommandHelpOption get P => _P ??= _makeOption(
|
||||
'P',
|
||||
'Toggle performance overlay.',
|
||||
'WidgetsApp.showPerformanceOverlay',
|
||||
);
|
||||
|
||||
CommandHelpOption _R;
|
||||
CommandHelpOption get R => _R ??= _makeOption('R', 'Hot restart.');
|
||||
CommandHelpOption get R => _R ??= _makeOption(
|
||||
'R',
|
||||
'Hot restart.',
|
||||
);
|
||||
|
||||
CommandHelpOption _S;
|
||||
CommandHelpOption get S => _S ??= _makeOption('S', 'Dump accessibility tree in traversal order.', 'debugDumpSemantics');
|
||||
CommandHelpOption get S => _S ??= _makeOption(
|
||||
'S',
|
||||
'Dump accessibility tree in traversal order.',
|
||||
'debugDumpSemantics',
|
||||
);
|
||||
|
||||
CommandHelpOption _U;
|
||||
CommandHelpOption get U => _U ??= _makeOption('U', 'Dump accessibility tree in inverse hit test order.', 'debugDumpSemantics');
|
||||
CommandHelpOption get U => _U ??= _makeOption(
|
||||
'U',
|
||||
'Dump accessibility tree in inverse hit test order.',
|
||||
'debugDumpSemantics',
|
||||
);
|
||||
|
||||
CommandHelpOption _a;
|
||||
CommandHelpOption get a => _a ??= _makeOption('a', 'Toggle timeline events for all widget build methods.', 'debugProfileWidgetBuilds');
|
||||
CommandHelpOption get a => _a ??= _makeOption(
|
||||
'a',
|
||||
'Toggle timeline events for all widget build methods.',
|
||||
'debugProfileWidgetBuilds',
|
||||
);
|
||||
|
||||
CommandHelpOption _c;
|
||||
CommandHelpOption get c => _c ??= _makeOption('c', 'Clear the screen');
|
||||
CommandHelpOption get c => _c ??= _makeOption(
|
||||
'c',
|
||||
'Clear the screen',
|
||||
);
|
||||
|
||||
CommandHelpOption _d;
|
||||
CommandHelpOption get d => _d ??= _makeOption('d', 'Detach (terminate "flutter run" but leave application running).');
|
||||
CommandHelpOption get d => _d ??= _makeOption(
|
||||
'd',
|
||||
'Detach (terminate "flutter run" but leave application running).',
|
||||
);
|
||||
|
||||
CommandHelpOption _h;
|
||||
CommandHelpOption get h => _h ??= _makeOption('h', 'Repeat this help message.');
|
||||
CommandHelpOption get h => _h ??= _makeOption(
|
||||
'h',
|
||||
'Repeat this help message.',
|
||||
);
|
||||
|
||||
CommandHelpOption _i;
|
||||
CommandHelpOption get i => _i ??= _makeOption('i', 'Toggle widget inspector.', 'WidgetsApp.showWidgetInspectorOverride');
|
||||
CommandHelpOption get i => _i ??= _makeOption(
|
||||
'i',
|
||||
'Toggle widget inspector.',
|
||||
'WidgetsApp.showWidgetInspectorOverride',
|
||||
);
|
||||
|
||||
CommandHelpOption _o;
|
||||
CommandHelpOption get o => _o ??= _makeOption('o', 'Simulate different operating systems.', 'defaultTargetPlatform');
|
||||
CommandHelpOption get o => _o ??= _makeOption(
|
||||
'o',
|
||||
'Simulate different operating systems.',
|
||||
'defaultTargetPlatform',
|
||||
);
|
||||
|
||||
CommandHelpOption _p;
|
||||
CommandHelpOption get p => _p ??= _makeOption('p', 'Toggle the display of construction lines.', 'debugPaintSizeEnabled');
|
||||
CommandHelpOption get p => _p ??= _makeOption(
|
||||
'p',
|
||||
'Toggle the display of construction lines.',
|
||||
'debugPaintSizeEnabled',
|
||||
);
|
||||
|
||||
CommandHelpOption _q;
|
||||
CommandHelpOption get q => _q ??= _makeOption('q', 'Quit (terminate the application on the device).');
|
||||
CommandHelpOption get q => _q ??= _makeOption(
|
||||
'q',
|
||||
'Quit (terminate the application on the device).',
|
||||
);
|
||||
|
||||
CommandHelpOption _r;
|
||||
CommandHelpOption get r => _r ??= _makeOption('r', 'Hot reload. $fire$fire$fire');
|
||||
CommandHelpOption get r => _r ??= _makeOption(
|
||||
'r',
|
||||
'Hot reload. $fire$fire$fire',
|
||||
);
|
||||
|
||||
CommandHelpOption _s;
|
||||
CommandHelpOption get s => _s ??= _makeOption('s', 'Save a screenshot to flutter.png.');
|
||||
CommandHelpOption get s => _s ??= _makeOption(
|
||||
's',
|
||||
'Save a screenshot to flutter.png.',
|
||||
);
|
||||
|
||||
CommandHelpOption _t;
|
||||
CommandHelpOption get t => _t ??= _makeOption('t', 'Dump rendering tree to the console.', 'debugDumpRenderTree');
|
||||
CommandHelpOption get t => _t ??= _makeOption(
|
||||
't',
|
||||
'Dump rendering tree to the console.',
|
||||
'debugDumpRenderTree',
|
||||
);
|
||||
|
||||
CommandHelpOption _w;
|
||||
CommandHelpOption get w => _w ??= _makeOption('w', 'Dump widget hierarchy to the console.', 'debugDumpApp');
|
||||
CommandHelpOption get w => _w ??= _makeOption(
|
||||
'w',
|
||||
'Dump widget hierarchy to the console.',
|
||||
'debugDumpApp',
|
||||
);
|
||||
|
||||
CommandHelpOption _z;
|
||||
CommandHelpOption get z => _z ??= _makeOption('z', 'Toggle elevation checker.');
|
||||
CommandHelpOption get z => _z ??= _makeOption(
|
||||
'z',
|
||||
'Toggle elevation checker.',
|
||||
);
|
||||
|
||||
CommandHelpOption _makeOption(String key, String description, [
|
||||
String inParenthesis = '',
|
||||
@@ -142,25 +206,30 @@ class CommandHelpOption {
|
||||
String toString() {
|
||||
final StringBuffer message = StringBuffer();
|
||||
message.writeAll(<String>[_terminal.bolden(key), description], ' ');
|
||||
|
||||
if (_hasTextInParenthesis) {
|
||||
bool wrap = false;
|
||||
final int maxWidth = math.max(_outputPreferences.wrapColumn ?? 0, maxLineWidth);
|
||||
int width = maxWidth - (_platform.stdoutSupportsAnsi ? _rawMessageLength + 1 : message.length);
|
||||
final String parentheticalText = '($inParenthesis)';
|
||||
if (width < parentheticalText.length) {
|
||||
width = maxWidth;
|
||||
wrap = true;
|
||||
}
|
||||
|
||||
if (wrap) {
|
||||
message.write('\n');
|
||||
}
|
||||
// pad according to the raw text
|
||||
message.write(''.padLeft(width - parentheticalText.length));
|
||||
|
||||
message.write(_terminal.color(parentheticalText, TerminalColor.grey));
|
||||
if (!_hasTextInParenthesis) {
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
bool wrap = false;
|
||||
final int maxWidth = math.max(
|
||||
_outputPreferences.wrapColumn ?? 0,
|
||||
maxLineWidth,
|
||||
);
|
||||
final int adjustedMessageLength = _platform.stdoutSupportsAnsi
|
||||
? _rawMessageLength + 1
|
||||
: message.length;
|
||||
int width = maxWidth - adjustedMessageLength;
|
||||
final String parentheticalText = '($inParenthesis)';
|
||||
if (width < parentheticalText.length) {
|
||||
width = maxWidth;
|
||||
wrap = true;
|
||||
}
|
||||
if (wrap) {
|
||||
message.write('\n');
|
||||
}
|
||||
// pad according to the raw text
|
||||
message.write(''.padLeft(width - parentheticalText.length));
|
||||
message.write(_terminal.color(parentheticalText, TerminalColor.grey));
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:platform/platform.dart';
|
||||
|
||||
import '../base/context.dart';
|
||||
import '../globals.dart' as globals;
|
||||
@@ -179,15 +178,13 @@ class StdoutLogger extends Logger {
|
||||
@required Stdio stdio,
|
||||
@required OutputPreferences outputPreferences,
|
||||
@required TimeoutConfiguration timeoutConfiguration,
|
||||
@required Platform platform,
|
||||
StopwatchFactory stopwatchFactory = const StopwatchFactory(),
|
||||
})
|
||||
: _stdio = stdio,
|
||||
_terminal = terminal,
|
||||
_timeoutConfiguration = timeoutConfiguration,
|
||||
_outputPreferences = outputPreferences,
|
||||
_stopwatchFactory = stopwatchFactory,
|
||||
_platform = platform;
|
||||
_stopwatchFactory = stopwatchFactory;
|
||||
|
||||
@override
|
||||
final AnsiTerminal _terminal;
|
||||
@@ -197,7 +194,6 @@ class StdoutLogger extends Logger {
|
||||
final TimeoutConfiguration _timeoutConfiguration;
|
||||
final Stdio _stdio;
|
||||
final StopwatchFactory _stopwatchFactory;
|
||||
final Platform _platform;
|
||||
|
||||
Status _status;
|
||||
|
||||
@@ -306,8 +302,8 @@ class StdoutLogger extends Logger {
|
||||
onFinish: _clearStatus,
|
||||
stdio: _stdio,
|
||||
timeoutConfiguration: _timeoutConfiguration,
|
||||
platform: _platform,
|
||||
stopwatch: _stopwatchFactory.createStopwatch(),
|
||||
terminal: _terminal,
|
||||
)..start();
|
||||
} else {
|
||||
_status = SummaryStatus(
|
||||
@@ -352,7 +348,6 @@ class WindowsStdoutLogger extends StdoutLogger {
|
||||
@required Stdio stdio,
|
||||
@required OutputPreferences outputPreferences,
|
||||
@required TimeoutConfiguration timeoutConfiguration,
|
||||
@required Platform platform,
|
||||
StopwatchFactory stopwatchFactory = const StopwatchFactory(),
|
||||
}) : super(
|
||||
terminal: terminal,
|
||||
@@ -360,15 +355,16 @@ class WindowsStdoutLogger extends StdoutLogger {
|
||||
outputPreferences: outputPreferences,
|
||||
timeoutConfiguration: timeoutConfiguration,
|
||||
stopwatchFactory: stopwatchFactory,
|
||||
platform: platform,
|
||||
);
|
||||
|
||||
@override
|
||||
void writeToStdOut(String message) {
|
||||
// TODO(jcollins-g): wrong abstraction layer for this, move to [Stdio].
|
||||
final String windowsMessage = message
|
||||
.replaceAll('✗', 'X')
|
||||
.replaceAll('✓', '√');
|
||||
final String windowsMessage = _terminal.supportsEmoji
|
||||
? message
|
||||
: message.replaceAll('🔥', '')
|
||||
.replaceAll('✗', 'X')
|
||||
.replaceAll('✓', '√');
|
||||
_stdio.stdoutWrite(windowsMessage);
|
||||
}
|
||||
}
|
||||
@@ -681,19 +677,18 @@ abstract class Status {
|
||||
@required Duration timeout,
|
||||
@required TimeoutConfiguration timeoutConfiguration,
|
||||
@required Stopwatch stopwatch,
|
||||
@required bool supportsColor,
|
||||
@required Platform platform,
|
||||
@required AnsiTerminal terminal,
|
||||
VoidCallback onFinish,
|
||||
SlowWarningCallback slowWarningCallback,
|
||||
}) {
|
||||
if (supportsColor) {
|
||||
if (terminal.supportsColor) {
|
||||
return AnsiSpinner(
|
||||
timeout: timeout,
|
||||
onFinish: onFinish,
|
||||
slowWarningCallback: slowWarningCallback,
|
||||
timeoutConfiguration: timeoutConfiguration,
|
||||
stopwatch: stopwatch,
|
||||
platform: platform,
|
||||
terminal: terminal,
|
||||
)..start();
|
||||
}
|
||||
return SilentStatus(
|
||||
@@ -862,12 +857,12 @@ class AnsiSpinner extends Status {
|
||||
@required Duration timeout,
|
||||
@required TimeoutConfiguration timeoutConfiguration,
|
||||
@required Stopwatch stopwatch,
|
||||
@required Platform platform,
|
||||
@required AnsiTerminal terminal,
|
||||
VoidCallback onFinish,
|
||||
this.slowWarningCallback,
|
||||
Stdio stdio,
|
||||
}) : _stdio = stdio ?? globals.stdio,
|
||||
_isWindows = platform.isWindows,
|
||||
_terminal = terminal,
|
||||
super(
|
||||
timeout: timeout,
|
||||
onFinish: onFinish,
|
||||
@@ -878,7 +873,7 @@ class AnsiSpinner extends Status {
|
||||
final String _backspaceChar = '\b';
|
||||
final String _clearChar = ' ';
|
||||
final Stdio _stdio;
|
||||
final bool _isWindows;
|
||||
final AnsiTerminal _terminal;
|
||||
|
||||
bool timedOut = false;
|
||||
|
||||
@@ -886,7 +881,7 @@ class AnsiSpinner extends Status {
|
||||
Timer timer;
|
||||
|
||||
// Windows console font has a limited set of Unicode characters.
|
||||
List<String> get _animation => _isWindows
|
||||
List<String> get _animation => !_terminal.supportsEmoji
|
||||
? const <String>[r'-', r'\', r'|', r'/']
|
||||
: const <String>['⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷'];
|
||||
|
||||
@@ -984,7 +979,7 @@ class AnsiStatus extends AnsiSpinner {
|
||||
this.padding = kDefaultStatusPadding,
|
||||
@required Duration timeout,
|
||||
@required Stopwatch stopwatch,
|
||||
@required Platform platform,
|
||||
@required AnsiTerminal terminal,
|
||||
VoidCallback onFinish,
|
||||
Stdio stdio,
|
||||
TimeoutConfiguration timeoutConfiguration,
|
||||
@@ -997,7 +992,7 @@ class AnsiStatus extends AnsiSpinner {
|
||||
stdio: stdio,
|
||||
timeoutConfiguration: timeoutConfiguration,
|
||||
stopwatch: stopwatch,
|
||||
platform: platform,
|
||||
terminal: terminal,
|
||||
);
|
||||
|
||||
final String message;
|
||||
|
||||
@@ -86,7 +86,10 @@ class OutputPreferences {
|
||||
}
|
||||
|
||||
class AnsiTerminal {
|
||||
AnsiTerminal({@required io.Stdio stdio, @required Platform platform})
|
||||
AnsiTerminal({
|
||||
@required io.Stdio stdio,
|
||||
@required Platform platform,
|
||||
})
|
||||
: _stdio = stdio,
|
||||
_platform = platform;
|
||||
|
||||
@@ -121,7 +124,16 @@ class AnsiTerminal {
|
||||
|
||||
bool get supportsColor => _platform.stdoutSupportsAnsi ?? false;
|
||||
|
||||
final RegExp _boldControls = RegExp('(${RegExp.escape(resetBold)}|${RegExp.escape(bold)})');
|
||||
// Assume unicode emojis are supported when not on Windows.
|
||||
// If we are on Windows, unicode emojis are supported in Windows Terminal,
|
||||
// which sets the WT_SESSION environment variable. See:
|
||||
// https://github.com/microsoft/terminal/blob/master/doc/user-docs/index.md#tips-and-tricks
|
||||
bool get supportsEmoji => !_platform.isWindows
|
||||
|| _platform.environment.containsKey('WT_SESSION');
|
||||
|
||||
final RegExp _boldControls = RegExp(
|
||||
'(${RegExp.escape(resetBold)}|${RegExp.escape(bold)})',
|
||||
);
|
||||
|
||||
/// Whether we are interacting with the flutter tool via the terminal.
|
||||
///
|
||||
|
||||
@@ -127,14 +127,12 @@ Future<T> runInContext<T>(
|
||||
stdio: globals.stdio,
|
||||
outputPreferences: outputPreferences,
|
||||
timeoutConfiguration: timeoutConfiguration,
|
||||
platform: globals.platform,
|
||||
)
|
||||
: StdoutLogger(
|
||||
terminal: globals.terminal,
|
||||
stdio: globals.stdio,
|
||||
outputPreferences: outputPreferences,
|
||||
timeoutConfiguration: timeoutConfiguration,
|
||||
platform: globals.platform,
|
||||
),
|
||||
MacOSWorkflow: () => const MacOSWorkflow(),
|
||||
MDnsObservatoryDiscovery: () => MDnsObservatoryDiscovery(),
|
||||
|
||||
@@ -258,8 +258,7 @@ class Doctor {
|
||||
slowWarningCallback: () => validator.slowWarning,
|
||||
timeoutConfiguration: timeoutConfiguration,
|
||||
stopwatch: Stopwatch(),
|
||||
supportsColor: globals.terminal.supportsColor,
|
||||
platform: globals.platform,
|
||||
terminal: globals.terminal,
|
||||
);
|
||||
ValidationResult result;
|
||||
try {
|
||||
|
||||
@@ -314,9 +314,8 @@ class XcodeProjectInterpreter {
|
||||
final Status status = Status.withSpinner(
|
||||
timeout: const TimeoutConfiguration().fastOperation,
|
||||
timeoutConfiguration: const TimeoutConfiguration(),
|
||||
platform: _platform,
|
||||
stopwatch: Stopwatch(),
|
||||
supportsColor: _terminal.supportsColor,
|
||||
terminal: _terminal,
|
||||
);
|
||||
final List<String> showBuildSettingsCommand = <String>[
|
||||
_executable,
|
||||
|
||||
Reference in New Issue
Block a user