Hey all, is there a way to get the current contents of the console? I'm sure it is stored in a table somewhere to be reprinted if the window is full. does anyone know where it is?
Get window contents
Started by KaoS, Sep 07 2012 12:37 PM
7 replies to this topic
#1
Posted 07 September 2012 - 12:37 PM
#2
Posted 07 September 2012 - 02:50 PM
You can look through the write() function, but I don't believe that it is stored anywhere. You could create a terminal redirection layer that wrote to both the screen and a table, though.
#3
Posted 07 September 2012 - 03:00 PM
I don't know how term.redirect works, could you possibly explain?
#4
Posted 07 September 2012 - 03:56 PM
I think he meant make your own print or redirect function that stores what is printed to the screen into a table to be read at a later date.
But, for the record, term.redirect() just pushes whatever is supposed to be typed to another source, usually a monitor (ie. term.redirect(mon)).
Also, this.
EDIT: Simple program is simplistic.
/>
But, for the record, term.redirect() just pushes whatever is supposed to be typed to another source, usually a monitor (ie. term.redirect(mon)).
Also, this.
hiddenTab = {}
function myWrite(whatRite)
local hiddenStr = ""
x, y = term.getCursorPos()
for i = 1, y do
hiddenStr = hiddenStr .. "n"
end
for i = 1, x do
hiddenStr = hiddenStr .. " "
end
hiddenStr = hiddenStr .. whatRite
hiddenTab[#hiddenTab+1] = hiddenStr
term.write(whatRite)
end
EDIT: Simple program is simplistic.
#5
Posted 07 September 2012 - 04:25 PM
I think I have figured it out, what you do is make a table of functions like so:
then you define your custom functions
which replaces the ones already on the function list. then finally
problem is making functions to accurately store the information because read() writes out the line again every time you press a key so you end up with an enormous table. any ideas on how to manage it?
funcs={}
record={}
for k,v in pairs(term.native) do
funcs[k]=v
end
then you define your custom functions
record={}
funcs.write=function(...) table.insert(record,...) return turtle.native.write(...) end
which replaces the ones already on the function list. then finally
term.redirect(funcs)
problem is making functions to accurately store the information because read() writes out the line again every time you press a key so you end up with an enormous table. any ideas on how to manage it?
#6
Posted 07 September 2012 - 04:31 PM
Yes, store each line in a table - and edit the line when the write command is called.
#7
Posted 07 September 2012 - 04:52 PM
an interesting idea, so far I have
and then to restore that window you call
and it rewrites everything, its quite cool to execute
but include something to only sleep if the write command is executed for better effect
EDIT: or even better just make it not sleep for any clear functions so a moving cursor is also animated
funcs={}
record={}
for k,v in pairs(term.native) do
funcs[k]=function(...) table.insert(record,{v,[2]={...}}) return v(...) end
funcs[k..'2']=v
end
term.redirect(funcs)
and then to restore that window you call
for k,v in pairs(record) do v[1](unpack(v[2])) sleep(0) end
and it rewrites everything, its quite cool to execute
term.clear() --you can store an alternate clear function in the func table so it won't call again if you like... up to you for k,v in pairs(record) do v[1](unpack(v[2])) sleep(0.1) end
but include something to only sleep if the write command is executed for better effect
EDIT: or even better just make it not sleep for any clear functions so a moving cursor is also animated
#8
Posted 07 September 2012 - 05:02 PM
You can check the screen api I made for MysticOS, it lets you get a character or line from the console. It works by saving the text on a table (like you did) and the cursor position so you know where to write. It also supports writing to multiple outputs (terminal and monitors).
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











