From 2528c0e3569b74247dd3161c7ac9b9109d4dceda Mon Sep 17 00:00:00 2001 From: b1ek Date: Wed, 15 Mar 2023 16:23:05 +1000 Subject: [PATCH] add cmd list --- react/resume/src/emulator/commands/cmds.js | 25 +++++++++++++++++++++ react/resume/src/emulator/commands/index.js | 5 ++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 react/resume/src/emulator/commands/cmds.js diff --git a/react/resume/src/emulator/commands/cmds.js b/react/resume/src/emulator/commands/cmds.js new file mode 100644 index 0000000..7fbbd63 --- /dev/null +++ b/react/resume/src/emulator/commands/cmds.js @@ -0,0 +1,25 @@ +import { Terminal } from 'xterm'; + +/** + * + * @param {string[]} argv + * @param {Terminal} terminal + */ +module.exports = (argv, terminal) => { + if (argv.indexOf('--help') != -1) { + terminal.writeln(`Usage: ${argv[0]} [--help]`); + terminal.writeln('Lists all available commands.'); + return; + } + const cmds = Object.keys(require('../commands')); + let i = 0; + cmds.forEach(x => { + if (x == argv[0]) return; + if (i == 4) { + terminal.writeln(''); + i = 0; + } else i++; + terminal.write('\033[1;32m' + x + '\033[0m '); + }); + terminal.writeln(''); +} \ No newline at end of file diff --git a/react/resume/src/emulator/commands/index.js b/react/resume/src/emulator/commands/index.js index 220c4e4..cac6f31 100644 --- a/react/resume/src/emulator/commands/index.js +++ b/react/resume/src/emulator/commands/index.js @@ -1,5 +1,8 @@ let cmds = { - 'cat': require('./cat') + 'cat': require('./cat'), + 'cmds': require('./cmds'), + 'cmdls': require('./cmds'), + 'help': require('./cmds') }; module.exports = cmds; \ No newline at end of file