Index: tools/ddbg_service/lib/commando.dart |
diff --git a/tools/ddbg/lib/commando.dart b/tools/ddbg_service/lib/commando.dart |
similarity index 96% |
copy from tools/ddbg/lib/commando.dart |
copy to tools/ddbg_service/lib/commando.dart |
index f3ff3ea5e888ad76006a5d047364375cf35f2113..f490cf8f836784ff921d649f1d6510037220c611 100644 |
--- a/tools/ddbg/lib/commando.dart |
+++ b/tools/ddbg_service/lib/commando.dart |
@@ -1,13 +1,15 @@ |
-// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
+library commando; |
+ |
import 'dart:async'; |
import 'dart:convert'; |
import 'dart:io'; |
import 'dart:math'; |
-import 'terminfo.dart'; |
+import 'package:ddbg/terminfo.dart'; |
typedef List<String> CommandCompleter(List<String> commandParts); |
@@ -492,6 +494,17 @@ class Commando { |
_cursorPos = _move(pos, newCursorPos); |
_currentLine = newLine; |
} |
+ |
+ void print(String text) { |
+ bool togglePrompt = _promptShown; |
+ if (togglePrompt) { |
+ hide(); |
+ } |
+ _stdout.writeln(text); |
+ if (togglePrompt) { |
+ show(); |
+ } |
+ } |
void hide() { |
if (!_promptShown) { |
@@ -687,15 +700,23 @@ List<String> _myCompleter(List<String> commandTokens) { |
int _helpCount = 0; |
Commando cmdo; |
+var cmdoSubscription; |
void _handleCommand(String rawCommand) { |
String command = rawCommand.trim(); |
cmdo.hide(); |
if (command == 'quit') { |
- cmdo.close().then((_) { |
- print('Exiting'); |
- }); |
+ var future = cmdoSubscription.cancel(); |
+ if (future != null) { |
+ future.then((_) { |
+ print('Exiting'); |
+ exit(0); |
+ }); |
+ } else { |
+ print('Exiting'); |
+ exit(0); |
+ } |
} else if (command == 'help') { |
switch (_helpCount) { |
case 0: |
@@ -727,5 +748,5 @@ void _handleCommand(String rawCommand) { |
void main() { |
print('[Commando demo]'); |
cmdo = new Commando(completer:_myCompleter); |
- cmdo.commands.listen(_handleCommand); |
+ cmdoSubscription = cmdo.commands.listen(_handleCommand); |
} |