Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local p = peripheral.wrap("right")
- p.clear()
- local mon = {}
- local oterm = term
- local mon2 = setmetatable({},{
- __index = function(s,k)
- local a = mon[k]
- local b = oterm[k]
- return function(...)
- if a and b then
- pcall(b,...) return select(2,pcall(a,...))
- elseif a or b then
- return select(2,pcall(a or b,...))
- end
- end
- end
- })
- _G.term = mon2
- local w = 0xffffff
- p.addGradientBox(266, 135, 1, 10, w, 255, w, 255, 1)
- p.addGradientBox(262, 139, 10, 1, w, 255, w, 255, 1)
- mon.visible = true
- mon.minY = 6 * 9
- mon.maxY = 24 * 9 + 4 + 9
- mon.minX = 0 * 6
- mon.maxX = 68 * 6 + 4 - 17 * 6
- mon.rows = math.floor((mon.maxY - mon.minY) / 9)
- mon.cols = math.floor((mon.maxX - mon.minX) / 6)
- mon.lines = {}
- mon.mtrx = {}
- for i = 1, mon.rows do
- mon.mtrx[i] = {}
- end
- mon.scale = 1
- mon.curr = 1
- mon.curc = 1
- mon.cur = p.addText(math.floor((mon.curc - 1) * 6 * mon.scale) + mon.minX + 2, math.floor(((mon.curr - 1) * 9 + 1) * mon.scale) + mon.minY + 2, " ", 0)
- mon.colors = {[1] = 0xffffff, [2] = 0xffc125, [4] = 0xff3e96, [8] = 0x836fff, [16] = 0xffff00, [32] = 0x00ff00, [64] = 0xff82ab, [128] = 0x444444, [256] = 0x999999, [512] = 0x009acd, [1024] = 0x9400d3, [2048] = 0x0000ff, [4096] = 0x8b5a2b, [8192] = 0x458b00, [16384] = 0xff0000, [32768] = 0}
- mon.stat = p.addText(0,mon.minY-18,"Loading...",w)
- mon.cur.setColor(0xffffff)
- mon.bgColor = 0
- mon.color = 0xffffff
- mon.box = p.addBox(mon.minX, mon.minY, mon.maxX - mon.minX + 1, mon.maxY - mon.minY + 1, mon.bgColor, 0)
- mon.box.setZIndex(-1)
- mon.write = function(s)
- if omon then omon.write(s) end
- for i = 1, #s do
- local x = math.floor((mon.curc - 1) * 6 * mon.scale) + mon.minX + 2
- local y = math.floor((mon.curr - 1) * 9 * mon.scale) + mon.minY + 2
- local j = 1
- local t = mon.mtrx[mon.curr][mon.curc]
- if t then
- t.delete()
- end
- t = p.addText(x, y, s:sub(i,i), mon.color)
- mon.mtrx[mon.curr][mon.curc] = t
- mon.lines[#mon.lines + 1] = t
- mon.curc = mon.curc + 1
- if mon.curc > mon.cols then
- mon.curc = 1
- if mon.curr == mon.rows then
- return
- else
- mon.curr = mon.curr + 1
- end
- end
- end
- mon.cur.setX(math.floor((mon.curc - 1) * 6 * mon.scale) + mon.minX + 2)
- mon.cur.setY(math.floor(((mon.curr - 1) * 9 + 1) * mon.scale) + mon.minY + 2)
- end
- mon.clear = function()
- if omon then omon.clear() end
- for i = 1, #mon.lines do
- mon.lines[i].delete()
- mon.lines[i] = nil
- end
- end
- mon.clearLine = function(n)
- if omon then omon.clearLine() end
- local y = math.floor(((n or mon.curr) - 1) * 9 * mon.scale) + mon.minY + 2
- local i = 1
- while i <= #mon.lines do
- if not mon.lines[i].getY() or mon.lines[i].getY() == y then
- mon.lines[i].delete()
- mon.lines[i] = mon.lines[#mon.lines]
- mon.lines[#mon.lines] = nil
- else
- i = i + 1
- end
- end
- end
- mon.scroll = function()
- if omon then omon.scroll() end
- mon.clearLine(1)
- local i = 1
- while i <= #mon.lines do
- if not mon.lines[i].getY() then
- mon.lines[i].delete()
- mon.lines[i] = mon.lines[#mon.lines]
- mon.lines[#mon.lines] = nil
- else
- mon.lines[i].setY(mon.lines[i].getY() - (9 * mon.scale))
- i = i + 1
- end
- end
- for i = 1, mon.rows - 1 do
- mon.mtrx[i] = mon.mtrx[i + 1]
- end
- mon.mtrx[mon.rows] = {}
- end
- mon.setBackgroundColor = function(n)
- if omon then omon.setBackgroundColor(n) end
- if mon.colors[n] then
- n = mon.colors[n]
- end
- mon.bgColor = n
- mon.box.setColor(n)
- mon.box.setOpacity(n == 0 and 0 or 0.40)
- end
- mon.setBackgroundColour = mon.setBackgroundColor
- mon.setTextColor = function(n)
- if mon.colors[n] then
- n = mon.colors[n]
- end
- if omon then omon.setTextColor(n) end
- mon.color = n
- mon.cur.setColor(n)
- end
- mon.setTextColour = mon.setTextColor
- mon.setTextScale = function(n)
- if omon then omon.setTextScale(n) end
- mon.rows = math.floor((mon.maxY - mon.minY - 4)/(9 * n))
- mon.cols = math.floor((mon.maxX - mon.minX - 4)/(6 * n))
- local y = nil
- local x = nil
- if n > mon.scale then
- y = math.floor((mon.rows + 1) * 9 * mon.scale) + mon.minY + 2
- x = math.floor((mon.cols + 1) * 6 * mon.scale) + mon.minX + 2
- end
- local i = 1
- while i < #mon.lines do
- if not mon.lines.getY() or y and (mon.lines[i].getY() >= y or mon.lines[i].getX() >= x) then
- mon.lines[i].delete()
- mon.lines[i] = mon.lines[#mon.lines]
- mon.lines[#mon.lines] = nil
- else
- local ny = (mon.lines[i].getY() - mon.minY - 2) / mon.scale * n
- local nx = (mon.lines[i].getX() - mon.minX - 2) / mon.scale * n
- mon.lines[i].setY(ny)
- mon.lines[i].setX(nx)
- mon.lines[i].setScale(n)
- i = i + 1
- end
- end
- for i = 1, mon.rows do
- if not mon.mtrx[i] then
- mon.mtrx[i] = {}
- end
- end
- mon.scale = n
- mon.cur.setX(math.floor((mon.curc - 1) * 6 * mon.scale) + mon.minX + 2)
- mon.cur.setY(math.floor(((mon.curr - 1) * 9 + 1) * mon.scale) + mon.minY + 2)
- end
- mon.setCursorPos = function(x,y)
- if omon then omon.setCursorPos(x,y) end
- mon.curc = x
- mon.curr = y
- mon.cur.setX(math.floor((mon.curc - 1) * 6 * mon.scale) + mon.minX + 2)
- mon.cur.setY(math.floor(((mon.curr - 1) * 9 + 1) * mon.scale) + mon.minY + 2)
- end
- mon.getCursorPos = function()
- return mon.curc, mon.curr
- end
- mon.getSize = function()
- return mon.cols, mon.rows
- end
- local blink = true
- local blinkstate = false
- local nextBlink = os.startTimer(0.3)
- mon.setCursorBlink = function(b)
- if omon then omon.setCursorBlink(b) end
- blink = b
- end
- local RMON,FMON = mon,{}
- local cell = peripheral.wrap("left")
- local function doBlink()
- blinkstate = not blinkstate
- RMON.cur.setText(blinkstate and blink and "_" or " ")
- nextBlink = os.startTimer(0.3)
- local m = cell.getMaxEnergyStored()
- local t = "["..math.floor(os.clock()).."s] "
- t = t..cell.getEnergyStored().."/"..m
- mon.stat.setText(t.." MJ")
- end
- mon.isColor = function() return true end
- mon.isColour = function() return true end
- local pullEvent = os.pullEvent
- local charQueue = ""
- os.pullEvent = function(...)
- return select(2,pcall(function(...)
- while true do
- if charQueue ~= "" then
- local c = charQueue:sub(1,1)
- charQueue = charQueue:sub(2)
- if c == "\\" then
- c = charQueue:sub(1,1)
- charQueue = charQueue:sub(2)
- if c == "\\" then
- return "char",c
- elseif c == "n" then
- return "key",28
- elseif c == "b" then
- return "key",14
- elseif c == "t" then
- error("Terminated")
- elseif c == "r" then
- os.reboot()
- elseif c == "s" then
- os.shutdown()
- end
- end
- return "char",c
- end
- local t = {pullEvent(...)}
- if t[1] == "chat_command" then
- charQueue = charQueue..t[2]
- local c = charQueue:sub(1,1)
- charQueue = charQueue:sub(2)
- if c == "\\" then
- charQueue = c..charQueue
- elseif t[2] == "$$" then
- -- term.restore()
- -- p.clear() term.clear()
- -- term.setCursorPos(1,1)
- mon.visible = not mon.visible
- mon = mon == RMON and FMON or RMON
- if mon == FMON then mon.clear() end
- charQueue = "" return "none"
- else
- return "char",c
- end
- elseif t[1] == "timer" and t[2] == nextBlink then
- doBlink()
- else
- return unpack(t)
- end
- end
- end,...))
- end
- doBlink()
- local reboot = os.reboot
- os.reboot = function()
- p.clear()
- mon.box.delete()
- mon.cur.delete()
- reboot()
- end
- local shutdown = os.shutdown
- os.shutdown = function()
- p.clear()
- shutdown()
- end
- _G.term.setCursorPos(1,1)
- _G.term.clear() print("Hello!")
- print("Bridge by einsteinK")
Add Comment
Please, Sign In to add comment