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
275
276
277
278
279
280
281
282
283
284
285
// 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 'package:meta/meta.dart';
import 'logger.dart';
import 'platform.dart';
import 'terminal.dart';
// ignore_for_file: non_constant_identifier_names
const String fire = '🔥';
const String image = '🖼️';
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;
CommandHelpOption _I;
CommandHelpOption get I => _I ??= _makeOption(
'I',
'Toggle oversized image inversion $image.',
'debugInvertOversizedImages',
);
CommandHelpOption _L;
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 _R;
CommandHelpOption get R => _R ??= _makeOption(
'R',
'Hot restart.',
);
CommandHelpOption _S;
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 _a;
CommandHelpOption get a => _a ??= _makeOption(
'a',
'Toggle timeline events for all widget build methods.',
'debugProfileWidgetBuilds',
);
CommandHelpOption _b;
CommandHelpOption get b => _b ??= _makeOption(
'b',
'Toggle the platform brightness setting (dark and light mode).',
'debugBrightnessOverride',
);
CommandHelpOption _c;
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 _g;
CommandHelpOption get g => _g ??= _makeOption(
'g',
'Run source code generators.'
);
CommandHelpOption _h;
CommandHelpOption get h => _h ??= _makeOption(
'h',
'Repeat this help message.',
);
CommandHelpOption _i;
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 _p;
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 _r;
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 _t;
CommandHelpOption get t => _t ??= _makeOption(
't',
'Dump rendering tree to the console.',
'debugDumpRenderTree',
);
CommandHelpOption _v;
CommandHelpOption get v => _v ??= _makeOption(
'v',
'Launch DevTools.',
);
CommandHelpOption _w;
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 _k;
CommandHelpOption get k => _k ??= _makeOption(
'k',
'Toggle CanvasKit rendering.',
);
CommandHelpOption _M;
CommandHelpOption get M => _M ??= _makeOption(
'M',
'Write SkSL shaders to a unique file in the project directory.',
);
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 != null && 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 ?? 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));
// 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());
}
}