This commit is contained in:
b1ek 2023-03-15 16:13:14 +10:00
parent 2e033026f0
commit 57b5fa7e8d
Signed by: blek
GPG Key ID: 14546221E3595D0C
1 changed files with 26 additions and 2 deletions

View File

@ -1,5 +1,29 @@
const fs = require('fs');
import { Terminal } from 'xterm';
const fs = require('../fs');
/**
*
* @param { string[] } argv
* @param { Terminal } terminal
*/
module.exports = (argv, terminal) => {
terminal.writeln('hi')
if (argv.indexOf('--help') != -1) {
terminal.writeln('Usage: cat [file] [-n]');
terminal.writeln(' -n --number: show lines numbers');
terminal.writeln(' --help: show this help');
return;
}
const numbers = (argv.indexOf('-n') != -1) || (argv.indexOf('--number') != -1);
let files = argv.filter(x => { return !x.startsWith('-') });
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++;
})
})
}