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

Commit

Permalink
Overhaul readline module
Browse files Browse the repository at this point in the history
  • Loading branch information
exoego committed Sep 27, 2019
1 parent 06af616 commit 4101abf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The following core Node.js modules (v8.7.0+) have been implemented:
| [path](https://nodejs.org/api/path.html) | :heavy_check_mark: |
| [process](https://nodejs.org/api/process.html) | :heavy_check_mark: |
| [querystring](https://nodejs.org/api/querystring.html) | :heavy_check_mark: |
| [readline](https://nodejs.org/api/readline.html) | |
| [readline](https://nodejs.org/api/readline.html) | :heavy_check_mark: |
| [repl](https://nodejs.org/api/repl.html) | :heavy_check_mark: |
| [stream](https://nodejs.org/api/stream.html) | |
| [string-decoder](https://nodejs.org/api/string_decoder.html) | :heavy_check_mark: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ trait Interface extends IEventEmitter {
* If output is set to null or undefined when calling createInterface, nothing is displayed.
* @example rl.question(query, callback)
*/
def question(query: String, callback: js.Function): Unit = js.native
def question(query: String, callback: js.Function1[String, Any]): Unit = js.native

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

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

// TODO: [Symbol.asyncIterator]()
}

class Key(
var ctrl: js.UndefOr[Boolean] = js.undefined,
var meta: js.UndefOr[Boolean] = js.undefined,
var shift: js.UndefOr[Boolean] = js.undefined,
var name: js.UndefOr[String] = js.undefined
) extends js.Object

/**
* Readline Interface Companion
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package io.scalajs.nodejs.readline

import io.scalajs.nodejs.events.IEventEmitter
import io.scalajs.nodejs.stream.{Readable, Writable}

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

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

/**
* Clears the screen from the current position of the cursor down.
* @example readline.clearScreenDown(stream)
*/
def clearScreenDown(stream: js.Any): Unit = js.native
def clearScreenDown(stream: Writable, callback: js.Function = js.native): Boolean = js.native

/**
* Creates a readline Interface instance.
Expand All @@ -41,13 +42,17 @@ trait Readline extends IEventEmitter {
* Move cursor to the specified position in a given TTY stream.
* @example readline.cursorTo(stream, x, y)
*/
def cursorTo(stream: js.Any, x: Int, y: Int): Unit = js.native
def cursorTo(stream: Writable, x: Int, y: Int, callback: js.Function = js.native): Unit = js.native
def cursorTo(stream: Writable, x: Int, callback: js.Function): Unit = js.native
def cursorTo(stream: Writable, x: Int): Unit = js.native

def emitKeypressEvents(stream: Readable, interface: Interface = js.native): Unit = js.native

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

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import scala.scalajs.js
/**
* Readline Options
*/
class ReadlineOptions(var input: js.UndefOr[Readable] = js.undefined,
var output: js.UndefOr[Writable] = js.undefined,
var completer: js.UndefOr[js.Function] = js.undefined,
var terminal: js.UndefOr[Boolean] = js.undefined,
var historySize: js.UndefOr[Int] = js.undefined)
extends js.Object
class ReadlineOptions(
var input: js.UndefOr[Readable] = js.undefined,
var output: js.UndefOr[Writable] = js.undefined,
var completer: js.UndefOr[js.Function] = js.undefined,
var terminal: js.UndefOr[Boolean] = js.undefined,
var historySize: js.UndefOr[Int] = js.undefined,
var prompt: js.UndefOr[String] = js.undefined,
var crlfDelay: js.UndefOr[Double] = js.undefined,
var removeHistoryDuplicates: js.UndefOr[Boolean] = js.undefined,
var escapeCodeTimeout: js.UndefOr[Double] = js.undefined
) extends js.Object

0 comments on commit 4101abf

Please sign in to comment.