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

Commit 752de7b

Browse files
author
exoego
committed
Overhaul repl module
1 parent 6816d87 commit 752de7b

File tree

4 files changed

+39
-27
lines changed

4 files changed

+39
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The following core Node.js modules (v8.7.0+) have been implemented:
3939
| [process](https://nodejs.org/api/process.html) | :heavy_check_mark: |
4040
| [querystring](https://nodejs.org/api/querystring.html) | :heavy_check_mark: |
4141
| [readline](https://nodejs.org/api/readline.html) | |
42-
| [repl](https://nodejs.org/api/repl.html) | |
42+
| [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: |
4545
| [timers](https://nodejs.org/api/timers.html) | :heavy_check_mark: |

app/current/src/main/scala/io/scalajs/nodejs/repl/REPL.scala

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.scalajs.nodejs.repl
22

33
import io.scalajs.nodejs.events.IEventEmitter
4-
import io.scalajs.nodejs.net.Socket
4+
import io.scalajs.nodejs.stream
55

66
import scala.scalajs.js
77
import scala.scalajs.js.annotation.JSImport
@@ -13,32 +13,31 @@ import scala.scalajs.js.annotation.JSImport
1313
*/
1414
@js.native
1515
trait REPL extends IEventEmitter {
16-
var REPL_MODE_SLOPPY: String = js.native
17-
var REPL_MODE_STRICT: String = js.native
18-
var REPL_MODE_MAGIC: String = js.native
16+
var REPL_MODE_SLOPPY: js.Symbol = js.native
17+
var REPL_MODE_STRICT: js.Symbol = js.native
1918

20-
/**
21-
* @example repl.start([options])
22-
*/
23-
def start(options: REPLOptions): REPLServer = js.native
24-
25-
/**
26-
* @example repl.start([options])
27-
*/
28-
def start(prompt: String, socket: Socket): REPLServer = js.native
29-
30-
/**
31-
* @example repl.start([options])
32-
*/
33-
def start(prompt: String): REPLServer = js.native
34-
35-
/**
36-
* @example repl.start([options])
37-
*/
38-
def start(): REPLServer = js.native
19+
@deprecated("Use REPL_MODE_SLOPPY instead", "Node.js v6.0.0")
20+
var REPL_MODE_MAGIC: js.UndefOr[js.Symbol] = js.native
3921

22+
def start(options: StartOptions = js.native): REPLServer = js.native
23+
def start(prompt: String): REPLServer = js.native
4024
}
4125

26+
class StartOptions(
27+
var prompt: js.UndefOr[String] = js.undefined,
28+
var input: js.UndefOr[stream.Readable] = js.undefined,
29+
var output: js.UndefOr[stream.Writable] = js.undefined,
30+
var terminal: js.UndefOr[Boolean] = js.undefined,
31+
var eval: js.UndefOr[js.Function4[String, js.Object, String, js.Function, Any]] = js.undefined,
32+
var useColors: js.UndefOr[Boolean] = js.undefined,
33+
var useGlobal: js.UndefOr[Boolean] = js.undefined,
34+
var ignoreUndefined: js.UndefOr[Boolean] = js.undefined,
35+
var writer: js.UndefOr[js.Function1[js.Any, Any]] = js.undefined,
36+
var completer: js.UndefOr[js.Function] = js.undefined,
37+
var replMode: js.UndefOr[js.Symbol] = js.undefined,
38+
var breakEvalOnSigint: js.UndefOr[Boolean] = js.undefined
39+
) extends js.Object
40+
4241
/**
4342
* REPL Singleton
4443
*/

app/current/src/main/scala/io/scalajs/nodejs/repl/REPLServer.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package io.scalajs.nodejs.repl
22

3+
import com.thoughtworks.enableIf
34
import io.scalajs.nodejs.events.IEventEmitter
45
import io.scalajs.nodejs.readline.Interface
56

67
import scala.scalajs.js
8+
import scala.scalajs.js.|
79

810
/**
911
* REPL Server
@@ -16,6 +18,9 @@ trait REPLServer extends IEventEmitter with Interface {
1618
*/
1719
val context: REPLContext = js.native
1820

21+
@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs10)
22+
def clearBufferedCommand(): Unit = js.native
23+
1924
/**
2025
* The replServer.defineCommand() method is used to add new .-prefixed commands to the REPL instance.
2126
* Such commands are invoked by typing a period (.) followed by the keyword. The cmd is either a Function
@@ -27,7 +32,7 @@ trait REPLServer extends IEventEmitter with Interface {
2732
* @param keyword The command keyword (without a leading . character).
2833
* @param cmd The function to invoke when the command is processed.
2934
*/
30-
def defineCommand(keyword: String, cmd: js.Function0[Any]): Unit = js.native
35+
def defineCommand(keyword: String, cmd: DefinedCommand | js.Function1[String, Any]): Unit = js.native
3136

3237
/**
3338
* The replServer.displayPrompt() method readies the REPL instance for input from the user, printing the
@@ -52,8 +57,16 @@ trait REPLServer extends IEventEmitter with Interface {
5257
*/
5358
def displayPrompt(): Unit = js.native
5459

60+
@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12)
61+
def setupHistory(historyPath: String, callback: js.Function2[io.scalajs.nodejs.Error, REPLServer, Any]): Unit =
62+
js.native
5563
}
5664

65+
class DefinedCommand(
66+
var action: js.Function1[String, Any],
67+
var help: js.UndefOr[String] = js.undefined
68+
) extends js.Object
69+
5770
/**
5871
* REPL Server Companion
5972
*/

app/current/src/main/scala/io/scalajs/nodejs/repl/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ package object repl {
1313
* REPL Server events
1414
* @param server the given [[REPLServer instance]]
1515
*/
16-
final implicit class REPLServerEvents(val server: REPLServer) extends AnyVal {
16+
final implicit class REPLServerEvents(private val server: REPLServer) extends AnyVal {
1717

1818
@inline
1919
def contextAs[T]: T = server.context.asInstanceOf[T]
@@ -47,7 +47,7 @@ package object repl {
4747
* <li>NODE_REPL_MODE</li>
4848
* </ul>
4949
*/
50-
final implicit class EnvironmentVariableOptions(val env: process.Environment) extends AnyVal {
50+
final implicit class EnvironmentVariableOptions(private val env: process.Environment) extends AnyVal {
5151

5252
/**
5353
* When a valid path is given, persistent REPL history will be saved to the specified file rather

0 commit comments

Comments
 (0)