Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modemSide = "left" -- Use your modem side here
- local monitor = peripheral.find("monitor") or peripheral.wrap("monitor_5")
- if not monitor then error("Monitor not found.") end
- rednet.open(modemSide)
- monitor.setTextScale(0.5)
- local monW, monH = monitor.getSize()
- local midX = math.floor(monW / 2)
- local function coloredLine(mon, color, text)
- mon.setTextColor(color)
- mon.write(text)
- mon.setTextColor(colors.white)
- end
- local prevCrafting = {}
- local craftHistory = {} -- list of {item, cpu, timestamp, duration}
- while true do
- local senderId, jobs = rednet.receive("ae2_crafting_status")
- monitor.clear()
- monitor.setCursorPos(1,1)
- coloredLine(monitor, colors.white, "Live CPUs:\n")
- monitor.setCursorPos(midX+1,1)
- coloredLine(monitor, colors.white, "Crafting History:\n")
- -- Draw vertical grey line between sections
- for y = 1, monH do
- monitor.setCursorPos(midX, y)
- monitor.setTextColor(colors.gray)
- monitor.write("|")
- end
- monitor.setTextColor(colors.white) -- reset
- -- Find finished jobs
- local currBusy = {}
- for _, job in ipairs(jobs or {}) do
- if job.isBusy then
- currBusy[job.cpu] = job
- end
- end
- for cpu, prev in pairs(prevCrafting) do
- if prev and (not currBusy[cpu]) and prev.item then
- -- CPU was busy, now idle: job finished!
- local tstamp = textutils.formatTime(os.time(), true)
- table.insert(craftHistory, 1, {item=prev.item, cpu=cpu, timestamp=tstamp, duration=prev.elapsed})
- if #craftHistory > monH - 1 then
- table.remove(craftHistory, #craftHistory)
- end
- end
- end
- prevCrafting = currBusy
- -- LEFT: Show all CPUs
- local line = 2
- if type(jobs) ~= "table" or #jobs == 0 then
- monitor.setCursorPos(1,line)
- coloredLine(monitor, colors.gray, " (None)\n")
- line = line + 1
- else
- for _, job in ipairs(jobs) do
- if line > monH - 2 then break end
- monitor.setCursorPos(1,line)
- coloredLine(monitor, colors.cyan, string.format("CPU #%d: ", job.cpu))
- if job.isBusy and job.item then
- coloredLine(monitor, colors.green, job.item .. "\n")
- line = line + 1
- monitor.setCursorPos(3,line)
- local pct = 0
- if (job.progress and job.total and job.total > 0) then
- pct = math.floor((job.progress / job.total) * 100)
- end
- coloredLine(monitor, colors.orange, string.format("Progress: %d%%", pct))
- line = line + 1
- monitor.setCursorPos(3,line)
- coloredLine(monitor, colors.gray, string.format("Elapsed: %ds", job.elapsed or 0))
- line = line + 2
- else
- coloredLine(monitor, colors.gray, "idle\n")
- line = line + 2
- end
- end
- end
- -- RIGHT: Crafting history (newest first), [timestamp] name (duration)
- for i, hist in ipairs(craftHistory) do
- if i > monH - 1 then break end
- monitor.setCursorPos(midX+1, i+1)
- coloredLine(monitor, colors.gray, "[" .. hist.timestamp .. "] ")
- coloredLine(monitor, colors.green, hist.item .. " ")
- coloredLine(monitor, colors.orange, string.format("(%ds)\n", hist.duration))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement