Merge pull request 'fix: pasting in prompt no worky' (#12) from 1.0.2 into main
All checks were successful
Create Version Tag / version-check (push) Successful in 22s
Create Version Tag / build-release (push) Successful in 3m54s
Create Version Tag / publish-release (push) Successful in 36s

Reviewed-on: #12
This commit is contained in:
Emmaline Autumn 2025-05-21 11:13:06 -07:00
commit cca6de1877
2 changed files with 43 additions and 25 deletions

View File

@ -43,41 +43,59 @@ export async function cliPrompt(
render(); render();
const buf = new Uint8Array(6); // 6 bytes is enough for all the keys const buf = new Uint8Array(64); // large enough for most pastes
while (true) { while (true) {
const n = await Deno.stdin.read(buf); const n = await Deno.stdin.read(buf);
if (n === null) break; if (n === null) break;
const [a, b, c] = buf;
if (a === 3) { // Ctrl+C for (let i = 0; i < n; i++) {
const byte = buf[i];
// Ctrl+C
if (byte === 3) {
block?.clear(); block?.clear();
block?.["layout"]?.clearAll(); block?.["layout"]?.clearAll();
Deno.stdin.setRaw(false); await Deno.stdin.setRaw(false);
Deno.exit(130); Deno.exit(130);
} }
if (a === 13) { // Enter // Escape sequence?
break; if (byte === 27 && i + 1 < n && buf[i + 1] === 91) {
} else if (a === 127 || a === 8) { // Backspace const third = buf[i + 2];
if (third === 68 && cursorPos > 0) cursorPos--; // Left
else if (third === 67 && cursorPos < input.length) cursorPos++; // Right
else if (third === 51 && i + 3 < n && buf[i + 3] === 126) { // Delete
if (cursorPos < input.length) input.splice(cursorPos, 1);
i += 1; // consume tilde
}
i += 2; // consume ESC [ X
continue;
}
// Backspace
if (byte === 127 || byte === 8) {
if (cursorPos > 0) { if (cursorPos > 0) {
input.splice(cursorPos - 1, 1); input.splice(cursorPos - 1, 1);
cursorPos--; cursorPos--;
} }
} else if (a === 46) { // Delete continue;
if (cursorPos < input.length) {
input.splice(cursorPos, 1);
} }
} else if (a === 27 && b === 91) { // Arrow keys
if (c === 51 && cursorPos < input.length) { // delete // Delete (ASCII 46)
if (byte === 46 && cursorPos < input.length) {
input.splice(cursorPos, 1); input.splice(cursorPos, 1);
continue;
} }
if (c === 68 && cursorPos > 0) cursorPos--; // Left
if (c === 67 && cursorPos < input.length) cursorPos++; // Right // Printable
} else if (a >= 32 && a <= 126) { // Printable ASCII if (byte >= 32 && byte <= 126) {
input.splice(cursorPos, 0, String.fromCharCode(a)); input.splice(cursorPos, 0, String.fromCharCode(byte));
cursorPos++; cursorPos++;
} }
// Other cases: ignore
}
render(); render();
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@bearmetal/pdf-tools", "name": "@bearmetal/pdf-tools",
"version": "1.0.4", "version": "1.0.5",
"license": "GPL 3.0", "license": "GPL 3.0",
"tasks": { "tasks": {
"dev": "deno run -A --env-file=.env main.ts", "dev": "deno run -A --env-file=.env main.ts",