Ctrl+backspace, register clipboard

This commit is contained in:
b1ek 2023-03-17 16:08:49 +10:00
parent 747b94f103
commit 34aaa678b1
Signed by: blek
GPG Key ID: 14546221E3595D0C
3 changed files with 48 additions and 15 deletions

View File

@ -20,6 +20,7 @@
},
"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

@ -3,7 +3,9 @@ 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

@ -24,7 +24,14 @@ function text_prompt() {
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;
terminal.write(char);
}
@ -99,20 +106,41 @@ 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();
backspace(dom.ctrlKey);
break;
// enter
@ -135,11 +163,9 @@ function control_char(id, dom) {
print_prompt();
break;
}
case 37:
backspace();
break;
case 86:
if (dom.altKey) break;
default:
if (dom.ctrlKey && (dom.key.length == 1)) {
@ -160,16 +186,20 @@ function key(e) {
/** @type {KeyboardEvent} */
const dom = e.domEvent;
if (dom.key.length == 1 && !(dom.ctrlKey || dom.altKey)) {
pr_char(e.domEvent.key);
pr_char(e.domEvent.key, dom);
} else {
control_char(e.domEvent.keyCode, dom)
}
}
module.exports = (t, d) => {
function register(t, d) {
terminal = t;
dom = d;
terminal.onKey(key);
terminal.write(prompt);
}
}
register.pr_char = pr_char;
module.exports = register;