OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 #library('readline'); |
| 6 #import('node.dart'); |
| 7 |
| 8 // module readline |
| 9 |
| 10 // Actual shape of result is [List<String>, String] |
| 11 typedef List ReadlineCompleter(String linePartial); |
| 12 |
| 13 // Actual shape of results is [List<String>, String] |
| 14 typedef void ReadlineCompleterCallback(var unused_pass_null, List results); |
| 15 |
| 16 typedef void ReadlineCompleterAsync(String linePartial, |
| 17 ReadlineCompleterCallback callback); |
| 18 |
| 19 class Readline native "require('readline')" { |
| 20 static ReadlineInterface createInterface(ReadStream input, WriteStream output, |
| 21 [ReadlineCompleter completer]) native; |
| 22 static ReadlineInterface createInterfaceAsyncCompleter(ReadStream input, |
| 23 WriteStream output, ReadlineCompleterAsync completer) |
| 24 native "this.createInterface(input, output, completer);"; |
| 25 static int columns; |
| 26 } |
| 27 |
| 28 typedef void ReadlineInterfaceLineListener(String line); |
| 29 typedef void ReadlineInterfaceCloseListener(); |
| 30 typedef void ReadlineInterfaceQuestionCallback(String answer); |
| 31 |
| 32 class ReadlineInterface implements EventEmitter native "Readline.Interface" { |
| 33 // EventEmitter |
| 34 void removeAllListeners(String event) |
| 35 native "this.removeAllListeners(event);"; |
| 36 void setMaxListeners(num n) |
| 37 native "this.setMaxListeners(n);"; |
| 38 var _listeners(String key) |
| 39 native "return this.listeners(key);"; |
| 40 |
| 41 // event 'line' |
| 42 void emitLine(String line) |
| 43 native "this.emit('line');"; |
| 44 void addListenerLine(ReadlineInterfaceLineListener listener) |
| 45 native "this.addListener('line', listener);"; |
| 46 void onLine(ReadlineInterfaceLineListener listener) |
| 47 native "this.on('line', listener);"; |
| 48 void onceLine(ReadlineInterfaceLineListener listener) |
| 49 native "this.once('line', listener);"; |
| 50 void removeListenerLine(ReadlineInterfaceLineListener listener) |
| 51 native "this.removeListener('line', listener);"; |
| 52 List<ReadlineInterfaceLineListener> listenersLine() |
| 53 => new _NativeListPrimitiveElement<ReadlineInterfaceLineListener>( |
| 54 _listeners('line')); |
| 55 |
| 56 // event 'close' |
| 57 void emitClose() |
| 58 native "this.emit('close');"; |
| 59 void addListenerClose(ReadlineInterfaceCloseListener listener) |
| 60 native "this.addListener('close', listener);"; |
| 61 void onClose(ReadlineInterfaceCloseListener listener) |
| 62 native "this.on('close', listener);"; |
| 63 void onceClose(ReadlineInterfaceCloseListener listener) |
| 64 native "this.once('close', listener);"; |
| 65 void removeListenerClose(ReadlineInterfaceCloseListener listener) |
| 66 native "this.removeListener('close', listener);"; |
| 67 List<ReadlineInterfaceCloseListener> listenersClose() |
| 68 => new _NativeListPrimitiveElement<ReadlineInterfaceCloseListener>( |
| 69 _listeners('close')); |
| 70 |
| 71 void setPrompt(String prompt, [int length]) native; |
| 72 void prompt() native; |
| 73 void question(String question, ReadlineInterfaceQuestionCallback callback) |
| 74 native; |
| 75 void close() native; |
| 76 void pause() native; |
| 77 void resume() native; |
| 78 void write(String s) native; |
| 79 } |
OLD | NEW |