Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add simple startup file support to REPL (.coffeerc) #1996

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/coffee-script/repl.js

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

11 changes: 9 additions & 2 deletions src/repl.coffee
Expand Up @@ -10,6 +10,7 @@ readline = require 'readline'
{inspect} = require 'util'
{Script} = require 'vm'
Module = require 'module'
fs = require 'fs'

# REPL Setup

Expand All @@ -34,7 +35,7 @@ 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 = (buffer) ->
run = (buffer, echo_output=true) ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase variables

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and a space before and after the operator

if !buffer.toString().trim() and !backlog
repl.prompt()
return
Expand All @@ -54,7 +55,8 @@ run = (buffer) ->
}
if returnValue is undefined
global._ = _
process.stdout.write inspect(returnValue, no, 2, enableColours) + '\n'
if echo_output
process.stdout.write inspect(returnValue, no, 2, enableColours) + '\n'
catch err
error err
repl.prompt()
Expand Down Expand Up @@ -120,5 +122,10 @@ repl.on 'close', ->

repl.on 'line', run

fs.readFile '.coffeerc',
(err, data) ->
unless err
run data, false

repl.setPrompt REPL_PROMPT
repl.prompt()