Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.setCursorBlink(true)
- local windows = {}
- local screens = {}
- local pers = peripheral.getNames()
- for i,name in pairs(pers) do
- if peripheral.getType(name)=='monitor' then
- screens[name] = peripheral.wrap(name)
- end
- end
- screens.term = term.current()
- local function filterEventPos(win,event)
- if event[3]>=win.x1 and
- event[3]<=win.x2 and
- event[4]>=win.y1 and
- event[4]<=win.y2 then
- return {
- event[1],
- event[2],
- event[3]-win.x1+1,
- event[4]-win.y1+1
- }
- end
- return nil
- end
- local function filterEvent(win,event)
- if event[1]=='mouse_click' or
- event[1]=='mouse_up' or
- event[1]=='mouse_scroll' or
- event[1]=='mouse_drag' then
- if win.monitor=='term' then
- return filterEventPos(win,event)
- end
- elseif event[1]=='monitor_touch' then
- if event[2]==win.monitor then
- return filterEventPos(win,event)
- end
- end
- return event
- end
- local function run(program,monitor,x,y,w,h,visible,floating)
- local win = window.create(screens[monitor],x,y,w,h,visible)
- local co = coroutine.create(function()
- os.run({shell=shell},program)
- end)
- local id
- id = coman.run(function()
- term.redirect(win)
- win.restoreCursor()
- local _,filter = coroutine.resume(co)
- repeat
- local event = {coroutine.yield(filter)}
- event = filterEvent(windows[id],event)
- if event then
- win.restoreCursor()
- term.redirect(win)
- local _,filter = coroutine.resume(co,unpack(event))
- end
- until coroutine.status(co)=='dead'
- windows[id] = nil
- end)
- windows[id] = {
- win = win,
- floating = floating,
- visible = visible,
- monitor = monitor,
- x1 = x,
- y1 = y,
- x2 = x+w-1,
- y2 = y+h-1
- }
- end
- winman = {
- screens = screens,
- run = run
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement