|
| 1 | +// Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:math' as math; |
| 6 | + |
| 7 | +import '../globals.dart' as globals; |
| 8 | +import 'terminal.dart'; |
| 9 | + |
| 10 | +const String fire = '🔥'; |
| 11 | +const int maxLineWidth = 84; |
| 12 | + |
| 13 | +/// Encapsulates the help text construction and printing |
| 14 | +class CommandHelp { |
| 15 | + |
| 16 | + const CommandHelp._(this.key, this.description, [this.inParenthesis = '']); |
| 17 | + |
| 18 | + static const CommandHelp L = CommandHelp._('L', 'Dump layer tree to the console.', 'debugDumpLayerTree'); |
| 19 | + static const CommandHelp P = CommandHelp._('P', 'Toggle performance overlay.', 'WidgetsApp.showPerformanceOverlay'); |
| 20 | + static const CommandHelp R = CommandHelp._('R', 'Hot restart.'); |
| 21 | + static const CommandHelp S = CommandHelp._('S', 'Dump accessibility tree in traversal order.', 'debugDumpSemantics'); |
| 22 | + static const CommandHelp U = CommandHelp._('U', 'Dump accessibility tree in inverse hit test order.', 'debugDumpSemantics'); |
| 23 | + static const CommandHelp a = CommandHelp._('a', 'Toggle timeline events for all widget build methods.', 'debugProfileWidgetBuilds'); |
| 24 | + static const CommandHelp d = CommandHelp._('d', 'Detach (terminate "flutter run" but leave application running).'); |
| 25 | + static const CommandHelp h = CommandHelp._('h', 'Repeat this help message.'); |
| 26 | + static const CommandHelp i = CommandHelp._('i', 'Toggle widget inspector.', 'WidgetsApp.showWidgetInspectorOverride'); |
| 27 | + static const CommandHelp o = CommandHelp._('o', 'Simulate different operating systems.', 'defaultTargetPlatform'); |
| 28 | + static const CommandHelp p = CommandHelp._('p', 'Toggle the display of construction lines.', 'debugPaintSizeEnabled'); |
| 29 | + static const CommandHelp q = CommandHelp._('q', 'Quit (terminate the application on the device).'); |
| 30 | + static const CommandHelp r = CommandHelp._('r', 'Hot reload. $fire$fire$fire'); |
| 31 | + static const CommandHelp s = CommandHelp._('s', 'Save a screenshot to flutter.png.'); |
| 32 | + static const CommandHelp t = CommandHelp._('t', 'Dump rendering tree to the console.', 'debugDumpRenderTree'); |
| 33 | + static const CommandHelp w = CommandHelp._('w', 'Dump widget hierarchy to the console.', 'debugDumpApp'); |
| 34 | + static const CommandHelp z = CommandHelp._('z', 'Toggle elevation checker.'); |
| 35 | + |
| 36 | + /// The key associated with this command |
| 37 | + final String key; |
| 38 | + /// A description of what this command does |
| 39 | + final String description; |
| 40 | + /// Text shown in parenthesis to give the context |
| 41 | + final String inParenthesis; |
| 42 | + |
| 43 | + bool get _hasTextInParenthesis => inParenthesis != null && inParenthesis.isNotEmpty; |
| 44 | + |
| 45 | + int get _rawMessageLength => key.length + description.length; |
| 46 | + |
| 47 | + @override |
| 48 | + String toString() { |
| 49 | + final StringBuffer message = StringBuffer(); |
| 50 | + message.writeAll(<String>[globals.terminal.bolden(key), description], ' '); |
| 51 | + |
| 52 | + if (_hasTextInParenthesis) { |
| 53 | + bool wrap = false; |
| 54 | + final int maxWidth = math.max(outputPreferences.wrapColumn ?? 0, maxLineWidth); |
| 55 | + int width = maxWidth - (globals.platform.stdoutSupportsAnsi ? _rawMessageLength + 1 : message.length); |
| 56 | + final String parentheticalText = '($inParenthesis)'; |
| 57 | + if (width < parentheticalText.length) { |
| 58 | + width = maxWidth; |
| 59 | + wrap = true; |
| 60 | + } |
| 61 | + |
| 62 | + if (wrap) { |
| 63 | + message.write('\n'); |
| 64 | + } |
| 65 | + // pad according to the raw text |
| 66 | + message.write(''.padLeft(width - parentheticalText.length)); |
| 67 | + |
| 68 | + message.write(globals.terminal.color(parentheticalText, TerminalColor.grey)); |
| 69 | + } |
| 70 | + return message.toString(); |
| 71 | + } |
| 72 | + |
| 73 | + void print() { |
| 74 | + globals.printStatus(toString()); |
| 75 | + } |
| 76 | +} |
0 commit comments