more stuff

This commit is contained in:
2025-12-23 09:52:48 -08:00
parent 4e0a5871bd
commit 9df738465a
11 changed files with 5387 additions and 33 deletions

View File

@@ -1,27 +1,36 @@
local apps = {}
local windows = loadfile("/libs/windows.lua")()
local containers = loadfile("/libs/containers.lua")()
local focusedapp = nil
local home_button = "[------]"
local launcherappid = "com.ruffles.launcher"
local launcherapp = nil
_G.app = {}
function _G.app.focusapp(pid)
print("focusing "..pid)
if focusedapp ~= nil and focusedapp.win ~= nil then
focusedapp.win.setVisible(false)
end
focusedapp = apps[pid]
print(focusedapp)
if focusedapp ~= nil and focusedapp.win ~= nil then
focusedapp.win.setVisible(true)
end
end
function _G.app.launch(id)
function _G.app.getApps()
local out = {}
for _,f in ipairs(fs.list("/apps-meta")) do
if fs.exists(fs.combine("/apps-meta",f)) then
print(f)
local file = fs.open(fs.combine("/apps-meta",f),"r")
if file then
out[#out+1] = textutils.unserialise(file.readAll())
file.close()
end
end
end
return out
end
function _G.app.launch(id,perms)
local w,h = term.getSize()
if not fs.exists(fs.combine("/apps",id)) then return false,"App Not Found" end
local win = window.create(term.native(),1,2,w,h-2,false)
print("loading "..id)
local env = containers.getENV(fs.combine("/apps",id),true, win)
local appobj = {win=win,co=nil,id=id,title=""}
local win = windows.create(id,w,h-2,1,2)
local env = containers.getENV(fs.combine("/apps",id), win, perms)
local appobj = {win=win,co=nil,id=id,title=id}
function env.setAppTitle(str) appobj.title=str end
print("loaded "..id)
appobj.co = coroutine.create(function () containers.start(env) end)
local pid = -1
for k=1,#apps+1 do
@@ -31,13 +40,43 @@ function _G.app.launch(id)
end
end
app.focusapp(pid)
return pid
end
local function render()
while true do
local w,h = term.getSize()
if focusedapp and focusedapp.win then
local window = focusedapp.win
for cy = 1, window.h do
term.setCursorPos(window.x, window.y + cy - 1)
local line, fg, bg = "", "", ""
for cx = 1, window.w do
if window.buffer[cx] then
local cell = window.buffer[cx][cy]
if cell then
line = line .. cell.char
fg = fg .. ("0123456789abcdef"):sub(math.log(cell.tc, 2) + 1, math.log(cell.tc, 2) + 1)
bg = bg .. ("0123456789abcdef"):sub(math.log(cell.bc, 2) + 1, math.log(cell.bc, 2) + 1)
else
line = line .. " "
fg = fg .. "0"
bg = bg .. "f"
end
else
line = line .. " "
fg = fg .. "0"
bg = bg .. "f"
end
end
term.blit(line, fg, bg)
end
end
term.setCursorPos(1,1)
term.setBackgroundColor(colors.black)
if focusedapp then
term.setBackgroundColor(focusedapp.win.getBackgroundColour())
end
term.clearLine()
term.write(os.date("%I:%M %p"))
local candidate = network.getCandidate()
@@ -47,17 +86,43 @@ local function render()
end
term.setCursorPos(w-right:len()+1,1)
term.write(right)
sleep()
term.setCursorPos((w/2)-(home_button:len()/2)+1,h)
term.write(home_button)
term.setCursorPos(1,h)
if focusedapp then
local window = focusedapp.win
if window then
term.setCursorPos(window.cursorX,window.cursorY)
term.setCursorBlink(window.cursorBlink)
else
term.setCursorBlink(false)
end
end
sleep(1/20)
end
end
local function process()
while true do
local event = {os.pullEvent()}
if event[1] == "mouse_click" then
local w,h = term.getSize()
if event[2] == 1 and event[3] >= (w/2)-(home_button:len()/2)+1 and event[3] <= (w/2)-(home_button:len()/2)+home_button:len() and event[4] == h then
app.focusapp(launcherapp)
end
event[4] = event[4]-1
elseif event[1] == "mouse_up" then
event[4] = event[4]-1
elseif event[1] == "mouse_drag" then
event[4] = event[4]-1
elseif event[1] == "mouse_scroll" then
event[4] = event[4]-1
end
if focusedapp then
if focusedapp.event then
local success, content = coroutine.resume(focusedapp.co,table.unpack(focusedapp.event))
if success then
-- print(focusedapp.title,focusedapp.filter)
focusedapp.event = nil
focusedapp.filter = content
else
@@ -73,13 +138,13 @@ local function process()
end
end
for k,v in pairs(apps) do
if v.filter == nil or v.filter == event[1] and v.event == nil and not v == focusedapp then
if v.filter == nil or v.filter == event[1] and v.event == nil and v ~= focusedapp then
v.event = event
end
end
end
end
print("launching test..")
app.launch("test")
print("launched")
print("launching launcher app..")
launcherapp = app.launch(launcherappid,{http=true,app=true,repo=true,network=true})
print("launched launcher app")
parallel.waitForAny(process,render,network.run)