interactive
Advanced tools
Comparing version 0.1.1 to 0.1.5
@@ -18,2 +18,6 @@ var util = require('util'); | ||
var isAbsolute = function (path) { | ||
return path.substr(0,2) == '\\' || path.substr(1,2) == ':\\' || path.substr(0,1) == '/'; | ||
}; | ||
var refreshLine = function () { | ||
@@ -82,2 +86,35 @@ display = display.replace(/[\x00-\x1F\x7F-\x9F]/, "", "g"); | ||
if(display.substr(0,2) == ':l') { | ||
var path = display.substr(3); | ||
if(!isAbsolute(path)) { | ||
path = process.cwd() + '/' + display.substr(3); | ||
} | ||
fs.exists(path, function(exists) { | ||
if(exists) { | ||
fs.readFile(path, {encoding:'utf8'}, function(err, data) { | ||
if(err) { | ||
stdout.write("Couldn't load snippet"); | ||
} else { | ||
command_memory.push(display); | ||
index = command_memory.length; | ||
stdout.write('\n'); | ||
result = eval.apply(global, [data]); | ||
stdout.write('\u001b[37m' + util.inspect(result) + '\u001b[0m'); | ||
pos = 0; | ||
tmp = ""; | ||
display = ""; | ||
refreshLine(); | ||
} | ||
}); | ||
} else { | ||
stdout.write("\nFile doesn't exist!\n"); | ||
pos = 0; | ||
tmp = ""; | ||
display = ""; | ||
refreshLine(); | ||
} | ||
}); | ||
break; | ||
} | ||
if(display.length === 0) { | ||
@@ -208,3 +245,3 @@ if(saved.length === 0) { | ||
module.exports.start = function (name) { | ||
fs.readFile('history.json', { encoding:"utf8" }, function(err, data) { | ||
fs.readFile(__dirname + '/history.json', { encoding:"utf8" }, function(err, data) { | ||
if(err) { | ||
@@ -215,3 +252,7 @@ stdout.write("Couldn't load command history!\n"); | ||
} else { | ||
try { | ||
command_memory = JSON.parse(data); | ||
} catch (e) { | ||
stdout.write("Couldn't load command history!\n"); | ||
} | ||
index = command_memory.length; | ||
@@ -238,8 +279,8 @@ } | ||
module.exports.stop = function (exit) { | ||
fs.writeFile('history.json', JSON.stringify(command_memory), function(err) { | ||
module.exports.stop = function (quit) { | ||
fs.writeFile(__dirname + '/history.json', JSON.stringify(command_memory), function(err) { | ||
if(err) { | ||
stdout.write("Couldn't save history!"); | ||
} | ||
if(exit) { | ||
if(quit) { | ||
process.exit(); | ||
@@ -246,0 +287,0 @@ } |
{ | ||
"name": "interactive", | ||
"version": "0.1.1", | ||
"version": "0.1.5", | ||
"description": "Togglable interactive mode", | ||
@@ -5,0 +5,0 @@ "main": "interactive.js", |
@@ -6,4 +6,4 @@ interactive | ||
You can start and stop it from any place in your code. | ||
It allows you to interact with your global objects and evaluate new pieces. You can use arrow keys to navigate through commands you ran, even in previous sessions! | ||
Start interactive mode from anywhere in your code! | ||
Interact with your global objects and evaluate new pieces. Use arrow keys to navigate through commands you ran, even in previous sessions! | ||
@@ -20,2 +20,7 @@ **Please note that it switches stdin to rawMode, so if you have any listeners on it, it's best to close them first.** | ||
Have an complicated object you need to set up often? Bored of repeating code? | ||
Try ```:l <filename>``` to run a code snippet from a file! | ||
Filename can be either relative to your project root or absolute. | ||
To quit type ```:q``` | ||
@@ -25,3 +30,9 @@ | ||
test.js | ||
```javascript | ||
console.log('this is output from test.js'); | ||
a = 7; | ||
``` | ||
yourscript.js | ||
```javascript | ||
var interactive = require('interactive'); | ||
@@ -34,2 +45,6 @@ interactive.start('Point 1'); | ||
//undefined | ||
//> :l test.js | ||
//this is output from test.js | ||
//> a | ||
//7 | ||
//> :q | ||
@@ -39,2 +54,3 @@ //Interactive mode off | ||
Licensed under MIT license. Copyright (c) 2014 Adam Paszke |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12339
268
51
2