From 07d1631d9d8731d4499babd7f8b706c71b42c221 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 19 Feb 2017 12:59:02 -0500 Subject: [PATCH] move command history to its own module --- lib/dashboard/command_history.js | 28 ++++++++++++++++++++++++++++ lib/dashboard/monitor.js | 27 +-------------------------- 2 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 lib/dashboard/command_history.js diff --git a/lib/dashboard/command_history.js b/lib/dashboard/command_history.js new file mode 100644 index 000000000..43e1d2d9d --- /dev/null +++ b/lib/dashboard/command_history.js @@ -0,0 +1,28 @@ + +var CommandHistory = function() { + this.history = []; + this.pointer = -1; +}; + +CommandHistory.prototype.addCommand = function(cmd) { + this.history.push(cmd); + this.pointer = this.history.length; +}; + +CommandHistory.prototype.getPreviousCommand = function(cmd) { + if (this.pointer >= 0) { + this.pointer--; + } + return this.history[this.pointer]; +}; + +CommandHistory.prototype.getNextCommand = function(cmd) { + if (this.pointer >= this.history.length) { + this.pointer = this.history.length - 1; + return ''; + } + this.pointer++; + return this.history[this.pointer]; +}; + +module.exports = CommandHistory; diff --git a/lib/dashboard/monitor.js b/lib/dashboard/monitor.js index cf7626d49..9ab036353 100644 --- a/lib/dashboard/monitor.js +++ b/lib/dashboard/monitor.js @@ -1,32 +1,7 @@ /*jshint esversion: 6 */ var blessed = require("blessed"); - -var CommandHistory = function() { - this.history = []; - this.pointer = -1; -}; - -CommandHistory.prototype.addCommand = function(cmd) { - this.history.push(cmd); - this.pointer = this.history.length; -}; - -CommandHistory.prototype.getPreviousCommand = function(cmd) { - if (this.pointer >= 0) { - this.pointer--; - } - return this.history[this.pointer]; -}; - -CommandHistory.prototype.getNextCommand = function(cmd) { - if (this.pointer >= this.history.length) { - this.pointer = this.history.length - 1; - return ''; - } - this.pointer++; - return this.history[this.pointer]; -}; +var CommandHistory = require('./command_history.js'); function Dashboard(options) { var title = (options && options.title) || "Embark 2.3.0";