added inital chat

This commit is contained in:
2025-12-12 14:09:35 -05:00
parent bf83b7495d
commit 2fa9be5ebf
3 changed files with 98 additions and 0 deletions

1
consumer/chat.lua Normal file
View File

@@ -0,0 +1 @@
print("Chat.lua loaded")

View File

@@ -1,6 +1,8 @@
local kernel = require("kernel")
local monitor = kernel.addDriver("monitor-driver")
local data = kernel.addDriver("disk-driver")
local taskManager = kernel.addDriver("program-driver")
local chatProgram = kernel.addDriver("chat")
local function run()
monitor.initialize()
@@ -11,6 +13,9 @@ local function run()
computerName = data.getRead("computer-name")
os.setComputerLabel(computerName)
monitor.writeLine("Computer name: " .. computerName)
taskManager.addProgram("Coms", "chat.lua");
taskManager.listPrograms()
end
return { run = run }

92
program-driver.lua Normal file
View File

@@ -0,0 +1,92 @@
local monitor = peripheral.find("monitor")
local programs = {}
local isRunning = false
local function addProgram(name, path)
table.insert(programs, {name = name, path = path})
end
local function runProgram(path)
if fs.exists(path) then
local w, h = monitor.getSize()
monitor.setBackgroundColor(colors.black)
monitor.clear()
-- Draw X button
monitor.setCursorPos(w, 1)
monitor.setBackgroundColor(colors.red)
monitor.setTextColor(colors.white)
monitor.write("X")
monitor.setBackgroundColor(colors.black)
-- Create window for program
local win = window.create(monitor, 1, 2, w, h - 1)
local oldTerm = term.redirect(win)
local function run()
shell.run(path)
end
local function watchExit()
while true do
local _, _, x, y = os.pullEvent("monitor_touch")
if x == w and y == 1 then
return
end
end
end
parallel.waitForAny(run, watchExit)
term.redirect(oldTerm)
return true
else
print("Program not found: " .. path)
return false
end
end
local function exitProgram()
isRunning = false
end
local function drawList()
monitor.clear()
monitor.setCursorPos(1, 1)
monitor.write("Available Programs:")
for i, program in ipairs(programs) do
monitor.setCursorPos(1, i + 2) -- Start from line 3
monitor.write(i .. ". " .. program.name)
end
monitor.setCursorPos(1, #programs + 4)
monitor.write("Click to run")
end
local function listPrograms()
isRunning = true
while isRunning do
drawList()
local event, side, x, y = os.pullEvent("monitor_touch")
local programIndex = y - 2
if programIndex > 0 and programIndex <= #programs then
local program = programs[programIndex]
monitor.clear()
monitor.setCursorPos(1,1)
monitor.write("Running " .. program.name .. "...")
sleep(1)
runProgram(program.path)
end
end
end
return {
addProgram = addProgram,
runProgram = runProgram,
exitProgram = exitProgram,
listPrograms = listPrograms
}