Compare commits

..

No commits in common. "b41f37efa7fe39bed93eb392bc63b1a96ee3a051" and "589fd08c611968d0fc2e771a69ffaa6ab6efb267" have entirely different histories.

6 changed files with 25 additions and 111 deletions

View File

@ -20,7 +20,6 @@
},
"dependencies": {
"@parcel/fs": "^2.8.3",
"copy-to-clipboard": "^3.3.3",
"memfs": "^3.4.13",
"react": "^18.2.0",
"react-dom": "^18.2.0",

View File

@ -19,10 +19,6 @@ module.exports = (argv, terminal) => {
let files = argv.filter(x => { return !x.startsWith('-') });
files.shift();
files.forEach(file => {
if (!fs.existsSync(file)) {
terminal.writeln(`${argv[0]}: ${file}: no such file or directory`);
return;
}
const lines = fs.readFileSync(file).toString().split('\n');
if (numbers) {

View File

@ -26,7 +26,8 @@ Usage: ${argv[0]} [URL] [-O out.file] [-V] [-Q] [-s]
terminal.writeln(`${argv[0]}: missing output file`);
return;
}
filepath = argv[argv.indexOf('-O') + 1];
filepath = argv[argv.indexOf('-O') + 1]
return;
}
function progress(p) {
@ -34,15 +35,11 @@ Usage: ${argv[0]} [URL] [-O out.file] [-V] [-Q] [-s]
if (total == 0)
total = '?'
// terminal.write(`\rDownloading... ${p.loaded}/${total}`);
terminal.write(`\rDownloading... ${p.loaded}/${total}`);
}
function write(file) {
if (filepath == '-') {
terminal.write(file);
} else {
fs.writeFileSync(filepath, file);
}
}
let file;
@ -53,7 +50,8 @@ Usage: ${argv[0]} [URL] [-O out.file] [-V] [-Q] [-s]
req.onprogress = progress;
req.onload = (e) => {
if (e.type == 'load') {
write(e.response);
let enc = new TextDecoder("utf-8");
terminal.write(enc.decode(req.response));
}
};
req.send();

View File

@ -3,9 +3,7 @@ module.exports = (dom) => {
terminal.writeln('Welcome to my online resume!')
terminal.writeln('Type \033[1;32mhelp\033[0m for list of commands')
terminal.writeln('Use \033[1;33mAlt+C/V\033[0m to copy or paste');
terminal.writeln('');
require('./zsh')(terminal, dom);
require('./pastebuffer')(terminal, dom);
}

View File

@ -1,37 +0,0 @@
import { Terminal } from "xterm"
import copy from 'copy-to-clipboard';
/** @type { Terminal } */
let terminal;
const zsh = require('./zsh');
/**
*
* @param {{ key: string, domEvent: KeyboardEvent }} e
*/
async function keyHandler(e) {
const dom = e.domEvent;
if (!dom.altKey)
return;
if (dom.key.length != 1)
return;
switch (dom.key.toLowerCase()) {
case 'c':
if (!terminal.hasSelection()) break;
copy(terminal.getSelection())
break;
case 'v':
zsh.pr_char(prompt("Paste your text:"), {key: 'a'})
}
}
module.exports = (t, d) => {
terminal = t;
terminal.onKey(keyHandler);
}

View File

@ -7,7 +7,7 @@ global.fs = fs;
const cmds = require('./commands');
/**
* @type { Terminal }
* @type {Terminal}
*/
let terminal;
@ -24,14 +24,7 @@ function text_prompt() {
return prompt.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
}
/**
*
* @param { string } char
* @param { KeyboardEvent } dom
*/
function pr_char(char, dom) {
if (dom.key.length != 1) return;
function pr_char(char) {
cmd += char;
terminal.write(char);
}
@ -54,7 +47,7 @@ function exec_file(f) {
return;
}
async function exec_cmd() {
function exec_cmd() {
let c = cmd;
const command = c.split(' ')[0];
reset_cmd(c);
@ -75,13 +68,8 @@ async function exec_cmd() {
}
if (cmds[command] != undefined) {
const startY = terminal.buffer.normal.cursorY
await cmds[command](c.split(' '), terminal);
await (new Promise(resolve => setTimeout(resolve, 10)));
if (terminal.buffer.active.cursorX != 0 && startY != terminal.buffer.active.cursorY) {
cmds[command](c.split(' '), terminal);
if (terminal.buffer.active.cursorX != 0) {
terminal.write('\033[30;47m%\033[0m\n');
}
print_prompt();
@ -106,41 +94,20 @@ function reset_cmd() {
terminal.writeln('');
}
function cbackspace() {
let exploded = cmd.split(' ');
if (exploded.length >= 1) {
reprint_prompt();
cmd = '';
return;
}
exploded.pop();
cmd = exploded.join(' ') + ' ';
reprint_prompt();
terminal.write(cmd);
return;
}
function backspace(isCtrl) {
if (terminal.buffer.active.cursorX <= text_prompt().length) return;
if (isCtrl) {
return cbackspace();
}
terminal.write('\b \b');
cmd = cmd.substring(0, cmd.length - 1);
}
/** @param { KeyboardEvent } dom */
function control_char(id, dom) {
const backspace = () => {
if (terminal.buffer.active.cursorX <= text_prompt().length) return;
terminal.write('\b \b');
cmd = cmd.substring(0, cmd.length - 1);
}
switch (id) {
// backspace
case 8:
backspace(dom.ctrlKey);
backspace();
break;
// enter
@ -164,15 +131,12 @@ function control_char(id, dom) {
break;
}
case 86:
if (dom.altKey) break;
case 37:
backspace();
break;
default:
if (dom.ctrlKey && (dom.key.length == 1)) {
terminal.write('^' + dom.key.toUpperCase());
break;
}
terminal.write('<');
if (dom.ctrlKey) terminal.write('C');
if (dom.altKey) terminal.write('A');
@ -186,20 +150,16 @@ function key(e) {
/** @type {KeyboardEvent} */
const dom = e.domEvent;
if (dom.key.length == 1 && !(dom.ctrlKey || dom.altKey)) {
pr_char(e.domEvent.key, dom);
pr_char(e.domEvent.key);
} else {
control_char(e.domEvent.keyCode, dom)
}
}
function register(t, d) {
module.exports = (t, d) => {
terminal = t;
dom = d;
terminal.onKey(key);
terminal.write(prompt);
}
register.pr_char = pr_char;
module.exports = register;