alot of stuff

This commit is contained in:
2025-10-22 16:43:36 -07:00
parent 734587569a
commit b6126945fd
8 changed files with 110 additions and 35 deletions

View File

@@ -6,13 +6,13 @@
30000000300055555555d555555d3d333333303333333333330 30000000300055555555d555555d3d333333303333333333330
3303333333353555555d5d555555d3333033333333330330000 3303333333353555555d5d555555d3333033333333330330000
033330303035355555555555555d3d333033033033333300000 033330303035355555555555555d3d333033033033333300000
003030333333555ffff555ffff55d3303333333333303300077 003030333333555ffff555ffff55d3303333333333303300007
0033333033035555555555555555d3333303330330333000878 0033333033035555555555555555d3333303330330333000877
78830333333535555555f555555d3d303333333333037787778 78830333333535555555f555555d3d303333333333037787787
87844bb0b0bb55b5555555555dbddbbbbbb0bbbb44407878888 87844bb0b0bb55b5555555555dbddbbbbbb0bbbb44407878887
0780044bbbb0bb5b55555555dbdbb0b0bbbbbb4440778888888 0780044bbbb0bb5b55555555dbdbb0b0bbbbbb4440778888877
7870040b0b0bbbbb55555555dbbbbbbb0bb0b44407888808888 7870040b0b0bbbbb55555555dbbbbbbb0bb0b44407888808788
78080044bbbbb0bb55555555db0bb0bb0bbbb40077870878087 78080044bbbbb0bb55555555db0bb0bb0bbbb40077870878087
78788004bbb0bbb555555555dbbbbbbbbbbb440078788887787 78788004bbb0bbb5555555555dbbbbbbbbbb440078788887787
778788004b0bbbb5555555555dbbbb0bbb04408878888088777 778788004b0bbbb5555555555dbbbb0bbb04408878888088777
777888004bbbbb555555555555dbbbbbbbb4008878088878888 777888004bbbbb555555555555dbbbbbbbb4008878088878877

View File

@@ -3,6 +3,7 @@ local threading = require("libs.threading")
local x, y = term.getSize() local x, y = term.getSize()
local win = window.create("Launcher", x / 3, y / 1.4, x / 2 - ((x / 3) / 2), y / 2 - ((y / 1.5) / 2)) local win = window.create("Launcher", x / 3, y / 1.4, x / 2 - ((x / 3) / 2), y / 2 - ((y / 1.5) / 2))
win.decorations = false win.decorations = false
win.draggable = false
win.alwaysOnTop = true win.alwaysOnTop = true
local apps = {} local apps = {}
-- tiny alphabetical boost based on the first AZ letter in the name -- tiny alphabetical boost based on the first AZ letter in the name

View File

@@ -2,6 +2,7 @@ local compat = require("libs.compat")
local window = require("libs.window") local window = require("libs.window")
local x, y = term.getSize() local x, y = term.getSize()
local win = window.create("Worm", x / 1.4, y / 1.4, x / 2 - ((x / 1.4) / 2), y / 2 - ((y / 1.5) / 2)) local win = window.create("Worm", x / 1.4, y / 1.4, x / 2 - ((x / 1.4) / 2), y / 2 - ((y / 1.5) / 2))
win.resizable = false
sleep() sleep()
compat.runFile("/rom/programs/fun/worm.lua", win) compat.runFile("/rom/programs/fun/worm.lua", win)
win.close() win.close()

View File

