Posted 11 May 2012 - 11:13 PM
here is the code
to start type in lua or other program
you can also use set function to insert monitor handle to log al whats on a monitor
example:
local native = term.native
local device = {}
local screen = {}
local w,h=native.getSize()
local function scroll(n)
if n>0 then
for i=1,n do
for j=1,h-1 do
screen[j]=screen[j+1]
end
screen[h]=string.rep(" ",w)
end
elseif n<0 then
for i=1,math.abs(n) do
screen[h]=string.rep(" ",w)
for j=2,h do
screen[j+1]=screen[j]
end
end
end
end
device.write = function (text)
local x,y=native.getCursorPos()
if screen[y]==nil then
screen[y]=string.rep(" ",w)
end
str=string.sub(screen[y],1,x-1)..text..string.sub(screen[y],x+string.len(text))
if y>h then
scroll(1)
y=h
end
screen[y]=string.sub(str,1,w)
while string.len(str)>w do
y=y+1
if y>h then
scroll(1)
y=h
end
str=string.sub(str,w+1)
screen[y]=string.sub(str,1,w)
end
native.write(text)
end
device.clear = function ()
for i=1,h do
screen[i]=string.rep(" ",w)
end
native.clear()
end
device.clearLine = function ()
native.clearLine()
end
device.getCursorPos = function ()
return native.getCursorPos()
end
device.setCursorPos = function (x,y)
native.setCursorPos(x,y)
end
device.setCursorBlink = function (:)/>/>
native.setCursorBlink(:)/>/>
end
device.getSize = function ()
return native.getSize()
end
device.scroll = function (n)
scroll(n)
native.scroll(n)
end
function getLogger()
return device
end
function set(obj)
native=obj
w,h=native.getSize()
end
function getLine(line)
return screen[line] or string.rep(" ",w)
end
function save(file)
f=io.open(file,"w")
for i=1,h do
f:write((getLine(i) or string.rep(" ",w)).."\n")
end
f:close()
end
to start type in lua or other program
os.loadAPI("filename")
term.redirect(filename.getLogger())
you can also use set function to insert monitor handle to log al whats on a monitor
example:
filename.set(peripheral.wrap("right")) //monitor on the right side