mirror of
https://github.com/MeexReay/poshlostios.git
synced 2025-06-24 18:42:59 +03:00
first kfc version and getTerminalSize
This commit is contained in:
parent
373e7307c4
commit
4842b99002
31
app/kfc/kfc.js
Normal file
31
app/kfc/kfc.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
async function main(args) {
|
||||||
|
if (args.length != 2) {
|
||||||
|
writeStdout(`Usage: kfc <file>\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
|
||||||
|
}
|
8
app/kfc/package.json
Normal file
8
app/kfc/package.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "kfc",
|
||||||
|
"version": "0.0.1-test",
|
||||||
|
"description": "Keep Files Customized",
|
||||||
|
"author": "MeexReay",
|
||||||
|
"apps": [ "kfc.js" ],
|
||||||
|
"configs": []
|
||||||
|
}
|
@ -158,6 +158,7 @@ async function main(args) {
|
|||||||
updateCursor() - обновить курсор
|
updateCursor() - обновить курсор
|
||||||
getCursorIndex() -> index - получить индекс курсора в тексте терминала
|
getCursorIndex() -> index - получить индекс курсора в тексте терминала
|
||||||
getCursor() -> [x, y] - получить курсор
|
getCursor() -> [x, y] - получить курсор
|
||||||
|
getTerminalSize() -> [width, height] - получить ширину высоту терминала в символах
|
||||||
|
|
||||||
`)
|
`)
|
||||||
return 0
|
return 0
|
||||||
|
@ -5,6 +5,13 @@ var terminal = document.getElementById("terminal")
|
|||||||
var terminal_text = ""
|
var terminal_text = ""
|
||||||
var last_stdin_length = 0
|
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) {
|
function writeTerminalAtCursor(content) {
|
||||||
let cursor_index = getCursorIndex()
|
let cursor_index = getCursorIndex()
|
||||||
terminal_text = terminal_text.slice(0, cursor_index) + content + terminal_text.slice(cursor_index)
|
terminal_text = terminal_text.slice(0, cursor_index) + content + terminal_text.slice(cursor_index)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user