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

Mirror Utility Program - Contents Of Computer Screen On Monitor. v2

Started by Wojbie, 08 November 2013 - 01:49 PM
Wojbie #1
Posted 08 November 2013 - 02:49 PM
Mirror Utility Program - Contents of Computer Screen On Monitor. v2.1

Mirror program allows you to copy contents of standard computer onto nearby screen. This allows for easy access to screen while having big monitor showing you exactly whats happening. Original version was created from standard monitor program. Since then it had many transformations.

Download Here: http://pastebin.com/DW3LCC3L
Or ingame by using command:
pastebin get DW3LCC3L mirror
(requires http-api to be active)

Features List:
  • Duplicates contents of screen in perfect fashion onto monitor
  • All monitor_touch event get transformed into mouse_click 1 events with translated coordinates.
  • Nice border to mark where screen ends. Also unused sides are nicely grayed out.
  • Handles term.redirect()!!! Attempts to resize mirror screen to fit new term target size. If not get as close as it can. Also if term.target is a monitor reacts to resizing of that monitor too.
  • Reacts to resizes of mirror monitor and attempts to keep it operational
  • For more that one mirror you can chain program. Command
    
    mirror monitor_0 mirror monitor_1 test
    
    Will mirror contents of terminal on both monitor_0 and monitor_1. They can be completely different sizes.
Screenshots:
Spoiler




As always i attach picture of bTetris morrored from term to a monitor!! It's still awesome game take a look at it! This image also shows chained mirrors.


This program is perfect when you want to show something to group of people and don't want them to mess with console.


Change-log:
Spoilerv1.0 - Release On Apis and Utility Sub-forum - First Relase
v1.1 - Term.redirect() handling and monitor_resize handling
v1.2 - Finalized Term.redirect() handling - its almost perfect now!
v2.0 - Total rewrite for new CC redirection system.
v2.1 - Bugfix with creation of terminal object. Thanks Bomb Bloke !


Future Plans:
SpoilerNone - v2 was made as side effect of me working on my own terminal objects api. To be released soon : RedirectToTerminalGlasses, RedirectToSmartHelmet, RedirectToWebsite

Old version:
SpoilerWarning: This program version was made for old version of ComputerCaft and will not work on current generation.


Mirror Utility Program - Contents of Computer Screen On Monitor. v1.2

Mirror program allows you to copy contents of standard computer onto nearby screen. This allows for easy acces to screen while having big monitor showing you exactly whats happening. It was created from standard monitor program.

Download Here: http://pastebin.com/pCtnxcWv
Or ingame by using command:
pastebin get pCtnxcWv mirror
(requires http-api to be active)

Features List:
  • Duplicates contents of screen in perfect fashion onto monitor
  • All monitor_touch event get transformed into mouse_click 1 events with translated coordinates. If you still want to receive raw monitor_touch events use flag" -t". If you don't want to receive mouse_click events use flag "-c"
  • Nice border to mark where screen ends. you can use flag "-b" to remove it or "-a" to make it thicker.
  • Handles term.redirect()!!! Attempts to resize mirror screen to fit new term target size. If not get as close as it can. Also if term.target is a monitor reacts to resizing of that monitor too.
  • Reacts to resizes of mirror monitor and attempts to keep it operational
  • For more that one mirror you can chain program. Command
    
    mirror monitor_0 mirror monitor_1 test
    
    Will mirror contents of termina on both monitor_0 and monitor_1. They can be completely different sizes/ use different flags.





In this picture bTetris redirected term to a monitor but my mirror catch on and resized himself to match new term size!!


Example of chained call (more than one copy of terminal)


This program if perfect when you want to show something to group of people and don't want them to mess with console.

Any Comment and Suggestions how to improve Code are appreciated.
Edited on 19 October 2015 - 09:34 AM
Bomb Bloke #2
Posted 09 November 2013 - 08:34 PM
Pretty impressive. I'd been considering coding something like this functionality into the Tetris game itself - this handily saves me the trouble, and then some! :)/>/>

