Compare commits

..

No commits in common. "a326c8f6b861eecbed5ae30ea8339e6195f1c448" and "2e033026f0c9f322e0ed3e36bc9b5d0b7fba7192" have entirely different histories.

2 changed files with 9 additions and 43 deletions

View File

@ -1,29 +1,5 @@
import { Terminal } from 'xterm'; const fs = require('fs');
const fs = require('../fs');
/**
*
* @param { string[] } argv
* @param { Terminal } terminal
*/
module.exports = (argv, terminal) => { module.exports = (argv, terminal) => {
if (argv.indexOf('--help') != -1) { terminal.writeln('hi')
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++;
})
})
} }

View File

@ -18,7 +18,6 @@ let dom;
const prompt = '\033[1;32muser@blek.codes \033[36m~ $ \033[0m'; const prompt = '\033[1;32muser@blek.codes \033[36m~ $ \033[0m';
let cmd = ''; let cmd = '';
let lastcmd = '';
function text_prompt() { function text_prompt() {
return prompt.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); return prompt.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
@ -49,30 +48,28 @@ function exec_file(f) {
function exec_cmd() { function exec_cmd() {
let c = cmd; let c = cmd;
const command = c.split(' ')[0];
reset_cmd(c); reset_cmd(c);
lastcmd = c;
if (command == '') { if (c == '') {
print_prompt(); print_prompt();
return; return;
} }
// if path // if path
if (command.match(/^((\.|\.\.)\/|\/).+$/gm)) { if (c.match(/^((\.|\.\.)\/|\/).+$/gm)) {
exec_file(command); exec_file(c);
terminal.writeln(''); terminal.writeln('');
print_prompt(); print_prompt();
return; return;
} }
if (cmds[command] != undefined) { if (cmds[c] != undefined) {
cmds[command](c.split(' '), terminal); cmds[c](c.split(' '), terminal);
print_prompt(); print_prompt();
return; return;
} }
terminal.writeln('zsh: command not found: ' + command); terminal.writeln('zsh: command not found: ' + c);
print_prompt(); print_prompt();
} }
@ -111,13 +108,6 @@ function control_char(id, dom) {
exec_cmd(); exec_cmd();
break; break;
case 38:
if (lastcmd == '') break;
cmd = lastcmd;
reprint_prompt();
terminal.write(lastcmd);
break;
// Ctrl+c // Ctrl+c
case 67: case 67:
if (dom.ctrlKey) { if (dom.ctrlKey) {
@ -145,7 +135,7 @@ function control_char(id, dom) {
function key(e) { function key(e) {
/** @type {KeyboardEvent} */ /** @type {KeyboardEvent} */
const dom = e.domEvent; const dom = e.domEvent;
if (dom.key.length == 1 && !(dom.ctrlKey || dom.altKey)) { if (dom.key.length == 1 && !(dom.ctrlKey || dom.altKey || dom.shiftKey)) {
pr_char(e.domEvent.key); pr_char(e.domEvent.key);
} else { } else {
control_char(e.domEvent.keyCode, dom) control_char(e.domEvent.keyCode, dom)