diff --git a/react/resume/src/emulator/commands/cat.js b/react/resume/src/emulator/commands/cat.js index 7776f4d..e330cc0 100644 --- a/react/resume/src/emulator/commands/cat.js +++ b/react/resume/src/emulator/commands/cat.js @@ -9,9 +9,9 @@ const fs = require('../fs'); module.exports = (argv, terminal) => { if (argv.indexOf('--help') != -1) { terminal.writeln(`Usage: ${argv[0]} [files] [-n]`); - terminal.writeln(' -n --number: show lines numbers'); - terminal.writeln(' --help: show this help'); - terminal.writeln('Reads file into stdout'); + terminal.writeln(' -n --number show lines numbers'); + terminal.writeln(' --help show this help'); + terminal.writeln('Read files into stdout'); return; } const numbers = (argv.indexOf('-n') != -1) || (argv.indexOf('--number') != -1); @@ -20,11 +20,16 @@ module.exports = (argv, terminal) => { files.shift(); files.forEach(file => { const lines = fs.readFileSync(file).toString().split('\n'); - let i = 1; - lines.forEach(line => { - if (numbers) terminal.write('\033[35m' + i + ' |\033[0m '); - terminal.writeln(line); - i++; - }) + + if (numbers) { + lines.forEach((line, i) => { + terminal.write('\033[35m' + i + ' |\033[0m '); + }) + } else { + terminal.write(file); + /// print % if no newline at eof + if (lines[lines.length - 1] != '') + terminal.write('\033[30;47m%\033[0m\n'); + } }) } \ No newline at end of file diff --git a/react/resume/src/emulator/commands/ls.js b/react/resume/src/emulator/commands/ls.js new file mode 100644 index 0000000..1d57180 --- /dev/null +++ b/react/resume/src/emulator/commands/ls.js @@ -0,0 +1,60 @@ +const { Terminal } = require('xterm'); +const fs = require('../fs'); + +/** + * + * @param {string[]} argv + * @param {Terminal} terminal + */ +module.exports = (argv, terminal) => { + if (argv.indexOf('--help') != -1) { + terminal.writeln(`Usage: ${argv[0]} [dirs] [-a|--all] [-l]`); + terminal.writeln('Lists files in directories'); + terminal.writeln(' -a --all List all files (including those who start with .)'); + terminal.writeln(' -l Use long listing format'); + return; + } + + const has_arg = (arg) => {return argv.indexOf(arg) != -1}; + + let directories = [...argv]; + + const all = (has_arg('-a') || has_arg('--all')); + const long_format = has_arg('-l'); + + directories.shift(); + + // remove .* files if -a not specified + if (!all) + directories = directories.filter(x => x.startsWith('.')); + + // remove arguments + directories = directories.filter(x => !x.startsWith('-')); + + if (directories.length == 0) directories = ['.']; + + // remove dublicates + directories = [...new Set(directories)]; + + directories.forEach((dir, i) => { + + if (directories.length != 1) { + terminal.writeln(dir + ':'); + terminal.writeln(''); + } + + let files = fs.readdirSync(dir); + files.forEach((file, i) => { + + if (!fs.accessSync(file, fs.constants.X_OK)) + terminal.write('\033[1;32m'); + if (fs.accessSync(file, fs.constants.R_OK)) + terminal.write('\033[35m'); + + terminal.write(file + '\033[0m '); + if ((i+1) % 5 == 0) + terminal.writeln(''); + }); + terminal.writeln(''); + }) +} \ No newline at end of file diff --git a/react/resume/src/emulator/commands/skills.js b/react/resume/src/emulator/commands/skills.js new file mode 100644 index 0000000..734acdd --- /dev/null +++ b/react/resume/src/emulator/commands/skills.js @@ -0,0 +1,3 @@ +module.exports = (argv, terminal) => { + terminal.write('uwu\nowo\n'); +} \ No newline at end of file