From ef960d6f6f68c0087b33bdcfcf052416aaa992a1 Mon Sep 17 00:00:00 2001 From: b1ek Date: Thu, 23 Mar 2023 10:09:58 +1000 Subject: [PATCH] add systemctl, exit and echo commands --- src/emulator/commands/echo.js | 36 ++++++++++++++++++++++++++++++ src/emulator/commands/exit.js | 10 +++++++++ src/emulator/commands/index.js | 3 +++ src/emulator/commands/systemctl.js | 10 +++++++++ 4 files changed, 59 insertions(+) create mode 100644 src/emulator/commands/echo.js create mode 100644 src/emulator/commands/exit.js create mode 100644 src/emulator/commands/systemctl.js diff --git a/src/emulator/commands/echo.js b/src/emulator/commands/echo.js new file mode 100644 index 0000000..224fb61 --- /dev/null +++ b/src/emulator/commands/echo.js @@ -0,0 +1,36 @@ +const { Terminal } = require("xterm"); + +/** + * + * @param {string[]} argv + * @param {Terminal} terminal + */ +module.exports = (argv, terminal) => { + if (argv.indexOf('--help') != -1) { + terminal.write( +`Usage: ${argv[0]} [-e] [MESSAGE] +Print a line of text into terminal. + -e \t Enable parsing of backslash escapes` + ); + return; + } + + let args = [...argv]; + args.shift(); + + // remove -e + if (args.indexOf('-e') != -1) + args.splice(args.indexOf('-e'), 1) + + let text = args.join(' '); + + if (argv.indexOf('-e') != -1) { + try { + text = JSON.parse(`"${text}"`); + } catch (err) { + terminal.write(`${argv[0]}: can't parse string: ${err}`); + } + } + + terminal.writeln(text); +} \ No newline at end of file diff --git a/src/emulator/commands/exit.js b/src/emulator/commands/exit.js new file mode 100644 index 0000000..02a8344 --- /dev/null +++ b/src/emulator/commands/exit.js @@ -0,0 +1,10 @@ +const { Terminal } = require("xterm"); + +/** + * + * @param {string[]} argv + * @param {Terminal} terminal + */ +module.exports = (argv, terminal) => { + terminal.writeln(`${argv[0]}: not supported`); +} \ No newline at end of file diff --git a/src/emulator/commands/index.js b/src/emulator/commands/index.js index afcc3fa..ff0c3e8 100644 --- a/src/emulator/commands/index.js +++ b/src/emulator/commands/index.js @@ -12,6 +12,9 @@ let cmds = { 'ps': require('./ps'), 'clear': require('./clear'), 'rm': require('./rm'), + 'echo': require('./echo'), + 'exit': require('./exit'), + 'systemctl': require('./systemctl'), 'guide': require('./guide'), diff --git a/src/emulator/commands/systemctl.js b/src/emulator/commands/systemctl.js new file mode 100644 index 0000000..0ae1048 --- /dev/null +++ b/src/emulator/commands/systemctl.js @@ -0,0 +1,10 @@ +const { Terminal } = require("xterm"); + +/** + * + * @param {string[]} argv + * @param {Terminal} terminal + */ +module.exports = (argv, terminal) => { + terminal.writeln(`${argv[0]}: systemd is bad`); +} \ No newline at end of file