This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
codedHamster's profile picture

question about terminals

Started by codedHamster, 27 March 2013 - 03:13 AM
codedHamster #1
Posted 27 March 2013 - 04:13 AM
Hello, say I want to program that will run 2 programs simultaneously, by using split screen
Is it possible to make a program that limits another program's terminal?

for example I have a program like this:

term.setCursorPos(1, 1)
local w, h = term.getSize()
for i = 1, h do
    print(i)
end

can I make the program thinks that its terminal is starting at the top middle of the sceen?
and also is there a way to detect if the computer's screen size change? (computercraft emulator)
Brandhout #2
Posted 27 March 2013 - 06:37 AM
and also is there a way to detect if the computer's screen size change? (computercraft emulator)
Yes there is, it will throw a monitor_resize event

can I make the program thinks that its terminal is starting at the top middle of the sceen?
If you'd write such a program yourself, sure! I'd say you'd probably have to make some of you own version of the function write.
Kingdaro #3
Posted 27 March 2013 - 06:53 AM
The only way I would know of doing this is to basically rewrite every term function accordingly.


-- define a screen object that keeps our imaginary screen sizes
local screen = {
  x = 3, y = 2;
  width = 30;
  height = 10;
}

-- overwrite term.getSize to return the screen size and height
local getSize = term.getSize
function term.getSize()
  return screen.width, screen.height
end

-- overwrite term.setCursorPos to offset with the screen position
local setCursorPos = term.setCursorPos
function term.setCursorPos(x, y)
  setCursorPos(x + screen.x - 1, y + screen.y - 1)
end

Though I'm sure someone who has actually done sandboxing/windowing (e.g. Lyqyd) could provide a better answer than me.

and also is there a way to detect if the computer's screen size change? (computercraft emulator)
Yes there is, it will throw a monitor_resize event
No, that's for when a monitor resizes, not a terminal screen.
Lyqyd #4
Posted 27 March 2013 - 07:05 AM
Essentially, you just create a terminal redirection table for each "pane" that limits the output of each program to a certain area of the screen, then write a quick coroutine manager to redirect the terminal output when resuming each program's coroutine.

The terminal redirect table is just a table of the term functions, which you customize to fit your needs, such as returning a smaller screen size or writing only to a portion of the screen. Kingdaro has the essentials correct. Bear in mind that you need to trim output that would extend beyond the edge of the screen. You don't want one of the programs calling `term.write("areallydarnedlongstringthatprobablyistoolongforthrfullscreensizeletaloneacutdownscreensizeforusewithmultipledisplayareas")` and having it overwrite things in another part of your display.