Jump to content




Terminal redirection questions


  • You cannot reply to this topic
7 replies to this topic

#1 0099

  • Members
  • 52 posts

Posted 07 July 2014 - 06:55 PM

Please explain me, how is new term redirection system supposed to work?
1. I can't find any analogue for term.restore. term table itself "is not recommended redirect target", term.native is "do-not-use-unless-you-have-to" function, term.redirect(nil) is forbidden. What should I do?
2. I noticed that when a program that called term.redirect stops, it restores automatically (but the error message, if it exists, is sent to monitor).
2.1. Please, show me that piece of code that changes redirect targets back. I can't find it.
2.2. How i can prevent this thing from happening?

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 07 July 2014 - 07:09 PM

View Post0099, on 07 July 2014 - 06:55 PM, said:

Please explain me, how is new term redirection system supposed to work?
1. I can't find any analogue for term.restore. term table itself "is not recommended redirect target", term.native is "do-not-use-unless-you-have-to" function, term.redirect(nil) is forbidden. What should I do?
2. I noticed that when a program that called term.redirect stops, it restores automatically (but the error message, if it exists, is sent to monitor).
2.1. Please, show me that piece of code that changes redirect targets back. I can't find it.
2.2. How i can prevent this thing from happening?
as stated here, term.redirect now returns the previous term object when invoked. meaning you just redirect back to that.

local monitor = peripheral.wrap("left")
local oldTerm = term.redirect(monitor)

--# code here

term.redirect(oldTerm)

it has been this way since 1.6x

Edited by theoriginalbit, 07 July 2014 - 07:24 PM.
oops. thanks Lyqyd.


#3 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 07 July 2014 - 07:23 PM

You swapped redirect for restore in your response, theoriginalbit.

Edit: Also, this is compatible with both pre- and post-1.6:

local _old = term.redirect(target)

--# code here

if _old then
  term.redirect(_old)
else
  term.restore()
end


#4 0099

  • Members
  • 52 posts

Posted 08 July 2014 - 03:46 PM

Thanks. But what about the automatical restoring - what if I don't like it?
I mean, I could write a small program to redirect output:
-- file name: "redir"
local tArgs = { ... }
assert(type(tArgs[1]) == "string", "Usage: redir (side)")
term.redirect(peripheral.wrap(tArgs[1]))
It won't work.

And I still can't find - where exactly does this happen?

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 08 July 2014 - 03:54 PM

There is no 'automatic restoring' using your code example you would do the following

local args = {...}
assert(type(args[1]) == "string", "Usage: redir (side)")

--# anything printed here will output to whatever the term object was before your program started (normally this is the computer)

local oldTerm = term.redirect(peripheral.wrap(args[1]))

--# everything printed here will output to the wrapped peripheral

term.redirect( oldTerm )

--# everything printed here will print back on the term object that was active when your program started


#6 0099

  • Members
  • 52 posts

Posted 10 July 2014 - 02:37 PM

View Posttheoriginalbit, on 08 July 2014 - 03:54 PM, said:

There is no 'automatic restoring' using your code example you would do the following
(code here)
The thing is, if I do NOT write term.redirect(oldTerm), when the program stops and returns to the shell, the output will be redirected automatically to the original screen. (if the program causes an error, its error report goes to the monitor, and THEN it redirects back)

P.S. My original question was in beta discussion, so I tested all this in 1.64pr2. 1.64 is where I need it, because term.restore is gone. I'll test it in an earlier version.

EDIT: Tested it in 1.63 and got the same result.

Edited by 0099, 10 July 2014 - 02:41 PM.


#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 10 July 2014 - 02:53 PM

Are you testing on an advanced computer or a normal one? The multishell program may be part of the reason you're seeing redirection after a program exits.

#8 0099

  • Members
  • 52 posts

Posted 10 July 2014 - 03:25 PM

View PostLyqyd, on 10 July 2014 - 02:53 PM, said:

Are you testing on an advanced computer or a normal one? The multishell program may be part of the reason you're seeing redirection after a program exits.

On a normal computer.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users