by BigTwisty
Have you ever found some files just too big to comfortably view on a standard computer screen? This simple but handy program allows you to use large monitors to display those big files without having to use the computer to navigate. Simply click the top half of the monitor to scroll up a screen, or the bottom half to scroll down. I found this to work best on a 4x4 monitor: anything larger and the scrolling kind of goofs up. But hey, 4x4 is still WAY better than that tiny computer screen!
download: http://pastebin.com/Ue3MeGhX
pastebin get Ue3MeGhX previewOn
previewOn requires an advanced monitor because it relies on monitor_touch to scroll the text. Because the "preview" program, which this uses for display, does not support "monitor_resize" I had to end the program on such an event.
This was my first attempt at limited multi-threading using coroutine, and as such it is fairly simple. It basically loads the "preview" program in a coroutine, and then translates events to make "preview" do what we want it to.
Code:
Spoiler
args = {...}
if #args < 2 then
print("Usage: readOn <direction> <filename>")
return
end
if not fs.exists(shell.resolve(args[2])) then
print("File does not exist: ",args[2])
return
end
if peripheral.getType(args[1])~="monitor" then
print("No monitor in direction: ",args[1])
return
end
local reader = coroutine.create( function()
shell.run("preview", args[2])
end )
function sendEvent(...)
coroutine.resume(reader, ...)
end
local mon = peripheral.wrap(args[1])
if not mon.isColor() then
print("previewOn requires an advanced monitor.")
return
end
mon.setTextScale(0.5)
_,height = mon.getSize()
midscreen = height / 2
print("Reading ", args[2], " on ", args[1], " monitor.")
print("Click top half to scroll up, bottom to scroll down.")
print("Press q to quit")
term.redirect(mon)
sendEvent()
while coroutine.status(reader)~="dead" do
e = { os.pullEventRaw() }
if e[1] == "char" and e[2] == "q" or e[1] == "monitor_resize" then
sendEvent("key", 29)
sendEvent("key", 28)
elseif e[1] == "monitor_touch" then
dir = e[4] > midscreen and 1 or -1
for i=1,height-1 do
sendEvent("mouse_scroll",dir, 1,1)
end
sendEvent("mouse_click", 1, 1, 1)
else
sendEvent(unpack(e))
end
end
term.restore()
Edit: Any way I can change the title of the post? The program is called "previewOn" in accordance to standard Lua naming convention, not "Previewon" which just looks goofy!