@@ -520,6 +520,7 @@ function lib.setupENV(win)
if http then load_apis("rom/apis/http") end if http then load_apis("rom/apis/http") end
if turtle then load_apis("rom/apis/turtle") end if turtle then load_apis("rom/apis/turtle") end
if pocket then load_apis("rom/apis/pocket") end if pocket then load_apis("rom/apis/pocket") end
env.shell = shell
env._ENV = env env._ENV = env
env._G = env env._G = env
@@ -534,7 +535,7 @@ local function generate_id(length)
return id return id
end end
local function runInRuntime(func, win) local function runInRuntime(func, win, close_handled)
expect(1, func, "function") expect(1, func, "function")
expect(2, win, "table") expect(2, win, "table")
local co = coroutine.create(func) local co = coroutine.create(func)
@@ -570,9 +571,15 @@ local function runInRuntime(func, win)
os.queueEvent("key_up_" .. winid, key, winid) os.queueEvent("key_up_" .. winid, key, winid)
end end
function win.resized()
os.queueEvent("term_resize_"..winid, winid)
end
if close_handled then
function win.closeRequested() function win.closeRequested()
run = false run = false
end end
end
local function escape_lua_pattern(s) local function escape_lua_pattern(s)
-- magic chars: ( ) . % + - * ? [ ^ $ ] -- magic chars: ( ) . % + - * ? [ ^ $ ]
@@ -628,6 +635,11 @@ local function runInRuntime(func, win)
data.n = data.n - 1 data.n = data.n - 1
event_data = data event_data = data
end end
elseif data[1] == "term_resize" then
if data[#data] == winid then
data.n = data.n - 1
event_data = data
end
else else
event_data = data event_data = data
end end
@@ -637,13 +649,13 @@ local function runInRuntime(func, win)
end end
end end
function lib.runFunc(func, win) function lib.runFunc(func, win, close_handled)
runInRuntime(setfenv(func, lib.setupENV(win)), win) runInRuntime(setfenv(func, lib.setupENV(win)), win, close_handled)
end end
function lib.runFile(file, win) function lib.runFile(file, win, close_handled)
local func = loadfile(file) local func = loadfile(file)
runInRuntime(setfenv(func, lib.setupENV(win)), win) runInRuntime(setfenv(func, lib.setupENV(win)), win, close_handled)
end end
return lib return lib

View File

@@ -65,6 +65,8 @@ function lib.create(name, w, h, x, y)
name = name, name = name,
w = w, w = w,
h = h, h = h,
min_w = 3,
min_h = 3,
x = x or 1, x = x or 1,
y = y or 2, y = y or 2,
@@ -75,6 +77,8 @@ function lib.create(name, w, h, x, y)
textColor = colors.white, textColor = colors.white,
bgColor = colors.black, bgColor = colors.black,
cursorBlink = false, cursorBlink = false,
resizable = true,
draggable = true,
decorations = true, decorations = true,
alwaysOnTop = false, alwaysOnTop = false,
alwaysBelow = false, alwaysBelow = false,
@@ -96,6 +100,7 @@ function lib.create(name, w, h, x, y)
init_col(xi) init_col(xi)
for yy = 1, t.h do for yy = 1, t.h do
local cell = t.buffer[xi][yy] local cell = t.buffer[xi][yy]
if not cell then cell = { char = " ", tc = t.textColor, bc = t.bgColor } end
cell.char, cell.tc, cell.bc = " ", t.textColor, t.bgColor cell.char, cell.tc, cell.bc = " ", t.textColor, t.bgColor
end end
end end
@@ -286,6 +291,8 @@ function lib.create(name, w, h, x, y)
function t.key_up(key) end function t.key_up(key) end
function t.resized(w,h) end
function t.closeRequested() t.closing = true end function t.closeRequested() t.closing = true end
function t.close() function t.close()

View File

@@ -1,10 +1,10 @@
local max_distance = 220 local max_distance = 220
local pullEvent = os.pullEventRaw _G.network = {}
local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end) local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end)
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)
_G.network = {}
if not modem then if not modem then
return return
end end
@@ -14,7 +14,7 @@ local canidate = {id = -1, distance = max_distance}
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end, parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
function () function ()
while true do while true do
local _, _, channel, _, msg, distance = pullEvent("modem_message") local _, _, channel, _, msg, distance = os.pullEvent("modem_message")
if channel == 15125 then if channel == 15125 then
if msg.protocol == "entrypoint_advertise" then if msg.protocol == "entrypoint_advertise" then
if distance < canidate.distance then if distance < canidate.distance then
@@ -30,18 +30,19 @@ modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerI
local function receive() local function receive()
while true do while true do
local _, _, channel, _, msg, distance = pullEvent("modem_message") local _, _, channel, _, msg, distance = os.pullEvent("modem_message")
if channel == 15125 then if channel == 15125 then
if msg.protocol == "heartbeat" and msg.target == os.getComputerID() and msg.sender == canidate.id then if msg.protocol == "heartbeat" and msg.target == os.getComputerID() and msg.sender == canidate.id then
last_heartbeat = os.epoch("utc") last_heartbeat = os.epoch("utc")
modem.transmit(15125,15125,{protocol="heartbeat_response",sender=os.getComputerID(),target=canidate.id}) modem.transmit(15125,15125,{protocol="heartbeat_response",sender=os.getComputerID(),target=canidate.id})
canidate.distance = distance
if distance > max_distance then if distance > max_distance then
modem.transmit(15125,15125,{protocol="entrypoint_disconnect",sender=os.getComputerID(),target=canidate.id}) modem.transmit(15125,15125,{protocol="entrypoint_disconnect",sender=os.getComputerID(),target=canidate.id})
canidate = {id = -1, distance = max_distance} canidate = {id = -1, distance = max_distance}
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end, parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
function () function ()
while true do while true do
local _, _, channel, _, msg, distance = pullEvent("modem_message") local _, _, channel, _, msg, distance = os.pullEvent("modem_message")
if channel == 15125 then if channel == 15125 then
if msg.protocol == "entrypoint_advertise" then if msg.protocol == "entrypoint_advertise" then
if distance < canidate.distance then if distance < canidate.distance then
@@ -73,6 +74,12 @@ function _G.network.send(msg,destination)
if not destination then error("No destination provided",2) end if not destination then error("No destination provided",2) end
message_queue[#message_queue+1] = {protocol="packet",content=msg,destination=destination,sender=os.getComputerID(),hops=0} message_queue[#message_queue+1] = {protocol="packet",content=msg,destination=destination,sender=os.getComputerID(),hops=0}
end end
function _G.network.getID()
return canidate.id
end
function _G.network.getDistance()
return canidate.distance
end
local function connect() local function connect()
while true do while true do
@@ -81,7 +88,7 @@ local function connect()
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end, parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
function () function ()
while true do while true do
local _, _, channel, _, msg, distance = pullEvent("modem_message") local _, _, channel, _, msg, distance = os.pullEvent("modem_message")
if channel == 15125 then if channel == 15125 then
if msg.protocol == "entrypoint_advertise" then if msg.protocol == "entrypoint_advertise" then
if distance < canidate.distance then if distance < canidate.distance then

View File

@@ -1,6 +1,8 @@
local threading = require("libs.threading") local threading = require("libs.threading")
local dragging = nil local dragging = nil
local resizing = false
local offsetX, offsetY = 0, 0 local offsetX, offsetY = 0, 0
local key = {}
local function bringtofront(indx) local function bringtofront(indx)
local win = _G.windows[indx] local win = _G.windows[indx]
if win.alwaysOnTop or win.alwaysBelow then return end if win.alwaysOnTop or win.alwaysBelow then return end
@@ -31,7 +33,13 @@ while true do
if data[1] == "mouse_click" then if data[1] == "mouse_click" then
for indx = #_G.windows, 1, -1 do for indx = #_G.windows, 1, -1 do
local win = _G.windows[indx] local win = _G.windows[indx]
if win.y - 1 == data[4] and win.x + 1 <= data[3] and win.x + win.w >= data[3] and data[2] == 1 and win.decorations then if data[4] == 1 then
break
elseif win.x+win.w-1 == data[3] and win.y+win.h-1 == data[4] and win.decorations and win.resizable then
dragging = win
resizing = true
bringtofront(indx)
elseif ((win.y - 1 == data[4] and win.x + 1 <= data[3] and win.x + win.w >= data[3] and data[2] == 1 and win.decorations) or (win.y <= data[4] and win.x <= data[3] and win.y + win.h > data[4] and win.x + win.w > data[3] and key[keys["leftAlt"] and win.draggable])) then
dragging = win dragging = win
offsetX = win.x - data[3] offsetX = win.x - data[3]
offsetY = win.y - data[4] offsetY = win.y - data[4]
@@ -49,8 +57,14 @@ while true do
end end
elseif data[1] == "mouse_drag" then elseif data[1] == "mouse_drag" then
if data[2] == 1 and dragging then if data[2] == 1 and dragging then
if resizing then
dragging.w = math.max(data[3] - dragging.x + 1,dragging.min_w)
dragging.h = math.max(data[4] - dragging.y + 1,dragging.min_h)
threading.addThread(function()dragging.resized(dragging.w,dragging.h)end)
else
dragging.x = data[3] + offsetX dragging.x = data[3] + offsetX
dragging.y = data[4] + offsetY dragging.y = data[4] + offsetY
end
else else
for indx = #_G.windows, 1, -1 do for indx = #_G.windows, 1, -1 do
local win = _G.windows[indx] local win = _G.windows[indx]
@@ -64,6 +78,7 @@ while true do
elseif data[1] == "mouse_up" then elseif data[1] == "mouse_up" then
if data[2] == 1 and dragging then if data[2] == 1 and dragging then
dragging = nil dragging = nil
resizing = false
else else
for indx = #_G.windows, 1, -1 do for indx = #_G.windows, 1, -1 do
local win = _G.windows[indx] local win = _G.windows[indx]
@@ -83,6 +98,7 @@ while true do
end end
end end
elseif data[1] == "key" then elseif data[1] == "key" then
key[data[2]] = true
if _G.windows[#_G.windows] then if _G.windows[#_G.windows] then
threading.addThread(function() _G.windows[#_G.windows].key(data[2], data[3]) end) threading.addThread(function() _G.windows[#_G.windows].key(data[2], data[3]) end)
end end
@@ -91,6 +107,7 @@ while true do
threading.addThread(function() _G.windows[#_G.windows].char(data[2]) end) threading.addThread(function() _G.windows[#_G.windows].char(data[2]) end)
end end
elseif data[1] == "key_up" then elseif data[1] == "key_up" then
key[data[2]] = false
if _G.windows[#_G.windows] then if _G.windows[#_G.windows] then
threading.addThread(function() _G.windows[#_G.windows].key_up(data[2]) end) threading.addThread(function() _G.windows[#_G.windows].key_up(data[2]) end)
end end

View File

@@ -1,4 +1,5 @@
--os.pullEvent = os.pullEventRaw --os.pullEvent = os.pullEventRaw
local window = require("libs.window") local window = require("libs.window")
local nft = require "cc.image.nft" local nft = require "cc.image.nft"
local wrap = require("cc.strings").wrap local wrap = require("cc.strings").wrap
@@ -42,18 +43,34 @@ local function windows()
term.setCursorPos(win.x, win.y + cy - 1) term.setCursorPos(win.x, win.y + cy - 1)
local line, fg, bg = "", "", "" local line, fg, bg = "", "", ""
for cx = 1, win.w do for cx = 1, win.w do
if win.buffer[cx] then
local cell = win.buffer[cx][cy] local cell = win.buffer[cx][cy]
if cell then
line = line .. cell.char line = line .. cell.char
fg = fg .. ("0123456789abcdef"):sub(math.log(cell.tc, 2) + 1, math.log(cell.tc, 2) + 1) 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) 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 end
term.blit(line, fg, bg) term.blit(line, fg, bg)
end end
if win.decorations then if win.decorations then
term.setCursorPos(win.x, win.y - 1) term.setCursorPos(win.x, win.y - 1)
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.setBackgroundColor(colors.gray) term.setBackgroundColor(colors.blue)
term.write("X " .. win.name .. string.rep(" ", win.w - #win.name - 2)) term.write(string.sub("X " .. win.name .. string.rep(" ", win.w - #win.name - 2),1,win.w))
if win.resizable then
term.setCursorPos(win.x+win.w-1,win.y+win.h-1)
term.write("\127")
end
end end
term.setCursorPos(win.x + win.cursorX - 1, win.y + win.cursorY - 1) term.setCursorPos(win.x + win.cursorX - 1, win.y + win.cursorY - 1)
term.setCursorBlink(win.cursorBlink) term.setCursorBlink(win.cursorBlink)
@@ -70,17 +87,29 @@ local function desktop()
local w, h = term.getSize() local w, h = term.getSize()
term.setBackgroundColor(colors.white) term.setBackgroundColor(colors.white)
term.clear() term.clear()
term.setCursorPos(1, 1)
term.setTextColor(colors.white)
term.setBackgroundColor(colors.gray)
term.clearLine()
term.write(" "..((_G.windows[#_G.windows] or {name=""}).name or "").." ")
if image then if image then
nft.draw(image,1,1) nft.draw(image,1,1)
elseif paint_image then elseif paint_image then
paintutils.drawImage(paint_image,1,2) paintutils.drawImage(paint_image,1,2)
end end
end end
local function bars()
local cx,cy = term.getCursorPos()
local w, h = term.getSize()
term.setCursorPos(1, 1)
term.setTextColor(colors.white)
term.setBackgroundColor(colors.gray)
term.clearLine()
term.write(" "..((_G.windows[#_G.windows] or {name=""}).name or "").." ")
local rightbar = ""
if network and network.getID and network.getDistance and network.getID() ~= -1 then
rightbar = "id: "..tostring(network.getID()).." dist: "..tostring(math.floor(network.getDistance()+0.5))
end
term.setCursorPos(w-(#rightbar),1)
term.write(rightbar)
term.setCursorPos(cx,cy)
end
local threading = require("libs.threading") local threading = require("libs.threading")
local compat = require("libs.compat") local compat = require("libs.compat")
for _, i in ipairs(fs.list("/modules")) do for _, i in ipairs(fs.list("/modules")) do
@@ -93,6 +122,7 @@ local function render()
while true do while true do
desktop() desktop()
windows() windows()
bars()
sleep(1 / 20) sleep(1 / 20)
end end
end end