Skip to content

Commit

Permalink
a bunch of node 0.11 related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra committed Jul 6, 2014
1 parent 3c7bc52 commit f199a7f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
26 changes: 18 additions & 8 deletions lib/repl.js

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

22 changes: 16 additions & 6 deletions src/repl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ CS = require './nodes'

addMultilineHandler = (repl) ->
{rli, inputStream, outputStream} = repl
initialPrompt = repl.prompt.replace /^[^> ]*/, (x) -> x.replace /./g, '-'
continuationPrompt = repl.prompt.replace /^[^> ]*>?/, (x) -> x.replace /./g, '.'
# Node 0.11.12 changed API, prompt is now _prompt.
origPrompt = repl._prompt ? repl.prompt
initialPrompt = origPrompt.replace /^[^> ]*/, (x) -> x.replace /./g, '-'
continuationPrompt = origPrompt.replace /^[^> ]*>?/, (x) -> x.replace /./g, '.'

enabled = no
buffer = ''
Expand All @@ -23,6 +25,7 @@ addMultilineHandler = (repl) ->
rli.setPrompt continuationPrompt
rli.prompt true
else
rli.setPrompt origPrompt
nodeLineListener cmd
return

Expand All @@ -33,7 +36,7 @@ addMultilineHandler = (repl) ->
# allow arbitrarily switching between modes any time before multiple lines are entered
unless buffer.match /\n/
enabled = not enabled
rli.setPrompt repl.prompt
rli.setPrompt origPrompt
rli.prompt true
return
# no-op unless the current line is empty
Expand Down Expand Up @@ -86,8 +89,8 @@ addHistory = (repl, filename, maxSize) ->
repl.rli.on 'exit', -> fs.closeSync fd

# .clear should also clear history
original_clear = repl.commands['.clear'].action
repl.commands['.clear'].action = ->
original_clear = repl.commands[getCommandId(repl, 'clear')].action
repl.commands[getCommandId(repl, 'clear')].action = ->
repl.outputStream.write 'Clearing history...\n'
repl.rli.history = []
fs.closeSync fd
Expand All @@ -96,12 +99,17 @@ addHistory = (repl, filename, maxSize) ->
original_clear.call this

# add a command to show the history stack
repl.commands['.history'] =
repl.commands[getCommandId(repl, 'history')] =
help: 'Show command history'
action: ->
repl.outputStream.write "#{repl.rli.history[..].reverse().join '\n'}\n"
do repl.displayPrompt


getCommandId = (repl, commandName) ->
# Node 0.11 changed API, a command such as '.help' is now stored as 'help'
if repl.commands['.help']? then ".#{commandName}" else commandName

module.exports =
start: (opts = {}) ->
# REPL defaults
Expand Down Expand Up @@ -132,4 +140,6 @@ module.exports =
addMultilineHandler repl
if opts.historyFile
addHistory repl, opts.historyFile, opts.historyMaxInputSize
# Adapt help inherited from the node REPL
repl.commands[getCommandId(repl, 'load')].help = 'Load code from a file into this REPL session'
repl
10 changes: 5 additions & 5 deletions test/functions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ suite 'Function Literals', ->
eq a, obj.first
eq b, obj.last

test.skip "destructuring splats", ->
(([{a: [b], c}]...) ->
eq 1, b
eq 2, c
) {a: [1], c: 2}
#test "destructuring splats", ->
# (([{a: [b], c}]...) ->
# eq 1, b
# eq 2, c
# ) {a: [1], c: 2}

test "default values", ->
nonceA = {}
Expand Down
1 change: 1 addition & 0 deletions test/repl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ suite 'REPL', ->
@written[@written.length - 1 - fromEnd].replace /\n$/, ''

historyFile = path.join __dirname, 'coffee_history_test'
console.dir historyFile
process.on 'exit', -> fs.unlinkSync historyFile

testRepl = (desc, fn, testFn = test) ->
Expand Down

0 comments on commit f199a7f

Please sign in to comment.