summaryrefslogtreecommitdiff
path: root/js/repl.ts
diff options
context:
space:
mode:
authorSergey Golovin <golovim@gmail.com>2019-01-29 22:41:12 +0300
committerRyan Dahl <ry@tinyclouds.org>2019-01-29 14:41:12 -0500
commit240ca25617bb57e4071193dbc040ab03a27f3a6c (patch)
tree096dce2ada85b63655658d683ba5b21c70d651de /js/repl.ts
parent457e65bc2f819ffda7a8192747099d62e65582bf (diff)
Add repl functions "help" and "exit" (#1563)
Diffstat (limited to 'js/repl.ts')
-rw-r--r--js/repl.ts24
1 files changed, 19 insertions, 5 deletions
diff --git a/js/repl.ts b/js/repl.ts
index 4fae31eab..6fb395e1b 100644
--- a/js/repl.ts
+++ b/js/repl.ts
@@ -10,6 +10,24 @@ import { globalEval } from "./global_eval";
const window = globalEval("this");
+const helpMsg = [
+ "exit Exit the REPL",
+ "help Print this help message"
+].join("\n");
+
+const replCommands = {
+ exit: {
+ get() {
+ exit(0);
+ }
+ },
+ help: {
+ get() {
+ return helpMsg;
+ }
+ }
+};
+
function startRepl(historyFile: string): number {
const builder = flatbuffers.createBuilder();
const historyFile_ = builder.createString(historyFile);
@@ -54,6 +72,7 @@ export async function readline(rid: number, prompt: string): Promise<string> {
// @internal
export async function replLoop(): Promise<void> {
window.deno = deno; // FIXME use a new scope (rather than window).
+ Object.defineProperties(window, replCommands);
const historyFile = "deno_history.txt";
const rid = startRepl(historyFile);
@@ -69,11 +88,6 @@ export async function replLoop(): Promise<void> {
console.error(err);
exit(1);
}
- if (!code) {
- continue;
- } else if (code.trim() === ".exit") {
- break;
- }
evaluate(code);
}