From 58e16239d3273e7c56263b680f0161b1175957c5 Mon Sep 17 00:00:00 2001 From: ajh123 Date: Sun, 21 Aug 2022 15:00:03 +0100 Subject: [PATCH] Add gui? fix? --- setup/installer.lua | 92 --------------------------------------------- setup/main.lua | 90 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 88 insertions(+), 94 deletions(-) delete mode 100644 setup/installer.lua diff --git a/setup/installer.lua b/setup/installer.lua deleted file mode 100644 index 07fbb90..0000000 --- a/setup/installer.lua +++ /dev/null @@ -1,92 +0,0 @@ -local api = require "/tmp/GuiH" -local main = {} - -local g_win = window.create(term.current(),1,1,term.getSize()) -local program,w,h = ... -local args = {...} -table.remove(args,1) -table.remove(args,1) -table.remove(args,1) -w,h = (w ~= "") and w or "20",(h ~= "") and h or "10" - -local gui = api.create_gui(g_win) - -function main:start() - local frame = gui.create.frame({ - x=2,2,width=tonumber(w),height=tonumber(h), - dragger={ - x=1,y=1,width=tonumber(w),height=1 - }, - on_move=function(object,pos) - local term = object.canvas.term_object - local w,h = term.getSize() - object.window.reposition( - math.max( - math.min( - pos.x+object.positioning.width, - w+1 - )-object.positioning.width,1 - ), - math.max( - math.min( - pos.y+object.positioning.height, - h+1 - )-object.positioning.height,1 - ) - ) - object.window.restoreCursor() - return true - end, - btn={true} - }) - local shown = true - local win = frame.window - local ele = frame.child - local w,h = win.getSize() - local t_win = window.create(win,2,2,w-2,h-2) - - win.setCursorPos(1,1) - win.blit((" "):rep(w),("f"):rep(w),("7"):rep(w)) - for i=2,h-1 do - win.setCursorPos(1,i) - win.blit(("\149"):rep(w),"8"..("f"):rep(w-1),"f"..("8"):rep(w-1)) - end - win.setCursorPos(1,h) - win.blit("\141"..("\140"):rep(w-2).."\142",("8"):rep(w),("f"):rep(w)) - - - t_win.clear() - local old_term = term.redirect(t_win) - local shell_coro = coroutine.create(function() - shell.run((program ~= "") and program or "sh",unpack(args)) - end) - local function update_shell() - sleep(0.05) - while coroutine.status(shell_coro) ~= "dead" do - local ev_data = table.pack(os.pullEvent()) - local ev = api.convert_event(table.unpack(ev_data,1,ev_data.n)) - if api.valid_events[ev.name] then - local x,y = win.getPosition() - ev_data[3] = ev.x-x - ev_data[4] = ev.y-y - end - if not (frame.dragged and ev_data[1] == "mouse_drag") and ev_data[1] ~= "key_up" then - coroutine.resume(shell_coro,table.unpack(ev_data,1,ev_data.n)) - end - local cx,cy = win.getCursorPos() - local prg = shell.getRunningProgram():match("[^%/-]+$") - local px,py = win.getCursorPos() - win.setCursorPos(1,1) - win.blit(" "..prg..(" "):rep(w-#prg-1),("0"):rep(w),("7"):rep(w)) - win.setCursorPos(px,py) - end - end - local err = gui.execute(update_shell) - term.redirect(old_term) - term.clear() - term.setCursorPos(1,1) - print("Ended window session. "..((err ~= nil) and err or "")) - term.setCursorPos(1,2) -end - -return main \ No newline at end of file diff --git a/setup/main.lua b/setup/main.lua index a8a031b..db032f4 100644 --- a/setup/main.lua +++ b/setup/main.lua @@ -34,5 +34,91 @@ end parallel.waitForAll(table.unpack(downloads)) print("Finished downloading GuiH") -local install = require "/tmp/IPvCC/setup/installer" -install:start() \ No newline at end of file +local api = require "/tmp/GuiH" +local main = {} + +local g_win = window.create(term.current(),1,1,term.getSize()) +local program,w,h = ... +local args = {...} +table.remove(args,1) +table.remove(args,1) +table.remove(args,1) +w,h = (w ~= "") and w or "20",(h ~= "") and h or "10" + +local gui = api.create_gui(g_win) + +local frame = gui.create.frame({ + x=2,2,width=tonumber(w),height=tonumber(h), + dragger={ + x=1,y=1,width=tonumber(w),height=1 + }, + on_move=function(object,pos) + local term = object.canvas.term_object + local w,h = term.getSize() + object.window.reposition( + math.max( + math.min( + pos.x+object.positioning.width, + w+1 + )-object.positioning.width,1 + ), + math.max( + math.min( + pos.y+object.positioning.height, + h+1 + )-object.positioning.height,1 + ) + ) + object.window.restoreCursor() + return true + end, + btn={true} +}) +local shown = true +local win = frame.window +local ele = frame.child +local w,h = win.getSize() +local t_win = window.create(win,2,2,w-2,h-2) + +win.setCursorPos(1,1) +win.blit((" "):rep(w),("f"):rep(w),("7"):rep(w)) +for i=2,h-1 do + win.setCursorPos(1,i) + win.blit(("\149"):rep(w),"8"..("f"):rep(w-1),"f"..("8"):rep(w-1)) +end +win.setCursorPos(1,h) +win.blit("\141"..("\140"):rep(w-2).."\142",("8"):rep(w),("f"):rep(w)) + + +t_win.clear() +local old_term = term.redirect(t_win) +local shell_coro = coroutine.create(function() + shell.run((program ~= "") and program or "sh",unpack(args)) +end) +local function update_shell() + sleep(0.05) + while coroutine.status(shell_coro) ~= "dead" do + local ev_data = table.pack(os.pullEvent()) + local ev = api.convert_event(table.unpack(ev_data,1,ev_data.n)) + if api.valid_events[ev.name] then + local x,y = win.getPosition() + ev_data[3] = ev.x-x + ev_data[4] = ev.y-y + end + if not (frame.dragged and ev_data[1] == "mouse_drag") and ev_data[1] ~= "key_up" then + coroutine.resume(shell_coro,table.unpack(ev_data,1,ev_data.n)) + end + local cx,cy = win.getCursorPos() + local prg = shell.getRunningProgram():match("[^%/-]+$") + local px,py = win.getCursorPos() + win.setCursorPos(1,1) + win.blit(" "..prg..(" "):rep(w-#prg-1),("0"):rep(w),("7"):rep(w)) + win.setCursorPos(px,py) + end +end +local err = gui.execute(update_shell) +term.redirect(old_term) +term.clear() +term.setCursorPos(1,1) +print("Ended window session. "..((err ~= nil) and err or "")) +term.setCursorPos(1,2)