Terminal redirection to parts of the screen. Easilly create scrolling sidebars, status bars and other screen areas.
- Create sidebar text that scrolls independently of other panels
- Works seamlessly with write() and print() since it uses term.redirect()
You can see in the screen shot that the edit program is contained inside the new main panel and doesn't overwrite the sidebar text.
Install
pastebin get aibwRhj1 panel
http://pastebin.com/aibwRhj1
GitHub repo:
https://github.com/Forte40/panel
Usage
Load the API with
os.loadAPI("panel")
Create a new panel with specified left, top, width and height:
new_panel = panel.new(5, 5, 10, 10)
-- or --
new_panel = panel.new{x=5, y=5, w=10, h=10}
-- or with default values
new_panel = panel.new{x=1, w=20} -- y will be 1 and height will fill the screen
Update: Or use relative coordinates so you don't have to know the size of the screen. A negative number will use the width or height and count back.
-- panel to occupy 20 characters on the right
-- y and height are defaulted to 1 and height of screen
new_panel = panel.new{x=-20, w=20}
New panels should be activated. Activating switches from one panel to the other. write() and print() will display to the active panel.
new_panel:redirect() -- notice the colon operator
-- or --
panel.redirect(new_panel)
Panel redirects don't stack (unlike term.redirect). Restoring always returns you to the terminal or monitor panel you were on. Restore the normal input with:
term.restore()
-- or --
panel.restore()
This will work with monitors as well:
Spoiler
mon = peripheral.wrap("left")
term.redirect(mon)
sidebar = panel.new(1, 20, 20, 20)
sidebar:redirect()
-- remove panel redirect from monitor
panel.restore()
-- remove panel redirect from monitor
term.restore()
Here is the example script in the screen shot:
Spoiler
Update: I changed the new function syntax slightly, so this code no longer matches the screenshot.
os.loadAPI("panel")
-- create area for info
sidebar = panel.new{x=-12, w=12}
sidebar:redirect()
for k in pairs(term) do
print(k)
end
-- create new main area
main = panel.new{x=1, w=-13}
panel.redirect(main)