| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library commando; |
| 6 |
| 5 import 'dart:async'; | 7 import 'dart:async'; |
| 6 import 'dart:convert'; | 8 import 'dart:convert'; |
| 7 import 'dart:io'; | 9 import 'dart:io'; |
| 8 import 'dart:math'; | 10 import 'dart:math'; |
| 9 | 11 |
| 10 import 'terminfo.dart'; | 12 import 'package:ddbg/terminfo.dart'; |
| 11 | 13 |
| 12 typedef List<String> CommandCompleter(List<String> commandParts); | 14 typedef List<String> CommandCompleter(List<String> commandParts); |
| 13 | 15 |
| 14 class Commando { | 16 class Commando { |
| 15 // Ctrl keys | 17 // Ctrl keys |
| 16 static const runeCtrlA = 0x01; | 18 static const runeCtrlA = 0x01; |
| 17 static const runeCtrlB = 0x02; | 19 static const runeCtrlB = 0x02; |
| 18 static const runeCtrlD = 0x04; | 20 static const runeCtrlD = 0x04; |
| 19 static const runeCtrlE = 0x05; | 21 static const runeCtrlE = 0x05; |
| 20 static const runeCtrlF = 0x06; | 22 static const runeCtrlF = 0x06; |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 if ('gondola'.startsWith(lastWord)) { | 682 if ('gondola'.startsWith(lastWord)) { |
| 681 completions.add('gondola'); | 683 completions.add('gondola'); |
| 682 } | 684 } |
| 683 | 685 |
| 684 return completions; | 686 return completions; |
| 685 } | 687 } |
| 686 | 688 |
| 687 | 689 |
| 688 int _helpCount = 0; | 690 int _helpCount = 0; |
| 689 Commando cmdo; | 691 Commando cmdo; |
| 692 var cmdoSubscription; |
| 690 | 693 |
| 691 | 694 |
| 692 void _handleCommand(String rawCommand) { | 695 void _handleCommand(String rawCommand) { |
| 693 String command = rawCommand.trim(); | 696 String command = rawCommand.trim(); |
| 694 cmdo.hide(); | 697 cmdo.hide(); |
| 695 if (command == 'quit') { | 698 if (command == 'quit') { |
| 696 cmdo.close().then((_) { | 699 var future = cmdoSubscription.cancel(); |
| 697 print('Exiting'); | 700 if (future != null) { |
| 698 }); | 701 future.then((_) { |
| 702 print('Exiting'); |
| 703 exit(0); |
| 704 }); |
| 705 } else { |
| 706 print('Exiting'); |
| 707 exit(0); |
| 708 } |
| 699 } else if (command == 'help') { | 709 } else if (command == 'help') { |
| 700 switch (_helpCount) { | 710 switch (_helpCount) { |
| 701 case 0: | 711 case 0: |
| 702 print('I will not help you.'); | 712 print('I will not help you.'); |
| 703 break; | 713 break; |
| 704 case 1: | 714 case 1: |
| 705 print('I mean it.'); | 715 print('I mean it.'); |
| 706 break; | 716 break; |
| 707 case 2: | 717 case 2: |
| 708 print('Seriously.'); | 718 print('Seriously.'); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 720 } else { | 730 } else { |
| 721 print('Received command($command)'); | 731 print('Received command($command)'); |
| 722 } | 732 } |
| 723 cmdo.show(); | 733 cmdo.show(); |
| 724 } | 734 } |
| 725 | 735 |
| 726 | 736 |
| 727 void main() { | 737 void main() { |
| 728 print('[Commando demo]'); | 738 print('[Commando demo]'); |
| 729 cmdo = new Commando(completer:_myCompleter); | 739 cmdo = new Commando(completer:_myCompleter); |
| 730 cmdo.commands.listen(_handleCommand); | 740 cmdoSubscription = cmdo.commands.listen(_handleCommand); |
| 731 } | 741 } |
| OLD | NEW |