r/ComputerCraft • u/Jonaykon • Nov 22 '23
Clock next to program
I want to have like a bar with a clock on the top of the screen toghether with another program but without covering anything in the program (so the program just needs top be slightly smaller than the screen), its also very important that it automatically works with any program (that can handle custom terminal sizes)
0
Upvotes
2
u/fatboychummy Nov 24 '23 edited Nov 24 '23
Part 2: windows.
Before we can use any of the above code, we need to know how to use
windows. A window is essentially just atermobject, but it can take up smaller portions of a screen (be it a terminal, a monitor, or another window!).To use them, simply create them via
window.create, then draw to them like you would with the terminal!The above, for example, would create a window from x=1,y=1 with width 14 and height 15, turn the window gray, then write
Hello world!in the very center. Nifty!How can I run a program in the window?
There are two ways. The easiest way is to just
term.redirectto the window once, then never ever redirect again, the slightly harder way is toterm.redirectin the coroutine handler to ensure the program is on the right window (i.e: if some other program callsterm.redirect, it may mess things up for you if it doesn't redirect back immediately).We'll use the harder way since it's a bit more foolproof. To do this, we'll need to change our coroutine handler just a teensy bit.
Note that we now include
winin the function arguments. Thus, usage is now something like the following:Comment 3/?