Compare commits
No commits in common. "a326c8f6b861eecbed5ae30ea8339e6195f1c448" and "2e033026f0c9f322e0ed3e36bc9b5d0b7fba7192" have entirely different histories.
a326c8f6b8
...
2e033026f0
|
@ -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) => {
|
||||
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++;
|
||||
})
|
||||
})
|
||||
terminal.writeln('hi')
|
||||
}
|
|
@ -18,7 +18,6 @@ let dom;
|
|||
|
||||
const prompt = '\033[1;32muser@blek.codes \033[36m~ $ \033[0m';
|
||||
let cmd = '';
|
||||
let lastcmd = '';
|
||||
|
||||
function text_prompt() {
|
||||
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() {
|
||||
let c = cmd;
|
||||
const command = c.split(' ')[0];
|
||||
reset_cmd(c);
|
||||
lastcmd = c;
|
||||
|
||||
if (command == '') {
|
||||
if (c == '') {
|
||||
print_prompt();
|
||||
return;
|
||||
}
|
||||
|
||||
// if path
|
||||
if (command.match(/^((\.|\.\.)\/|\/).+$/gm)) {
|
||||
exec_file(command);
|
||||
if (c.match(/^((\.|\.\.)\/|\/).+$/gm)) {
|
||||
exec_file(c);
|
||||
terminal.writeln('');
|
||||
print_prompt();
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmds[command] != undefined) {
|
||||
cmds[command](c.split(' '), terminal);
|
||||
if (cmds[c] != undefined) {
|
||||
cmds[c](c.split(' '), terminal);
|
||||
print_prompt();
|
||||
return;
|
||||
}
|
||||
|
||||
terminal.writeln('zsh: command not found: ' + command);
|
||||
terminal.writeln('zsh: command not found: ' + c);
|
||||
print_prompt();
|
||||
}
|
||||
|
||||
|
@ -111,13 +108,6 @@ function control_char(id, dom) {
|
|||
exec_cmd();
|
||||
break;
|
||||
|
||||
case 38:
|
||||
if (lastcmd == '') break;
|
||||
cmd = lastcmd;
|
||||
reprint_prompt();
|
||||
terminal.write(lastcmd);
|
||||
break;
|
||||
|
||||
// Ctrl+c
|
||||
case 67:
|
||||
if (dom.ctrlKey) {
|
||||
|
@ -145,7 +135,7 @@ function control_char(id, dom) {
|
|||
function key(e) {
|
||||
/** @type {KeyboardEvent} */
|
||||
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);
|
||||
} else {
|
||||
control_char(e.domEvent.keyCode, dom)
|
||||
|
|
Loading…
Reference in New Issue