Unverified Commit 149e0623 authored by Levi Lesches's avatar Levi Lesches Committed by GitHub

Add option to clear the terminal by pressing "c" (#50034)

parent a9b8d360
...@@ -53,6 +53,9 @@ class CommandHelp { ...@@ -53,6 +53,9 @@ class CommandHelp {
CommandHelpOption _a; 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 _d; 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).');
......
...@@ -168,6 +168,9 @@ abstract class Logger { ...@@ -168,6 +168,9 @@ abstract class Logger {
/// Only surfaces a value in machine modes, Loggers may ignore this message in /// Only surfaces a value in machine modes, Loggers may ignore this message in
/// non-machine modes. /// non-machine modes.
void sendEvent(String name, [Map<String, dynamic> args]) { } void sendEvent(String name, [Map<String, dynamic> args]) { }
/// Clears all output.
void clear();
} }
class StdoutLogger extends Logger { class StdoutLogger extends Logger {
...@@ -326,6 +329,13 @@ class StdoutLogger extends Logger { ...@@ -326,6 +329,13 @@ class StdoutLogger extends Logger {
@override @override
void sendEvent(String name, [Map<String, dynamic> args]) { } void sendEvent(String name, [Map<String, dynamic> args]) { }
@override
void clear() {
_status?.pause();
writeToStdOut(_terminal.clearScreen() + '\n');
_status?.resume();
}
} }
/// A [StdoutLogger] which replaces Unicode characters that cannot be printed to /// A [StdoutLogger] which replaces Unicode characters that cannot be printed to
...@@ -470,7 +480,7 @@ class BufferLogger extends Logger { ...@@ -470,7 +480,7 @@ class BufferLogger extends Logger {
)..start(); )..start();
} }
/// Clears all buffers. @override
void clear() { void clear() {
_error.clear(); _error.clear();
_status.clear(); _status.clear();
...@@ -627,6 +637,9 @@ class VerboseLogger extends Logger { ...@@ -627,6 +637,9 @@ class VerboseLogger extends Logger {
@override @override
bool get hasTerminal => parent.hasTerminal; bool get hasTerminal => parent.hasTerminal;
@override
void clear() => parent.clear();
} }
enum _LogType { error, status, trace } enum _LogType { error, status, trace }
......
...@@ -1000,6 +1000,10 @@ class NotifyingLogger extends Logger { ...@@ -1000,6 +1000,10 @@ class NotifyingLogger extends Logger {
@override @override
bool get hasTerminal => false; bool get hasTerminal => false;
// This method is only relevant for terminals.
@override
void clear() { }
} }
/// A running application, started by this daemon. /// A running application, started by this daemon.
...@@ -1230,6 +1234,10 @@ class _AppRunLogger extends Logger { ...@@ -1230,6 +1234,10 @@ class _AppRunLogger extends Logger {
@override @override
bool get hasTerminal => false; bool get hasTerminal => false;
// This method is only relevant for terminals.
@override
void clear() { }
} }
class LogMessage { class LogMessage {
......
...@@ -1052,9 +1052,6 @@ abstract class ResidentRunner { ...@@ -1052,9 +1052,6 @@ abstract class ResidentRunner {
commandHelp.P.print(); commandHelp.P.print();
commandHelp.a.print(); commandHelp.a.print();
} }
if (flutterDevices.any((FlutterDevice d) => d.device.supportsScreenshot)) {
commandHelp.s.print();
}
} }
/// Called when a signal has requested we exit. /// Called when a signal has requested we exit.
...@@ -1062,6 +1059,9 @@ abstract class ResidentRunner { ...@@ -1062,6 +1059,9 @@ abstract class ResidentRunner {
/// Called right before we exit. /// Called right before we exit.
Future<void> cleanupAtFinish(); Future<void> cleanupAtFinish();
// Clears the screen.
void clearScreen() => globals.logger.clear();
} }
class OperationResult { class OperationResult {
...@@ -1167,6 +1167,9 @@ class TerminalHandler { ...@@ -1167,6 +1167,9 @@ class TerminalHandler {
return true; return true;
} }
return false; return false;
case 'c':
residentRunner.clearScreen();
return true;
case 'd': case 'd':
case 'D': case 'D':
await residentRunner.detach(); await residentRunner.detach();
......
...@@ -189,6 +189,7 @@ class ColdRunner extends ResidentRunner { ...@@ -189,6 +189,7 @@ class ColdRunner extends ResidentRunner {
if (_didAttach) { if (_didAttach) {
commandHelp.d.print(); commandHelp.d.print();
} }
commandHelp.c.print();
commandHelp.q.print(); commandHelp.q.print();
for (final FlutterDevice device in flutterDevices) { for (final FlutterDevice device in flutterDevices) {
final String dname = device.device.name; final String dname = device.device.name;
......
...@@ -1053,6 +1053,7 @@ class HotRunner extends ResidentRunner { ...@@ -1053,6 +1053,7 @@ class HotRunner extends ResidentRunner {
if (_didAttach) { if (_didAttach) {
commandHelp.d.print(); commandHelp.d.print();
} }
commandHelp.c.print();
commandHelp.q.print(); commandHelp.q.print();
if (details) { if (details) {
printHelpDetails(); printHelpDetails();
......
...@@ -737,6 +737,9 @@ class StreamLogger extends Logger { ...@@ -737,6 +737,9 @@ class StreamLogger extends Logger {
@override @override
bool get hasTerminal => false; bool get hasTerminal => false;
@override
void clear() => _log('[stdout] ${globals.terminal.clearScreen()}\n');
} }
class LoggerInterrupted implements Exception { class LoggerInterrupted implements Exception {
......
...@@ -377,6 +377,7 @@ void main() { ...@@ -377,6 +377,7 @@ void main() {
commandHelp.r, commandHelp.r,
commandHelp.R, commandHelp.R,
commandHelp.h, commandHelp.h,
commandHelp.c,
commandHelp.q, commandHelp.q,
commandHelp.s, commandHelp.s,
commandHelp.w, commandHelp.w,
...@@ -390,7 +391,6 @@ void main() { ...@@ -390,7 +391,6 @@ void main() {
commandHelp.z, commandHelp.z,
commandHelp.P, commandHelp.P,
commandHelp.a, commandHelp.a,
commandHelp.s,
'An Observatory debugger and profiler on null is available at: null', 'An Observatory debugger and profiler on null is available at: null',
'' ''
].join('\n') ].join('\n')
...@@ -423,6 +423,15 @@ void main() { ...@@ -423,6 +423,15 @@ void main() {
expect(testLogger.errorText, contains('Error')); expect(testLogger.errorText, contains('Error'));
})); }));
test('ResidentTunner clears the screen when it should', () => testbed.run(() async {
const String message = 'This should be cleared';
expect(testLogger.statusText, equals(''));
testLogger.printStatus(message);
expect(testLogger.statusText, equals(message + '\n')); // printStatus makes a newline
residentRunner.clearScreen();
expect(testLogger.statusText, equals(''));
}));
test('ResidentRunner bails taking screenshot on debug device if debugAllowBanner throws post', () => testbed.run(() async { test('ResidentRunner bails taking screenshot on debug device if debugAllowBanner throws post', () => testbed.run(() async {
when(mockDevice.supportsScreenshot).thenReturn(true); when(mockDevice.supportsScreenshot).thenReturn(true);
when(mockIsolate.flutterDebugAllowBanner(true)).thenThrow(Exception()); when(mockIsolate.flutterDebugAllowBanner(true)).thenThrow(Exception());
......
...@@ -822,6 +822,9 @@ class DelegateLogger implements Logger { ...@@ -822,6 +822,9 @@ class DelegateLogger implements Logger {
@override @override
bool get supportsColor => delegate.supportsColor; bool get supportsColor => delegate.supportsColor;
@override
void clear() => delegate.clear();
} }
/// An implementation of the Cache which does not download or require locking. /// An implementation of the Cache which does not download or require locking.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment