echo.js (1627B)
1 /** 2 * The "echo" command 3 * @param {window.FakeTerminal} instance The instance of FakeTerminal 4 * @return {Object} 5 */ 6 window.FakeTerminal.command.echo = 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: 'Writes an argument to the standard output' 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 const args = $.makeArray(arguments); 38 let returnVal; 39 40 // Merge all the arguments 41 returnVal = args.join(' '); 42 returnVal = $.trim(returnVal); 43 44 // Remove quotes 45 returnVal = returnVal.replace(/["']/g, ''); 46 returnVal = returnVal.replace(/["']/g, ''); 47 48 // Ensure we write *something* to the screen 49 if (returnVal.length === 0) { 50 returnVal = ' '; 51 } 52 53 // Write to the terminal 54 instance.output.write(returnVal); 55 56 base.deferred.resolve(); 57 return base.deferred.promise(); 58 }; 59 60 // -------------------------------------------------------------------------- 61 62 return base; 63 };