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": { "dependencies": {
"@parcel/fs": "^2.8.3", "@parcel/fs": "^2.8.3",
"copy-to-clipboard": "^3.3.3",
"memfs": "^3.4.13", "memfs": "^3.4.13",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^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('-') }); let files = argv.filter(x => { return !x.startsWith('-') });
files.shift(); files.shift();
files.forEach(file => { 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'); const lines = fs.readFileSync(file).toString().split('\n');
if (numbers) { 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`); terminal.writeln(`${argv[0]}: missing output file`);
return; return;
} }
filepath = argv[argv.indexOf('-O') + 1]; filepath = argv[argv.indexOf('-O') + 1]
return;
} }
function progress(p) { function progress(p) {
@ -34,15 +35,11 @@ Usage: ${argv[0]} [URL] [-O out.file] [-V] [-Q] [-s]
if (total == 0) if (total == 0)
total = '?' total = '?'
// terminal.write(`\rDownloading... ${p.loaded}/${total}`); terminal.write(`\rDownloading... ${p.loaded}/${total}`);
} }
function write(file) { function write(file) {
if (filepath == '-') {
terminal.write(file);
} else {
fs.writeFileSync(filepath, file);
}
} }
let file; let file;
@ -53,7 +50,8 @@ Usage: ${argv[0]} [URL] [-O out.file] [-V] [-Q] [-s]
req.onprogress = progress; req.onprogress = progress;
req.onload = (e) => { req.onload = (e) => {
if (e.type == 'load') { if (e.type == 'load') {
write(e.response); let enc = new TextDecoder("utf-8");
terminal.write(enc.decode(req.response));
} }
}; };
req.send(); req.send();

View File

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