Skip to content

Commit

Permalink
allow Ctrl-C to escape an unwanted continuation prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra committed Jul 7, 2011
1 parent 2a9fd34 commit 6e9cfd8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
20 changes: 15 additions & 5 deletions lib/repl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 17 additions & 6 deletions src/repl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ stdout = process.stdout
error = (err) ->
stdout.write (err.stack or err.toString()) + '\n\n'

# The current backlog of multi-line code.
backlog = ''

# The main REPL function. **run** is called every time a line of code is entered.
# Attempt to evaluate the command. If there's an exception, print it out instead
# of exiting.
run = do ->
# The current backlog of multi-line code.
backlog = ''
# The REPL context
sandbox = Script.createContext()
sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox
(buffer) ->
unless buffer.toString().trim()
if !buffer.toString().trim() and !backlog
repl.prompt()
return
code = backlog += buffer
Expand Down Expand Up @@ -111,9 +111,20 @@ if readline.createInterface.length < 3
else
repl = readline.createInterface stdin, stdout, autocomplete

repl.setPrompt REPL_PROMPT
repl.on 'close', ->
repl.on 'attemptClose', ->
if backlog
backlog = ''
process.stdout.write '\n'
repl.setPrompt REPL_PROMPT
repl.prompt()
else
repl.close()

repl.on 'close', ->
process.stdout.write '\n'
stdin.destroy()
repl.on 'line', run

repl.on 'line', run

repl.setPrompt REPL_PROMPT
repl.prompt()

0 comments on commit 6e9cfd8

Please sign in to comment.