From 361dffd818245f32e997fc2eb9f144385a2e68ff Mon Sep 17 00:00:00 2001 From: Jos van Bakel Date: Wed, 24 May 2017 15:07:09 +0200 Subject: [PATCH] Fixed wrong ignore of livescript/node_readline.js --- .gitignore | 2 ++ livescript/node_readline.js | 47 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 livescript/node_readline.js diff --git a/.gitignore b/.gitignore index a7f1a11b..354278e9 100644 --- a/.gitignore +++ b/.gitignore @@ -125,3 +125,5 @@ common-lisp/*.lib common-lisp/images/* common-lisp/hist/* livescript/*.js +!livescript/node_readline.js +livescript/node_modules diff --git a/livescript/node_readline.js b/livescript/node_readline.js new file mode 100644 index 00000000..e59a62bd --- /dev/null +++ b/livescript/node_readline.js @@ -0,0 +1,47 @@ +// IMPORTANT: choose one +var RL_LIB = "libreadline"; // NOTE: libreadline is GPL +//var RL_LIB = "libedit"; + +var HISTORY_FILE = require('path').join(process.env.HOME, '.mal-history'); + +var rlwrap = {}; // namespace for this module in web context + +var ffi = require('ffi'), + fs = require('fs'); + +var rllib = ffi.Library(RL_LIB, { + 'readline': [ 'string', [ 'string' ] ], + 'add_history': [ 'int', [ 'string' ] ]}); + +var rl_history_loaded = false; + +exports.readline = rlwrap.readline = function(prompt) { + prompt = typeof prompt !== 'undefined' ? prompt : "user> "; + + if (!rl_history_loaded) { + rl_history_loaded = true; + var lines = []; + if (fs.existsSync(HISTORY_FILE)) { + lines = fs.readFileSync(HISTORY_FILE).toString().split("\n"); + } + // Max of 2000 lines + lines = lines.slice(Math.max(lines.length - 2000, 0)); + for (var i=0; i