Things get a bit screwy if you try to resize a monitor while in use - though it would be difficult to counter that completely, at a glance I think it's supposed to at least clear the display before continueing, and in my tests it just used whatever the called script had set for the background colour to do that.

It crashes outright if it loses the monitor, and it seems it doesn't clear the monitor when you're done with it (or at least the border stays there)?

I wonder if you could rig this to direct the output to a computer (via rednet or whatever) instead of a monitor. That computer would forward it on to an actual monitor, and accept "redirects" from multiple computers at once (switching between the one it actually shows at random, or on redstone events etc). Having a large display in an arcade that alternates between what's happening on the different computers in the area would be pretty cool.
Edited on 09 November 2013 - 07:36 PM
Wojbie #3
Posted 09 November 2013 - 08:48 PM
As for monitor loosing crash i will add fix to it in later version. Resizing is giving me a bit of problems at the moment cause it needs to wait until next yeld before resizing in current code - i plan to fix that in next version. Your program is great testbed for it with that Awesome self-resizing code ;p

As you can see i started from Monitor code and have a bits and parts leftover from that (like all coroutine code)
I need to rework it so term.redirect and term.recover yield program and then resize contents.

As for directing output to computer via rednet that would require me to write whole new term api with virtual screen storage and stuff. Good idea but not possible with direction I am going with this program right now.

This program got written when i started working on arcade on server i play on - idea is that there will be bricked computers locked in games and this mirror will duplicate contents of said games on screens over booths - so each booth has 3x4 or 2x3 screen showing current game and one computer to play said game. and all that wired using modem cables to main comuputer allowing me to turn booths on and off.
Bomb Bloke #4
Posted 09 November 2013 - 11:58 PM
Thought of this, forgot it, then remembered it again:

Your script automatically resizes the monitor's text scale up to the largest it can while still fitting in the whole terminal display. You've probably noticed that my Tetris script does the exact same thing, but because it "knows" it only needs 50 columns (as opposed to the 51 available to the terminal) it'll scale up the text on a 5x3 monitor, whereas your mirroring tool waits for at least a 5x4 setup before enlarging.

It's probably a moot point for scripts that don't try to center themselves, but you might consider adding additional command line parameters to allow users to specify exactly how many columns/rows need to remain visible.
Edited on 09 November 2013 - 11:00 PM
Wojbie #5
Posted 10 November 2013 - 07:31 AM
Finished polishing term.redirect() handling. Now it should work in all situations. I want to thank yo Bomb Bloke. That tetris code proved to be great test bed for all capabilities of my program!

It's probably a moot point for scripts that don't try to center themselves, but you might consider adding additional command line parameters to allow users to specify exactly how many columns/rows need to remain visible.

Idea of Mirror is to show whole screen - not a cut off part - while good idea by itself it don't fit what i tried to achieve here.
Molinko #6
Posted 06 December 2013 - 09:37 PM
I have a handy suggestion if you think you'd like it I'd be hapy to see it!!
The program could have a cmd line flag like '-keyboard' or something.. that will bring up a touchscreen keyboard ether on the redirected monitor or on a second monitor just for input to the redirected program. Other than my HARSH JUDGEMENT ON YOU AS A PROGRAMMER, great job, looks very handy as is and well coded too :)/>.
p.s. PLZ take my suggestion if you have time to burn.. thanks
Zambonie #7
Posted 06 December 2013 - 11:20 PM
Seems very impressive! Ive been trying to figure out a way to do something like this for my program, and boom :D/>. There you are. I will check it out tomorrow.
Wojbie #8
Posted 07 December 2013 - 04:22 AM
I have a handy suggestion if you think you'd like it I'd be hapy to see it!!
The program could have a cmd line flag like '-keyboard' or something.. that will bring up a touchscreen keyboard ether on the redirected monitor or on a second monitor just for input to the redirected program. Other than my HARSH JUDGEMENT ON YOU AS A PROGRAMMER, great job, looks very handy as is and well coded too :)/>.
p.s. PLZ take my suggestion if you have time to burn.. thanks

