Currently I added normal write/print functions, flashing text and marquee left and right. More is coming.
Current functions:
Spoiler
writeM(side, text) - Write text on the monitor.printM(side, text) - Print text on the monitor (it adds an extra line).
writePos(side, text, xpos, ypos) - Write text at a specific point.
slowPrint(side, text) - Slowly print text on the monitor.
slowPrintPos(side, text, xpos, ypos) - Slowly print text at a specific point.
clear(side) - Clear the monitor's screen.
flashyText(side, text, sleep, times) - Flash text on the monitor.
flashyTextPos(side, text, xpos, ypos, sleep, times) - Flash text at a specific point.
marqueeLeft(side, text, ypos, sleep) - Slide text from right to left.
marqueeRight(side, text, ypos, sleep) - Slide text from left to right.
The marquee functions now work properly thanks to Lyqyd.
goto(side) - Redirect to a monitor quickly (term.redirect(peripheral.wrap("right")) vs monitorapi.goto("right")). Use term.restore() to go back.
runprgm(side, prgm, args) - Run a program on the monitor.
run(side, func) - Run some lua code. For func, either put a function name or do "function() yourcodehere() end".
Spoiler
--Monitor API by ihaveamac
function getVersion()
return 1.2
end
function writeM(side, text)
if peripheral.isPresent(side) then
term.redirect(peripheral.wrap(side))
write(text)
term.restore()
end
end
function printM(side, text)
if peripheral.isPresent(side) then
term.redirect(peripheral.wrap(side))
print(text)
term.restore()
end
end
function writePos(side, text, xpos, ypos)
if peripheral.isPresent(side) then
term.redirect(peripheral.wrap(side))
term.setCursorPos(xpos, ypos)
write(text)
term.restore()
end
end
function slowPrint(side, text)
if peripheral.isPresent(side) then
term.redirect(peripheral.wrap(side))
textutils.slowPrint(text)
term.restore()
end
end
function slowPrintPos(side, text, xpos, ypos)
if peripheral.isPresent(side) then
term.redirect(peripheral.wrap(side))
term.setCursorPos(xpos, ypos)
textutils.slowPrint(text)
term.restore()
end
end
function clear(side)
if peripheral.isPresent(side) then
term.redirect(peripheral.wrap(side))
term.clear()
term.setCursorPos(1, 1)
term.restore()
end
end
function flashyText(side, text, sleep, times)
if peripheral.isPresent(side) then
term.redirect(peripheral.wrap(side))
for i = 1, times do
local cx, cy = term.getCursorPos()
write(text)
term.setCursorPos(cx, cy)
os.sleep(sleep)
term.clearLine()
os.sleep(sleep)
end
term.restore()
end
end
function flashyTextPos(side, text, xpos, ypos, sleep, times)
if peripheral.isPresent(side) then
term.redirect(peripheral.wrap(side))
for i = 1, times do
term.setCursorPos(xpos, ypos)
write(text)
term.setCursorPos(xpos, ypos)
os.sleep(sleep)
term.clearLine()
os.sleep(sleep)
end
term.restore()
end
end
function marqueeLeft(side, text, ypos, sleep)
if peripheral.isPresent(side) then
term.redirect(peripheral.wrap(side))
local sx, sy = term.getSize()
text = string.rep(" ", sx - 1)..text
for i=1,string.len(text) do
term.clearLine()
displayString = string.sub(text, i, math.min(string.len(text), (i + sx - 2)))
term.setCursorPos(1, ypos)
write(displayString)
os.sleep(sleep)
end
term.clearLine()
term.restore()
end
end
function marqueeRight(side, text, ypos, sleep)
if peripheral.isPresent(side) then
term.redirect(peripheral.wrap(side))
local sx, sy = term.getSize()
text = string.rep(" ", sx - 1)..text..string.rep(" ", sx - 1)
for i = 1,string.len(text) - (sx - 1) do
term.clearLine()
displayString = string.sub(text, -math.min(string.len(text), i + sx - 2), -i)
term.setCursorPos(1, ypos)
write(displayString)
os.sleep(sleep)
end
term.clearLine()
term.restore()
end
end
--thanks to Lyqyd from the ComputerCraft fourms for fixing the marquee code. :mellow:/>/>
function goto(side)
if peripheral.isPresent(side) then
term.redirect(peripheral.wrap(side))
end
end
function runprgm(side, prgm, args)
if peripheral.isPresent(side) then
term.redirect(peripheral.wrap(side))
shell.run(prgm, args)
term.restore()
end
end
function run(side, func)
if peripheral.isPresent(side) then
term.redirect(peripheral.wrap(side))
func()
term.restore()
end
end