diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2009-09-24 00:56:24 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2009-09-24 00:56:24 +0200 |
commit | ffded5ac86d603e2b254449ae9ab49af4acc6ce8 (patch) | |
tree | fdab909972fb5fa50aed0323690e484f064bd512 /bin | |
parent | 55a2e8271edb613dd3532904c08e84616c3406af (diff) | |
download | node-new-ffded5ac86d603e2b254449ae9ab49af4acc6ce8.tar.gz |
Extract the good parts of node-repl into standalone library.
Now you can require("/repl.js") in your server to be able to examine it
while it's running.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/node-repl | 43 |
1 files changed, 5 insertions, 38 deletions
diff --git a/bin/node-repl b/bin/node-repl index e2e742f9e8..eb2aff31d5 100755 --- a/bin/node-repl +++ b/bin/node-repl @@ -1,43 +1,10 @@ #!/usr/bin/env node -node.stdio.open(); +puts("Welcome to the Node.js REPL."); +puts("Enter ECMAScript at the prompt."); +puts("Tip 1: Use 'rlwrap node-repl' for a better interface"); +puts("Tip 2: Type Control-D to exit."); -var buffered_cmd = ''; - -function prompt () { - node.stdio.write(buffered_cmd.length ? '... ' : "\nnode> "); -} - -node.stdio.write("Welcome to the Node.js REPL.\n"); -node.stdio.write("Enter ECMAScript at the prompt.\n"); -node.stdio.write("Type Control-D to exit.\n"); -node.stdio.write("For more information, see http://tinyclouds.org/node\n"); - -prompt(); - -var trimmer = /^\s*(.+)\s*$/m; - -node.stdio.addListener("data", function (cmd) { - var matches = trimmer.exec(cmd); - - if (matches && matches.length == 2) { - cmd = matches[1]; - try { - buffered_cmd += cmd; - try { - node.stdio.write(JSON.stringify(eval(buffered_cmd)) + "\n"); - buffered_cmd = ''; - } catch (e) { - if (!(e instanceof SyntaxError)) - throw e; - } - } catch (e) { - node.stdio.writeError('caught an exception: ' + e + '\n'); - buffered_cmd = ''; - } - } - - prompt(); -}); +include("/repl.js"); // vim:ft=javascript |