Hmm i could add this. It would require monitor to be bit bigger for keyboard to fin under the frame. Will think on it.

Seems very impressive! Ive been trying to figure out a way to do something like this for my program, and boom :D/>. There you are. I will check it out tomorrow.

Hope you like it. Any feedback is welcome.
comp500 #9
Posted 23 December 2013 - 05:55 AM
Would it be possible to run one application on 2 monitors and use the Parallel api to run another on the main terminal? In my example I am making a cinema with 1 large monitor mirrored with a small monitor, and the main computer used to control everything. Would this be available as an API so that it can be easily incorporated into my program?
Wojbie #10
Posted 23 December 2013 - 04:22 PM
hmm i wrote it a long time ago when i wanted to copy monitor program functionality. There are some parts of code that would not translate correctly in api form (i know i was young and idiot in lua ways, ) I never considered making a api from this thing. While i think it can be done i also for-see problems with term.redirect causing a mess ;p Sadly i don't have a lot of time those day to fit this program up and make something like api from that. Anyone is welcome to try it ;p i might get on it when i have some free time.
Edited on 23 December 2013 - 03:23 PM
comp500 #11
Posted 24 December 2013 - 04:29 AM
hmm i wrote it a long time ago when i wanted to copy monitor program functionality. There are some parts of code that would not translate correctly in api form (i know i was young and idiot in lua ways, ) I never considered making a api from this thing. While i think it can be done i also for-see problems with term.redirect causing a mess ;p Sadly i don't have a lot of time those day to fit this program up and make something like api from that. Anyone is welcome to try it ;p i might get on it when i have some free time.
Thanks! I currently have it set up with monitor and mirror together outputting one program to 2 monitors but i need to be able to control the terminal itself.
trajing #12
Posted 24 December 2013 - 02:05 PM
Wow, this is amazing! I use it for my advanced monitor billboard.
comp500 #13
Posted 28 December 2013 - 11:55 AM
hmm i wrote it a long time ago when i wanted to copy monitor program functionality. There are some parts of code that would not translate correctly in api form (i know i was young and idiot in lua ways, ) I never considered making a api from this thing. While i think it can be done i also for-see problems with term.redirect causing a mess ;p Sadly i don't have a lot of time those day to fit this program up and make something like api from that. Anyone is welcome to try it ;p i might get on it when i have some free time.
Thanks! I currently have it set up with monitor and mirror together outputting one program to 2 monitors but i need to be able to control the terminal itself.
nvm - I found http://www.computercraft.info/forums2/index.php?/topic/5130-gophers-apis-new-ggui-beta-goroutine-redirect-ctrlkeys/page__pid__41117#entry41117 and managed to achieve what I wanted. Thanks anyway!
Mr_Programmer #14
Posted 09 January 2014 - 11:53 PM
how would i get this to work using wired modems hooked up to a computer and a monitor?

