From 4842b99002312b7a355df8d1f5037c6183faf544 Mon Sep 17 00:00:00 2001 From: MeexReay Date: Fri, 21 Mar 2025 17:27:36 +0300 Subject: [PATCH] first kfc version and getTerminalSize --- app/kfc/kfc.js | 31 +++++++++++++++++++++++++++++++ app/kfc/package.json | 8 ++++++++ app/woman/woman.js | 1 + sys/terminal.js | 7 +++++++ 4 files changed, 47 insertions(+) create mode 100644 app/kfc/kfc.js create mode 100644 app/kfc/package.json diff --git a/app/kfc/kfc.js b/app/kfc/kfc.js new file mode 100644 index 0000000..3aef136 --- /dev/null +++ b/app/kfc/kfc.js @@ -0,0 +1,31 @@ + +async function main(args) { + if (args.length != 2) { + writeStdout(`Usage: kfc \n`) + return 1 + } + + let content = readFile(args[1]) + + let pos = getCursor() + + setStdinFlag(SILENT_STDIN) + + while (true) { + let event = await pollStdinEvent() + + if (event.type == "key") { + if (event.key == "Escape") { + break + } + + writeStdout(event.key + "\n") + } else if (event.type == "char") { + writeStdout(event.char + "\n") + } + } + + setStdinFlag(RENDER_STDIN) + + return 0 +} \ No newline at end of file diff --git a/app/kfc/package.json b/app/kfc/package.json new file mode 100644 index 0000000..825e424 --- /dev/null +++ b/app/kfc/package.json @@ -0,0 +1,8 @@ +{ + "name": "kfc", + "version": "0.0.1-test", + "description": "Keep Files Customized", + "author": "MeexReay", + "apps": [ "kfc.js" ], + "configs": [] +} \ No newline at end of file diff --git a/app/woman/woman.js b/app/woman/woman.js index 69ce7cd..ba32be4 100644 --- a/app/woman/woman.js +++ b/app/woman/woman.js @@ -158,6 +158,7 @@ async function main(args) { updateCursor() - обновить курсор getCursorIndex() -> index - получить индекс курсора в тексте терминала getCursor() -> [x, y] - получить курсор + getTerminalSize() -> [width, height] - получить ширину высоту терминала в символах `) return 0 diff --git a/sys/terminal.js b/sys/terminal.js index c2cacec..a5d3cc3 100644 --- a/sys/terminal.js +++ b/sys/terminal.js @@ -5,6 +5,13 @@ var terminal = document.getElementById("terminal") var terminal_text = "" var last_stdin_length = 0 +function getTerminalSize() { + return [ + Math.floor(window.innerWidth - CURSOR_OFFSET[0] * 2 / CHAR_SIZE[0]), + Math.floor(window.innerHeight - CURSOR_OFFSET[1] * 2 / CHAR_SIZE[1]) + ] +} + function writeTerminalAtCursor(content) { let cursor_index = getCursorIndex() terminal_text = terminal_text.slice(0, cursor_index) + content + terminal_text.slice(cursor_index)