interactive
Advanced tools
Comparing version 0.1.0 to 0.1.1
var util = require('util'); | ||
var fs = require('fs'); | ||
var stdin = process.stdin; | ||
@@ -34,3 +35,3 @@ var stdout = process.stdout; | ||
var countindentationation = function (line) { | ||
var countIndentation = function (line) { | ||
var len = line.length; | ||
@@ -57,3 +58,3 @@ for(var i = 0; i < len; i++) { | ||
stdout.write('\n'); | ||
process.exit(); | ||
module.exports.stop(true); | ||
} | ||
@@ -74,8 +75,7 @@ break; | ||
countindentationation(display); | ||
countIndentation(display); | ||
if(display == ':q') { | ||
stdout.write('\n\u001b[37m' + 'Interactive mode off' + '\u001b[0m\n'); | ||
stdin.removeListener('data', processKey); | ||
stdin.setRawMode(false); | ||
stdout.write('\n'); | ||
module.exports.stop(); | ||
break; | ||
@@ -209,22 +209,39 @@ } | ||
module.exports.start = function (name) { | ||
if(name) { | ||
stdout.write('Interactive mode started at: ' + name + '\n'); | ||
} | ||
stdin.setRawMode(true); | ||
stdin.setEncoding('utf8'); | ||
stdout.setEncoding('utf8'); | ||
stdin.resume(); | ||
stdin.on('data', processKey); | ||
command_memory = []; | ||
tmp = ""; | ||
index = 0; | ||
pos = 0; | ||
display = ""; | ||
exit = false; | ||
indentation = 0; | ||
saved = ""; | ||
refreshLine(); | ||
fs.readFile('history.json', { encoding:"utf8" }, function(err, data) { | ||
if(err) { | ||
stdout.write("Couldn't load command history!\n"); | ||
command_memory = []; | ||
index = 0; | ||
} else { | ||
command_memory = JSON.parse(data); | ||
index = command_memory.length; | ||
} | ||
if(name) { | ||
stdout.write('Interactive mode started at: ' + name + '\n'); | ||
} | ||
stdin.setRawMode(true); | ||
stdin.setEncoding('utf8'); | ||
stdout.setEncoding('utf8'); | ||
stdin.resume(); | ||
stdin.on('data', processKey); | ||
tmp = ""; | ||
pos = 0; | ||
display = ""; | ||
exit = false; | ||
indentation = 0; | ||
saved = ""; | ||
refreshLine(); | ||
}); | ||
}; | ||
module.exports.stop = function () { | ||
module.exports.stop = function (exit) { | ||
fs.writeFile('history.json', JSON.stringify(command_memory), function(err) { | ||
if(err) { | ||
stdout.write("Couldn't save history!"); | ||
} | ||
if(exit) { | ||
process.exit(); | ||
} | ||
}); | ||
stdout.write('\u001b[37m' + 'Interactive mode off\n' + '\u001b[0m'); | ||
@@ -231,0 +248,0 @@ stdin.removeListener('data', processKey); |
{ | ||
"name": "interactive", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Togglable interactive mode", | ||
@@ -5,0 +5,0 @@ "main": "interactive.js", |
@@ -7,3 +7,3 @@ 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. | ||
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! | ||
@@ -10,0 +10,0 @@ **Please note that it switches stdin to rawMode, so if you have any listeners on it, it's best to close them first.** |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
10296
229
1