mirror of
https://github.com/MeexReay/poshlostios.git
synced 2025-06-24 02:22:58 +03:00
make zterm working
This commit is contained in:
parent
7560e4d7af
commit
8448d5d20a
@ -20,8 +20,8 @@ async function drawWindowDecorations(ctx, x, y, width, height, title) {
|
||||
|
||||
const outerX = x - borderWidth - 1;
|
||||
const outerY = y - headerHeight - borderWidth - 2;
|
||||
const outerWidth = width + borderWidth * 2 + 1;
|
||||
const outerHeight = height + headerHeight + borderWidth * 2 + 2;
|
||||
const outerWidth = width + borderWidth * 2 + 2;
|
||||
const outerHeight = height + headerHeight + borderWidth * 2 + 3;
|
||||
|
||||
ctx.fillStyle = "#f4f4f4";
|
||||
ctx.fillRect(outerX, outerY, outerWidth, outerHeight)
|
||||
|
@ -1,21 +1,88 @@
|
||||
eval(readFile("/app/zcom.js"))
|
||||
|
||||
var text = ""
|
||||
let text = ""
|
||||
let stdin_text = ""
|
||||
let stdin_visible = true
|
||||
let stdin_disable = true
|
||||
|
||||
async function draw(ctx) {
|
||||
ctx.fillStyle = "cyan"
|
||||
ctx.fillStyle = "black"
|
||||
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height)
|
||||
|
||||
ctx.fillStyle = "#222";
|
||||
ctx.font = "bold 14px sans-serif";
|
||||
let y = 500 - 12
|
||||
for (let line of text.split("\n").reverse()) {
|
||||
ctx.fillStyle = "white";
|
||||
ctx.font = "bold 14px terminus";
|
||||
ctx.textBaseline = "middle";
|
||||
ctx.textAlign = "left";
|
||||
ctx.fillText(text, 10, 10);
|
||||
ctx.fillText(line, 5, y);
|
||||
y -= 18
|
||||
}
|
||||
}
|
||||
function setStdinFlag(flag) {
|
||||
if (flag == SILENT_STDIN) {
|
||||
stdin_visible = false
|
||||
} else if (flag == RENDER_STDIN) {
|
||||
stdin_visible = true
|
||||
} else if (flag == DISABLE_STDIN) {
|
||||
stdin_disable = true
|
||||
} else if (flag == ENABLE_STDIN) {
|
||||
stdin_disable = false
|
||||
}
|
||||
}
|
||||
|
||||
async function readStdin() {
|
||||
while (stdin_text.length == 0) {
|
||||
await new Promise(resolve => setTimeout(resolve, 10))
|
||||
}
|
||||
let was_stdin = stdin_text.charAt(0)
|
||||
stdin_text = stdin_text.slice(1)
|
||||
return was_stdin
|
||||
}
|
||||
|
||||
async function writeStdout(wh) {
|
||||
text += wh
|
||||
}
|
||||
|
||||
let altKey = false
|
||||
let ctrlKey = false
|
||||
let shiftKey = false
|
||||
|
||||
async function onKeyDown(key) {
|
||||
console.log(key)
|
||||
if (!stdin_disable) {
|
||||
if (key == "Enter") {
|
||||
stdin_text += "\n"
|
||||
if (stdin_visible) {
|
||||
text += "\n"
|
||||
}
|
||||
} else if (key.length == 1) {
|
||||
if (key == "\0") return
|
||||
if (stdin_visible) {
|
||||
text += key
|
||||
}
|
||||
stdin_text += key
|
||||
} else if (key == "Alt") {
|
||||
altKey = true
|
||||
} else if (key == "Shift") {
|
||||
shiftKey = true
|
||||
} else if (key == "Control") {
|
||||
ctrlKey = true
|
||||
} else {
|
||||
stdin_text += "\r"+(ctrlKey ? "1" : "0")+(altKey ? "1" : "0")+(shiftKey ? "1" : "0")+key+"\r"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function onKeyUp(key) {
|
||||
if (key == "Alt") {
|
||||
altKey = false
|
||||
} else if (key == "Shift") {
|
||||
shiftKey = false
|
||||
} else if (key == "Control") {
|
||||
ctrlKey = false
|
||||
}
|
||||
}
|
||||
|
||||
async function main(args) {
|
||||
let wid, ctx = createWindow({
|
||||
@ -24,7 +91,12 @@ async function main(args) {
|
||||
"height": 500,
|
||||
"x": 50,
|
||||
"y": 50,
|
||||
"onkeydown": onKeyDown
|
||||
"onkeydown": onKeyDown,
|
||||
"onkeyup": onKeyUp
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
executeCommand(["/app/posh.js"], readStdin, writeStdout, setStdinFlag)
|
||||
})
|
||||
|
||||
while (graphics_canvas != null) {
|
||||
|
@ -25,7 +25,7 @@ async function processCommand(command, args) {
|
||||
await writeStdout("\nСтатус код: "+code+"\n")
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
console.log(e.toString())
|
||||
await writeStdout("Не запустилася\n")
|
||||
}
|
||||
} else {
|
||||
|
@ -13,7 +13,7 @@ const SILENT_STDIN = 2
|
||||
const DISABLE_STDIN = 3
|
||||
const ENABLE_STDIN = 4
|
||||
|
||||
async function readLine(on_key=(key, ctrl, alt, shift, content, pos) => [content, pos]) {
|
||||
const READ_FUNCTIONS_CODE = `async function readLine(on_key=(key, ctrl, alt, shift, content, pos) => [content, pos]) {
|
||||
setStdinFlag(ENABLE_STDIN)
|
||||
|
||||
let start_terminal = getTerminal()
|
||||
@ -63,8 +63,8 @@ async function readLine(on_key=(key, ctrl, alt, shift, content, pos) => [content
|
||||
|
||||
continue
|
||||
} else if (event.type == "char") {
|
||||
if (event.char == "\n") break
|
||||
if (event.char == "\0") continue
|
||||
if (event.char == "\\n") break
|
||||
if (event.char == "\\0") continue
|
||||
|
||||
content = content.slice(0, pos) + event.char + content.slice(pos)
|
||||
pos += 1
|
||||
@ -79,10 +79,10 @@ async function readLine(on_key=(key, ctrl, alt, shift, content, pos) => [content
|
||||
async function pollStdinEvent() {
|
||||
let char = await readStdin()
|
||||
|
||||
if (char == "\r") {
|
||||
if (char == "\\r") {
|
||||
let key = ""
|
||||
char = await readStdin()
|
||||
while (char != "\r") {
|
||||
while (char != "\\r") {
|
||||
key += char
|
||||
char = await readStdin()
|
||||
}
|
||||
@ -107,6 +107,34 @@ async function pollStdinEvent() {
|
||||
}
|
||||
}
|
||||
|
||||
function executeCommand(args, read=readStdin, write=writeStdout, set_flag=setStdinFlag, inject="") {
|
||||
let id = new Date().getMilliseconds().toString()+(Math.random()*100)
|
||||
let func_content = readFile(args[0])
|
||||
if (func_content == null || !func_content.includes("function main")) return
|
||||
let func = new Function(
|
||||
"args", "readStdin", "writeStdout", "setStdinFlag",
|
||||
READ_FUNCTIONS_CODE+"\\n\\n\\n"+func_content+"\\n"+inject+"\\nreturn main(args)"
|
||||
)
|
||||
let process = {
|
||||
"id": id,
|
||||
"name": args.join(" "),
|
||||
"promise": new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
resolve(func(args, read, write, set_flag))
|
||||
} catch (e) {
|
||||
reject(e)
|
||||
}
|
||||
}, 0)
|
||||
}).then(o => {
|
||||
processes = processes.filter(x => x.id != id)
|
||||
return o
|
||||
})
|
||||
}
|
||||
processes.push(process)
|
||||
return process
|
||||
}`
|
||||
|
||||
async function readStdin() {
|
||||
while (stdin.length == 0) {
|
||||
await new Promise(resolve => setTimeout(resolve, 10))
|
||||
@ -133,18 +161,21 @@ function setStdinFlag(flag) {
|
||||
}
|
||||
}
|
||||
|
||||
function executeCommand(args, read=readStdin, write=writeStdout) {
|
||||
function executeCommand(args, read=readStdin, write=writeStdout, set_flag=setStdinFlag, inject="") {
|
||||
let id = new Date().getMilliseconds().toString()+(Math.random()*100)
|
||||
let func_content = readFile(args[0])
|
||||
if (func_content == null || !func_content.includes("function main")) return
|
||||
let func = new Function("args", "readStdin", "writeStdout", func_content+"\n\nreturn main(args)")
|
||||
let func = new Function(
|
||||
"args", "readStdin", "writeStdout", "setStdinFlag",
|
||||
READ_FUNCTIONS_CODE+"\n\n\n"+func_content+"\n"+inject+"\nreturn main(args)"
|
||||
)
|
||||
let process = {
|
||||
"id": id,
|
||||
"name": args.join(" "),
|
||||
"promise": new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
resolve(func(args, read, write))
|
||||
resolve(func(args, read, write, set_flag))
|
||||
} catch (e) {
|
||||
reject(e)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user