Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
Advertisement
Add Comment
Please, Sign In to add comment