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

How To Make Some Kind Of A Notifcation

Started by theeboris, 04 October 2013 - 07:53 AM
theeboris #1
Posted 04 October 2013 - 09:53 AM
Hello,

A few days ago I've got an idea. The idea is that I can run some code and write some things on the screen snd if the code is on the end the old screen restores. But I really don't know how to do that. Can anybody help me please?

~TheeBoris
Cranium #2
Posted 04 October 2013 - 11:23 AM
Lemme make sure I got this right…you want to run a block of code within another code, and when the new code block is run, you want to return to where you were?
What you want to do is run a redraw function to return you to where you were when you originally ran that first code.
theeboris #3
Posted 04 October 2013 - 12:17 PM
Yes :D/> Exactly that :D/> Do you know how I can do that? :)/>
Yevano #4
Posted 04 October 2013 - 08:41 PM
In startup, you could override the shell.run function to call term.restore before returning.
theoriginalbit #5
Posted 04 October 2013 - 09:35 PM
theeboris, when you run something such as a program with shell.run/os.run or even a function your program will return to that call and continue running, as such you can (as Cranium stated) create a redraw function which handles setting the screen back to your program's output.

local function redraw( extra )
  term.clear()
  term.setCursorPos(1,1)
  print("My awesome program")
  write("What is your poison? "..extra)
end

--# your program contents here
redraw()
local poison = read()

--# run the new program or call a function, or whatever
shell.run("poison", poison)

--# call the redraw, making it look back to where it was, maybe with some extra content too
redraw( poison..'\nHow did that feel? ' )

In startup, you could override the shell.run function to call term.restore before returning.
I think that either term.restore doesn't do what you think it does, or you're not understanding the OP's question.
Yevano #6
Posted 04 October 2013 - 09:57 PM
I think that either term.restore doesn't do what you think it does, or you're not understanding the OP's question.

Yeah, I think I was half answering his question and half answering someone else's question from another thread. :P/> The part about overriding shell.run, however, is still relevant, even if probably unnecessary for what OP is trying to do. Overriding would be useful if you wanted to do this in all instances, so that for example the shell wouldn't be cleared when you exit a program. You'd have to also override the term.write function to keep up with the draw buffer so that it can be saved and restored later (after shell.run exits).
theoriginalbit #7
Posted 04 October 2013 - 10:06 PM
Overriding would be useful if you wanted to do this in all instances, so that for example the shell wouldn't be cleared when you exit a program.
Not really. look


local function runProgram( path, ... )
  shell.run(path, ...)
  redraw()
end

done, then you just go


runProgram( "monitor", "left", "edit", "startup")

No override needed.
theeboris #8
Posted 05 October 2013 - 07:56 AM
theeboris, when you run something such as a program with shell.run/os.run or even a function your program will return to that call and continue running, as such you can (as Cranium stated) create a redraw function which handles setting the screen back to your program's output.
 local function redraw( extra ) term.clear() term.setCursorPos(1,1) print("My awesome program") write("What is your poison? "..extra) end --# your program contents here redraw() local poison = read() --# run the new program or call a function, or whatever shell.run("poison", poison) --# call the redraw, making it look back to where it was, maybe with some extra content too redraw( poison..'\nHow did that feel? ' ) 
In startup, you could override the shell.run function to call term.restore before returning.
I think that either term.restore doesn't do what you think it does, or you're not understanding the OP's question.

But if I do that I can't make a 'popup'if you know what I mean. Is it a possibility to redirect the screen to a virtual screen?
Yevano #9
Posted 05 October 2013 - 10:29 AM
But if I do that I can't make a 'popup'if you know what I mean. Is it a possibility to redirect the screen to a virtual screen?

As in, have a virtual screen in a specific area of the real monitor? Yeah, you could use Gopher's API. If you want to make it yourself, it would just require some overrides of the term functions, I think.
theeboris #10
Posted 05 October 2013 - 11:22 AM
I'm going to test it ;)/>