Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 4101abf

Browse files
author
exoego
committed
Overhaul readline module
1 parent 06af616 commit 4101abf

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ The following core Node.js modules (v8.7.0+) have been implemented:
3838
| [path](https://nodejs.org/api/path.html) | :heavy_check_mark: |
3939
| [process](https://nodejs.org/api/process.html) | :heavy_check_mark: |
4040
| [querystring](https://nodejs.org/api/querystring.html) | :heavy_check_mark: |
41-
| [readline](https://nodejs.org/api/readline.html) | |
41+
| [readline](https://nodejs.org/api/readline.html) | :heavy_check_mark: |
4242
| [repl](https://nodejs.org/api/repl.html) | :heavy_check_mark: |
4343
| [stream](https://nodejs.org/api/stream.html) | |
4444
| [string-decoder](https://nodejs.org/api/string_decoder.html) | :heavy_check_mark: |

app/current/src/main/scala/io/scalajs/nodejs/readline/Interface.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ trait Interface extends IEventEmitter {
5151
* If output is set to null or undefined when calling createInterface, nothing is displayed.
5252
* @example rl.question(query, callback)
5353
*/
54-
def question(query: String, callback: js.Function): Unit = js.native
54+
def question(query: String, callback: js.Function1[String, Any]): Unit = js.native
5555

5656
/**
5757
* Resumes the readline input stream.
@@ -71,7 +71,7 @@ trait Interface extends IEventEmitter {
7171
* This will also resume the input stream if it has been paused.
7272
* @example rl.write(data[, key])
7373
*/
74-
def write(data: String, key: js.Any): Unit = js.native
74+
def write(data: String, key: Key): Unit = js.native
7575

7676
/**
7777
* Writes data to output stream, unless output is set to null or undefined when calling createInterface.
@@ -81,8 +81,16 @@ trait Interface extends IEventEmitter {
8181
*/
8282
def write(data: String): Unit = js.native
8383

84+
// TODO: [Symbol.asyncIterator]()
8485
}
8586

87+
class Key(
88+
var ctrl: js.UndefOr[Boolean] = js.undefined,
89+
var meta: js.UndefOr[Boolean] = js.undefined,
90+
var shift: js.UndefOr[Boolean] = js.undefined,
91+
var name: js.UndefOr[String] = js.undefined
92+
) extends js.Object
93+
8694
/**
8795
* Readline Interface Companion
8896
*/

app/current/src/main/scala/io/scalajs/nodejs/readline/Readline.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package io.scalajs.nodejs.readline
22

33
import io.scalajs.nodejs.events.IEventEmitter
4+
import io.scalajs.nodejs.stream.{Readable, Writable}
45

56
import scala.scalajs.js
67
import scala.scalajs.js.annotation.JSImport
78

8-
/**
9-
* Readline allows reading of a stream (such as process.stdin) on a line-by-line basis.
9+
/**reading
10+
* Readline allows of a stream (such as process.stdin) on a line-by-line basis.
1011
* To use this module, do require('readline').
1112
* Note that once you've invoked this module, your Node.js program will not terminate until you've closed the interface.
1213
* @see https://nodejs.org/api/readline.html
@@ -23,13 +24,13 @@ trait Readline extends IEventEmitter {
2324
* </ul>
2425
* @example readline.clearLine(stream, dir)
2526
*/
26-
def clearLine(stream: js.Any, dir: Int): Unit = js.native
27+
def clearLine(stream: Writable, dir: Int, callback: js.Function = js.native): Boolean = js.native
2728

2829
/**
2930
* Clears the screen from the current position of the cursor down.
3031
* @example readline.clearScreenDown(stream)
3132
*/
32-
def clearScreenDown(stream: js.Any): Unit = js.native
33+
def clearScreenDown(stream: Writable, callback: js.Function = js.native): Boolean = js.native
3334

3435
/**
3536
* Creates a readline Interface instance.
@@ -41,13 +42,17 @@ trait Readline extends IEventEmitter {
4142
* Move cursor to the specified position in a given TTY stream.
4243
* @example readline.cursorTo(stream, x, y)
4344
*/
44-
def cursorTo(stream: js.Any, x: Int, y: Int): Unit = js.native
45+
def cursorTo(stream: Writable, x: Int, y: Int, callback: js.Function = js.native): Unit = js.native
46+
def cursorTo(stream: Writable, x: Int, callback: js.Function): Unit = js.native
47+
def cursorTo(stream: Writable, x: Int): Unit = js.native
48+
49+
def emitKeypressEvents(stream: Readable, interface: Interface = js.native): Unit = js.native
4550

4651
/**
4752
* Move cursor relative to it's current position in a given TTY stream.
4853
* @example readline.moveCursor(stream, dx, dy)
4954
*/
50-
def moveCursor(stream: js.Any, dx: Int, dy: Int): Unit = js.native
55+
def moveCursor(stream: Writable, dx: Int, dy: Int, callback: js.Function = js.native): Unit = js.native
5156

5257
}
5358

app/current/src/main/scala/io/scalajs/nodejs/readline/ReadlineOptions.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ import scala.scalajs.js
77
/**
88
* Readline Options
99
*/
10-
class ReadlineOptions(var input: js.UndefOr[Readable] = js.undefined,
11-
var output: js.UndefOr[Writable] = js.undefined,
12-
var completer: js.UndefOr[js.Function] = js.undefined,
13-
var terminal: js.UndefOr[Boolean] = js.undefined,
14-
var historySize: js.UndefOr[Int] = js.undefined)
15-
extends js.Object
10+
class ReadlineOptions(
11+
var input: js.UndefOr[Readable] = js.undefined,
12+
var output: js.UndefOr[Writable] = js.undefined,
13+
var completer: js.UndefOr[js.Function] = js.undefined,
14+
var terminal: js.UndefOr[Boolean] = js.undefined,
15+
var historySize: js.UndefOr[Int] = js.undefined,
16+
var prompt: js.UndefOr[String] = js.undefined,
17+
var crlfDelay: js.UndefOr[Double] = js.undefined,
18+
var removeHistoryDuplicates: js.UndefOr[Boolean] = js.undefined,
19+
var escapeCodeTimeout: js.UndefOr[Double] = js.undefined
20+
) extends js.Object

0 commit comments

Comments
 (0)