mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Use separate variable for fd used to read history file; use string interpolation to print code lines; do not use unit test to remove temporary file and instead use a process exit event handler
This commit is contained in:
@@ -92,13 +92,13 @@
|
||||
};
|
||||
|
||||
addHistory = function(repl, filename) {
|
||||
var buffer, fd, size, stat;
|
||||
var buffer, fd, readFd, size, stat;
|
||||
try {
|
||||
stat = fs.statSync(filename);
|
||||
size = Math.min(10240, stat.size);
|
||||
fd = fs.openSync(filename, 'r');
|
||||
readFd = fs.openSync(filename, 'r');
|
||||
buffer = new Buffer(size);
|
||||
fs.readSync(fd, buffer, 0, size, stat.size - size);
|
||||
fs.readSync(readFd, buffer, 0, size, stat.size - size);
|
||||
repl.rli.history = buffer.toString().split('\n').reverse();
|
||||
repl.rli.history.shift();
|
||||
repl.rli.historyIndex = -1;
|
||||
@@ -106,7 +106,7 @@
|
||||
fd = fs.openSync(filename, 'a');
|
||||
repl.rli.addListener('line', function(code) {
|
||||
if (code && code.length && code !== '.history') {
|
||||
return fs.write(fd, code + '\n');
|
||||
return fs.write(fd, "" + code + "\n");
|
||||
}
|
||||
});
|
||||
process.on('exit', function() {
|
||||
|
||||
@@ -86,9 +86,9 @@ addHistory = (repl, filename) ->
|
||||
stat = fs.statSync filename
|
||||
size = Math.min 10240, stat.size
|
||||
# Read last `size` bytes from the file
|
||||
fd = fs.openSync filename, 'r'
|
||||
readFd = fs.openSync filename, 'r'
|
||||
buffer = new Buffer(size)
|
||||
fs.readSync fd, buffer, 0, size, stat.size - size
|
||||
fs.readSync readFd, buffer, 0, size, stat.size - size
|
||||
# Set the history on the interpreter
|
||||
repl.rli.history = buffer.toString().split('\n').reverse()
|
||||
repl.rli.history.shift()
|
||||
@@ -99,7 +99,7 @@ addHistory = (repl, filename) ->
|
||||
repl.rli.addListener 'line', (code) ->
|
||||
if code and code.length and code isnt '.history'
|
||||
# Save the latest command in the file
|
||||
fs.write fd, code + '\n'
|
||||
fs.write fd, "#{code}\n"
|
||||
|
||||
process.on 'exit', ->
|
||||
fs.closeSync fd
|
||||
|
||||
@@ -107,5 +107,5 @@ testRepl "keeps running after runtime error", (input, output) ->
|
||||
input.emitLine 'a'
|
||||
eq 'undefined', output.lastWrite()
|
||||
|
||||
testRepl 'remove history file', (input, output) ->
|
||||
process.on 'exit', ->
|
||||
fs.unlinkSync historyFile
|
||||
|
||||
Reference in New Issue
Block a user