scratch that last comment i found it out and i cant get the display to go bigger as im using a 7x5 monitor and its only using like 5x4 :(/>
Lyqyd #15
Posted 10 January 2014 - 12:32 AM
You could try adjusting the text scale. Check the wiki for more information.
Wojbie #16
Posted 10 January 2014 - 01:52 AM
how would i get this to work using wired modems hooked up to a computer and a monitor?

scratch that last comment i found it out and i cant get the display to go bigger as im using a 7x5 monitor and its only using like 5x4 :(/>
You could try adjusting the text scale. Check the wiki for more information.

That would not work - program scales monitor on its own depending on needed size. Also its made for 100% perfect duplication of terminal - so it will leave empty space on sides when it finds best scale simply cause thats the best one it detected.
The5heep #17
Posted 08 May 2014 - 05:26 AM
This will not work in the 1.6 update. It has a problem with multishell and gives me an error 60% of the time. Please fix this it was sooooooo good when it worked!
Wojbie #18
Posted 08 May 2014 - 07:55 AM
Yes i realize its not working correctly in 1.6 due to the changes in redirection mechanisms. I am working on new improved version but its a little bit in future because of lack of time to code right now. Will update as soon as its ready. :D/>
The5heep #19
Posted 08 May 2014 - 08:41 PM
Yay!

When will the new version be out do you suppose?
SquidDev #20
Posted 08 May 2014 - 09:28 PM
I wonder if you could rig this to direct the output to a computer (via rednet or whatever) instead of a monitor. That computer would forward it on to an actual monitor, and accept "redirects" from multiple computers at once (switching between the one it actually shows at random, or on redstone events etc). Having a large display in an arcade that alternates between what's happening on the different computers in the area would be pretty cool.
As for directing output to computer via rednet that would require me to write whole new term api with virtual screen storage and stuff. Good idea but not possible with direction I am going with this program right now.
You could have a look at NSH (mostly the Framebuffer API). I think this uses term.redirect to achieve most of its functionality.
LewisTehMinerz #21
Posted 11 May 2014 - 05:26 PM
I downloaded your program and tryed running it but whatever i type it comes up with:

multishell:39: attempt to call nil

and then it shuts down the computer.

Why does it do this?
Wojbie #22
Posted 11 May 2014 - 05:41 PM
Yes i realize its not working correctly in 1.6 due to the changes in redirection mechanisms. I am working on new improved version but its a little bit in future because of lack of time to code right now. Will update as soon as its ready. :D/>
LewisTehMinerz #23
Posted 14 May 2014 - 04:46 PM
Yes i realize its not working correctly in 1.6 due to the changes in redirection mechanisms. I am working on new improved version but its a little bit in future because of lack of time to code right now. Will update as soon as its ready. :D/>
Thank You!
Luca_S #24
Posted 16 November 2014 - 12:14 PM
If i try to do this my PC crashes with always other errors(See this error list:

mirror monitor_0 edit test
multishell:39: attempt to call nil
mirror monitor_0 shell
shell:4 attempt to call nil

When i look at the specified lines its alway term.current(), is there a way to fix it?
TheOddByte #25
Posted 16 November 2014 - 01:03 PM
If i try to do this my PC crashes with always other errors(See this error list:

mirror monitor_0 edit test
multishell:39: attempt to call nil
mirror monitor_0 shell
shell:4 attempt to call nil

When i look at the specified lines its alway term.current(), is there a way to fix it?
Yes i realize its not working correctly in 1.6 due to the changes in redirection mechanisms.
I am working on new improved version but its a little bit in future because of lack of time to code right now.
Will update as soon as its ready. :D/>
How did you not see that?
Skullcut #26
Posted 30 December 2014 - 07:34 PM
Hey,

i have a problem, the size of the displayed content, doesn't resize..
Do i have to do a command for this?





LDDestroier #27
Posted 22 January 2015 - 10:15 PM
Hey, could you fix this for 1.6 as soon as possible? I'm trying to make a game room, and I get the multishell:39: problem
Bomb Bloke #28
Posted 23 January 2015 - 07:13 AM
It seems that if a line such as this one is added into the _G["term"] table defined around line 227:

["current"] = saveterm["current"],

… then it should otherwise work more or less "as-is". It won't play all that well with multishell, but it'll likely handle whatever job you're wanting it for so long as you don't try working with multiple tabs.
Wojbie #29
Posted 02 October 2015 - 12:19 AM
UPDATE! v2.0
  • Total Rewrite
  • Some features got removed due to lack of need. If requested they may come back
  • It works in new CC!
On side-note take a look at this project twin that just happened to be released at same time ye old time ago. bTetris is still awesome!
Bomb Bloke #30
Posted 03 October 2015 - 08:31 AM
Hmm… Is this you gearing up to work on this thing? ;)/>
Konlab #31
Posted 03 October 2015 - 10:36 AM
Hmm… Is this you gearing up to work on this thing? ;)/>/>/>
Hologram projector redirect :o/>/>
But with optional 3rd arg for setCursorPos
And more optional arguments for mouse_click event like z, side
More colors, too
It would be so cool!
Edited on 03 October 2015 - 08:37 AM
Wojbie #32
Posted 03 October 2015 - 11:20 AM
Hmm… Is this you gearing up to work on this thing? ;)/>

More like side effect of finalizing work on lua side of this thing and internal want to revive Mirror. But those holograms are on todo list for future. Now that i have made terminal handling side all i have to do is create term.blit that blits onto hologram using font stuff instead of onto terminal. rest of code would stay exactly the same. I just don't feel muse for hologram project atm.


On side note if any of you find any programs that are erroring with the mirror and working fine without it i would be grateful for info. At the moment all that errors for me is battleship treasure disk. And i am working on figuring out why.
Edited on 03 October 2015 - 09:36 AM
Konlab #33
Posted 03 October 2015 - 12:11 PM
-long post-
What about a hide-able on-screen keyboard with virtual mouse, where you can specify what type of mouse_click or mouse_scroll will be sent to the computer? And a terminate event sender and a paste event sender?
Toggle shift and toggle ctrl… for example for multiselection in (my filebrowser, see in my signature ;)/> ) Lattice…
It is already a great program and has great potencial.
Wojbie #34
Posted 03 October 2015 - 01:03 PM
What about a hide-able on-screen keyboard with virtual mouse, where you can specify what type of mouse_click or mouse_scroll will be sent to the computer? And a terminate event sender and a paste event sender?
Toggle shift and toggle ctrl… for example for multiselection in (my filebrowser, see in my signature ;)/> ) Lattice…

