1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:math' as math;
import 'logger.dart';
import 'platform.dart';
import 'terminal.dart';
const String fire = '🔥';
const int maxLineWidth = 84;
/// Encapsulates the help text construction and printing.
class CommandHelp {
CommandHelp({
required Logger logger,
required AnsiTerminal terminal,
required Platform platform,
required OutputPreferences outputPreferences,
}) : _logger = logger,
_terminal = terminal,
_platform = platform,
_outputPreferences = outputPreferences;
final Logger _logger;
final AnsiTerminal _terminal;
final Platform _platform;
final OutputPreferences _outputPreferences;
// COMMANDS IN ALPHABETICAL ORDER.
// Uppercase first, then lowercase.
// When updating this, update all the tests in command_help_test.dart accordingly.
late final CommandHelpOption I = _makeOption(
'I',
'Toggle oversized image inversion.',
'debugInvertOversizedImages',
);
late final CommandHelpOption L = _makeOption(
'L',
'Dump layer tree to the console.',
'debugDumpLayerTree',
);
late final CommandHelpOption M = _makeOption(
'M',
'Write SkSL shaders to a unique file in the project directory.',
);
late final CommandHelpOption P = _makeOption(
'P',
'Toggle performance overlay.',
'WidgetsApp.showPerformanceOverlay',
);
late final CommandHelpOption R = _makeOption(
'R',
'Hot restart.',
);
late final CommandHelpOption S = _makeOption(
'S',
'Dump accessibility tree in traversal order.',
'debugDumpSemantics',
);
late final CommandHelpOption U = _makeOption(
'U',
'Dump accessibility tree in inverse hit test order.',
'debugDumpSemantics',
);
late final CommandHelpOption a = _makeOption(
'a',
'Toggle timeline events for all widget build methods.',
'debugProfileWidgetBuilds',
);
late final CommandHelpOption b = _makeOption(
'b',
'Toggle platform brightness (dark and light mode).',
'debugBrightnessOverride',
);
late final CommandHelpOption c = _makeOption(
'c',
'Clear the screen',
);
late final CommandHelpOption d = _makeOption(
'd',
'Detach (terminate "flutter run" but leave application running).',
);
late final CommandHelpOption f = _makeOption(
'f',
'Dump focus tree to the console.',
'debugDumpFocusTree',
);
late final CommandHelpOption g = _makeOption(
'g',
'Run source code generators.'
);
late final CommandHelpOption hWithDetails = _makeOption(
'h',
'Repeat this help message.',
);
late final CommandHelpOption hWithoutDetails = _makeOption(
'h',
'List all available interactive commands.',
);
late final CommandHelpOption i = _makeOption(
'i',
'Toggle widget inspector.',
'WidgetsApp.showWidgetInspectorOverride',
);
late final CommandHelpOption j = _makeOption(
'j',
'Dump frame raster stats for the current frame. (Unsupported for web)',
);
late final CommandHelpOption k = _makeOption(
'k',
'Toggle CanvasKit rendering.',
);
late final CommandHelpOption o = _makeOption(
'o',
'Simulate different operating systems.',
'defaultTargetPlatform',
);
late final CommandHelpOption p = _makeOption(
'p',
'Toggle the display of construction lines.',
'debugPaintSizeEnabled',
);
late final CommandHelpOption q = _makeOption(
'q',
'Quit (terminate the application on the device).',
);
late final CommandHelpOption r = _makeOption(
'r',
'Hot reload. $fire$fire$fire',
);
late final CommandHelpOption s = _makeOption(
's',
'Save a screenshot to flutter.png.',
);
late final CommandHelpOption t = _makeOption(
't',
'Dump rendering tree to the console.',
'debugDumpRenderTree',
);
late final CommandHelpOption v = _makeOption(
'v',
'Open Flutter DevTools.',
);
late final CommandHelpOption w = _makeOption(
'w',
'Dump widget hierarchy to the console.',
'debugDumpApp',
);
// When updating the list above, see the notes above the list regarding order
// and tests.
CommandHelpOption _makeOption(String key, String description, [
String inParenthesis = '',
]) {
return CommandHelpOption(
key,
description,
inParenthesis: inParenthesis,
logger: _logger,
terminal: _terminal,
platform: _platform,
outputPreferences: _outputPreferences,
);
}
}
/// Encapsulates printing help text for a single option.
class CommandHelpOption {
CommandHelpOption(
this.key,
this.description, {
this.inParenthesis = '',
required Logger logger,
required Terminal terminal,
required Platform platform,
required OutputPreferences outputPreferences,
}) : _logger = logger,
_terminal = terminal,
_platform = platform,
_outputPreferences = outputPreferences;
final Logger _logger;
final Terminal _terminal;
final Platform _platform;
final OutputPreferences _outputPreferences;
/// The key associated with this command.
final String key;
/// A description of what this command does.
final String description;
/// Text shown in parenthesis to give the context.
final String inParenthesis;
bool get _hasTextInParenthesis => inParenthesis.isNotEmpty;
int get _rawMessageLength => key.length + description.length;
@override
String toString() {
final StringBuffer message = StringBuffer();
message.writeAll(<String>[_terminal.bolden(key), description], ' ');
if (!_hasTextInParenthesis) {
return message.toString();
}
bool wrap = false;
final int maxWidth = math.max(
_outputPreferences.wrapColumn,
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));
// Terminals seem to require this because we have both bolded and colored
// a line. Otherwise the next line comes out bold until a reset bold.
if (_terminal.supportsColor) {
message.write(AnsiTerminal.resetBold);
}
return message.toString();
}
void print() {
_logger.printStatus(toString());
}
}