tuiHoneyPot

front and back end of my TUI honeypot
Log | Files | Refs | README

history.js (1447B)


      1 /**
      2  * The "history" command
      3  * @param  {window.FakeTerminal} instance The instance of FakeTerminal
      4  * @return {Object}
      5  */
      6 window.FakeTerminal.command.history = function (instance) {
      7 
      8     //  Extend the base command
      9     window.FakeTerminal.command.apply(this, arguments);
     10 
     11     /**
     12      * Avoid scope issues by using `base` instead of `this`
     13      * @type {Object}
     14      */
     15     const base = this;
     16 
     17     // --------------------------------------------------------------------------
     18 
     19     /**
     20      * Describes the command
     21      * @return {Object}
     22      */
     23     base.info = function () {
     24         return {
     25             description: 'Displays the command history, up to ' + instance.options.historyLength + ' items'
     26         };
     27     };
     28 
     29     // --------------------------------------------------------------------------
     30 
     31     /**
     32      * Executes the command
     33      * @return {Object} A promise which will be resolved when the command completes
     34      */
     35     base.execute = function () {
     36 
     37         instance.output.write('  ');
     38 
     39         for (var i = 0; i < instance.history.items.length; i++) {
     40             instance.output.write(
     41                 instance.history.items[i].counter + '  ' + instance.history.items[i].command
     42             );
     43         }
     44 
     45         instance.output.write('  ');
     46 
     47         base.deferred.resolve();
     48         return base.deferred.promise();
     49     };
     50 
     51     // --------------------------------------------------------------------------
     52 
     53     return base;
     54 };