Well truthfully i consider this program done and finished. It has one job - copy terminal onto monitor. Mouse interaction is in cause it was easy to do and there was no point in not including it. And truthfully from my standpoint there is no need to reinvent the keyboard when there are many mods that already give you better keyboard that on-screen one could ever be. Like this per example.
Edited on 03 October 2015 - 11:04 AM
Bomb Bloke #35
Posted 03 October 2015 - 03:24 PM
At the moment all that errors for me is battleship treasure disk. And i am working on figuring out why.

You may have already gotten this sorted out, but I'm seeing the issue being triggered here:

--redirect just to block scroll
local redir={}
for k,v in pairs(originalTerm) do
  if k~="scroll" then
    redir[k]=v
  else
    redir[k]=function() end
  end
end
originalTerm = term.redirect(redir)

If something is available through a metatable, but is not actually in the table said metatable is built out of, then "pairs" won't see it. In this case, it believes "originalTerm" to be empty (because your createMultitable() function returns empty tables).
Wojbie #36
Posted 03 October 2015 - 03:36 PM
(because your createMultitable() function returns empty tables).

*Sound of Wojbie facepalming so hard that he falls out of chair*
I placed wrong createMultitable version in this program. Thanks a lot for that. On accident I placed fluid one instead of static one.
This one (fluid) was created for when tables inside multitable change a lot.
Will need to find where i put my static one and replace it.

Thanks for the help. I was looking for error in completely wrong place (function). Its right what they say. Sometimes you just need a pair of new eyes or a rubber duck so solve problems. ( and i may have lost Mr. Duckpants)
Edited on 16 January 2016 - 06:16 PM
Wojbie #37
Posted 03 October 2015 - 04:34 PM
UPDATE! v2.1
  • Bugfix with creation of terminal object.
On side-note: Yay i sunk that battleship. I mean bug. Thanks Bomb Bloke !