Socket
Socket
Sign inDemoInstall

interactive

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interactive - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

65

interactive.js
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.**

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc