cormo
Advanced tools
Comparing version 0.6.1 to 0.6.2
// Generated by CoffeeScript 1.6.2 | ||
(function() { | ||
var CommandConsole, Connection, Fiber, Future, Model, coffee, commander, path, prettyErrorMessage, repl, vm; | ||
var CommandConsole, Connection, Fiber, Future, Model, addHistory, addMultilineHandler, coffee, commander, fs, path, prettyErrorMessage, repl, vm; | ||
@@ -19,2 +19,4 @@ coffee = require('coffee-script'); | ||
fs = require('fs'); | ||
Connection = require('../connection'); | ||
@@ -28,2 +30,96 @@ | ||
addMultilineHandler = function(repl) { | ||
var inputStream, multiline, nodeLineListener, outputStream, rli; | ||
rli = repl.rli, inputStream = repl.inputStream, outputStream = repl.outputStream; | ||
multiline = { | ||
enabled: false, | ||
initialPrompt: repl.prompt.replace(/^[^> ]*/, function(x) { | ||
return x.replace(/./g, '-'); | ||
}), | ||
prompt: repl.prompt.replace(/^[^> ]*>?/, function(x) { | ||
return x.replace(/./g, '.'); | ||
}), | ||
buffer: '' | ||
}; | ||
nodeLineListener = rli.listeners('line')[0]; | ||
rli.removeListener('line', nodeLineListener); | ||
rli.on('line', function(cmd) { | ||
if (multiline.enabled) { | ||
multiline.buffer += "" + cmd + "\n"; | ||
rli.setPrompt(multiline.prompt); | ||
rli.prompt(true); | ||
} else { | ||
nodeLineListener(cmd); | ||
} | ||
}); | ||
return inputStream.on('keypress', function(char, key) { | ||
if (!(key && key.ctrl && !key.meta && !key.shift && key.name === 'v')) { | ||
return; | ||
} | ||
if (multiline.enabled) { | ||
if (!multiline.buffer.match(/\n/)) { | ||
multiline.enabled = !multiline.enabled; | ||
rli.setPrompt(repl.prompt); | ||
rli.prompt(true); | ||
return; | ||
} | ||
if ((rli.line != null) && !rli.line.match(/^\s*$/)) { | ||
return; | ||
} | ||
multiline.enabled = !multiline.enabled; | ||
rli.line = ''; | ||
rli.cursor = 0; | ||
rli.output.cursorTo(0); | ||
rli.output.clearLine(1); | ||
multiline.buffer = multiline.buffer.replace(/\n/g, '\uFF00'); | ||
rli.emit('line', multiline.buffer); | ||
multiline.buffer = ''; | ||
} else { | ||
multiline.enabled = !multiline.enabled; | ||
rli.setPrompt(multiline.initialPrompt); | ||
rli.prompt(true); | ||
} | ||
}); | ||
}; | ||
addHistory = function(repl, filename, maxSize) { | ||
var buffer, fd, lastLine, readFd, size, stat; | ||
lastLine = null; | ||
try { | ||
stat = fs.statSync(filename); | ||
size = Math.min(maxSize, stat.size); | ||
readFd = fs.openSync(filename, 'r'); | ||
buffer = new Buffer(size); | ||
fs.readSync(readFd, buffer, 0, size, stat.size - size); | ||
repl.rli.history = buffer.toString().split('\n').reverse(); | ||
if (stat.size > maxSize) { | ||
repl.rli.history.pop(); | ||
} | ||
if (repl.rli.history[0] === '') { | ||
repl.rli.history.shift(); | ||
} | ||
repl.rli.historyIndex = -1; | ||
lastLine = repl.rli.history[0]; | ||
} catch (_error) {} | ||
fd = fs.openSync(filename, 'a'); | ||
repl.rli.addListener('line', function(code) { | ||
if (code && code.length && code !== '.history' && lastLine !== code) { | ||
fs.write(fd, "" + code + "\n"); | ||
return lastLine = code; | ||
} | ||
}); | ||
repl.rli.on('exit', function() { | ||
return fs.close(fd); | ||
}); | ||
return repl.commands['.history'] = { | ||
help: 'Show command history', | ||
action: function() { | ||
repl.outputStream.write("" + (repl.rli.history.slice(0).reverse().join('\n')) + "\n"); | ||
return repl.displayPrompt(); | ||
} | ||
}; | ||
}; | ||
CommandConsole = (function() { | ||
@@ -57,2 +153,4 @@ function CommandConsole(argv) { | ||
CommandConsole.prototype.runCoffee = function() { | ||
var historyFile; | ||
repl = repl.start({ | ||
@@ -64,5 +162,4 @@ prompt: 'cormo> ', | ||
if (cmd[0] === '(' && cmd[cmd.length - 1] === ')') { | ||
cmd = cmd.substr(1, cmd.length - 2).trim(); | ||
} | ||
cmd = cmd.replace(/\uFF00/g, '\n'); | ||
cmd = cmd.replace(/^\(([\s\S]*)\n\)$/m, '$1'); | ||
if (!cmd) { | ||
@@ -103,2 +200,9 @@ return callback(null); | ||
}); | ||
addMultilineHandler(repl); | ||
if (process.env.HOME) { | ||
historyFile = path.join(process.env.HOME, '.cormo_history'); | ||
} | ||
if (historyFile) { | ||
addHistory(repl, historyFile, 10240); | ||
} | ||
return this._setupContext(repl.context); | ||
@@ -105,0 +209,0 @@ }; |
{ | ||
"name": "cormo", | ||
"description": "ORM framework for Node.js", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "orm", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
212313
5271
11