Commit 067715e3 authored by Devon Carew's avatar Devon Carew

Send exit for flutter run --resident (#3829)

* send ext.flutter.exit

* listen for help restart, quit

* refactor into a separate class
parent 810b3e32
......@@ -3,15 +3,16 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert' show ASCII;
import 'dart:io';
final _AnsiTerminal _terminal = new _AnsiTerminal();
final AnsiTerminal terminal = new AnsiTerminal();
abstract class Logger {
bool get isVerbose => false;
set supportsColor(bool value) {
_terminal.supportsColor = value;
terminal.supportsColor = value;
}
/// Display an error level message to the user. Commands should use this if they
......@@ -59,7 +60,7 @@ class StdoutLogger extends Logger {
_status?.cancel();
_status = null;
print(emphasis ? _terminal.writeBold(message) : message);
print(emphasis ? terminal.writeBold(message) : message);
}
@override
......@@ -70,7 +71,7 @@ class StdoutLogger extends Logger {
_status?.cancel();
_status = null;
if (_terminal.supportsColor) {
if (terminal.supportsColor) {
_status = new _AnsiStatus(message);
return _status;
} else {
......@@ -177,34 +178,48 @@ class _LogMessage {
String prefix = '${millis.toString().padLeft(4)} ms • ';
String indent = ''.padLeft(prefix.length);
if (millis >= 100)
prefix = _terminal.writeBold(prefix.substring(0, prefix.length - 3)) + ' • ';
prefix = terminal.writeBold(prefix.substring(0, prefix.length - 3)) + ' • ';
String indentMessage = message.replaceAll('\n', '\n$indent');
if (type == _LogType.error) {
stderr.writeln(prefix + _terminal.writeBold(indentMessage));
stderr.writeln(prefix + terminal.writeBold(indentMessage));
if (stackTrace != null)
stderr.writeln(indent + stackTrace.toString().replaceAll('\n', '\n$indent'));
} else if (type == _LogType.status) {
print(prefix + _terminal.writeBold(indentMessage));
print(prefix + terminal.writeBold(indentMessage));
} else {
print(prefix + indentMessage);
}
}
}
class _AnsiTerminal {
_AnsiTerminal() {
class AnsiTerminal {
AnsiTerminal() {
// TODO(devoncarew): This detection does not work for Windows.
String term = Platform.environment['TERM'];
supportsColor = term != null && term != 'dumb';
}
static const String _bold = '\u001B[1m';
static const String KEY_F1 = '\u001BOP';
static const String KEY_F5 = '\u001B[15~';
static const String KEY_F10 = '\u001B[21~';
static const String _bold = '\u001B[1m';
static const String _reset = '\u001B[0m';
bool supportsColor;
String writeBold(String str) => supportsColor ? '$_bold$str$_reset' : str;
set singleCharMode(bool value) {
stdin.echoMode = !value;
stdin.lineMode = !value;
}
/// Return keystrokes from the console.
///
/// Useful when the console is in [singleCharMode].
Stream<String> get onCharInput => stdin.transform(ASCII.decoder);
}
class _AnsiStatus extends Status {
......
......@@ -3,8 +3,8 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'dart:convert';
import 'dart:io';
import '../base/common.dart';
import '../base/utils.dart';
......
......@@ -12,8 +12,8 @@ import 'package:web_socket_channel/io.dart';
import 'android/android_device.dart';
import 'application_package.dart';
import 'base/common.dart';
import 'base/utils.dart';
import 'base/os.dart';
import 'base/utils.dart';
import 'build_configuration.dart';
import 'globals.dart';
import 'ios/devices.dart';
......
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