Advertisement
Guest User

winman

a guest
Feb 5th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. term.setCursorBlink(true)
  2. local windows = {}
  3. local screens = {}
  4.  
  5. local pers = peripheral.getNames()
  6. for i,name in pairs(pers) do
  7.   if peripheral.getType(name)=='monitor' then
  8.     screens[name] = peripheral.wrap(name)
  9.   end
  10. end
  11. screens.term = term.current()
  12.  
  13. local function filterEventPos(win,event)
  14.   if event[3]>=win.x1 and
  15.      event[3]<=win.x2 and
  16.      event[4]>=win.y1 and
  17.      event[4]<=win.y2 then
  18.     return {
  19.       event[1],
  20.       event[2],
  21.       event[3]-win.x1+1,
  22.       event[4]-win.y1+1
  23.     }
  24.   end
  25.   return nil
  26. end
  27.  
  28. local function filterEvent(win,event)
  29.   if event[1]=='mouse_click' or
  30.      event[1]=='mouse_up' or
  31.      event[1]=='mouse_scroll' or
  32.      event[1]=='mouse_drag' then
  33.     if win.monitor=='term' then
  34.       return filterEventPos(win,event)
  35.     end
  36.   elseif event[1]=='monitor_touch' then
  37.     if event[2]==win.monitor then
  38.       return filterEventPos(win,event)
  39.     end
  40.   end
  41.   return event
  42. end
  43.  
  44. local function run(program,monitor,x,y,w,h,visible,floating)
  45.   local win = window.create(screens[monitor],x,y,w,h,visible)
  46.   local co = coroutine.create(function()
  47.     os.run({shell=shell},program)
  48.   end)
  49.   local id
  50.   id = coman.run(function()
  51.     term.redirect(win)
  52.     win.restoreCursor()
  53.     local _,filter = coroutine.resume(co)
  54.     repeat
  55.       local event = {coroutine.yield(filter)}
  56.       event = filterEvent(windows[id],event)
  57.       if event then
  58.         win.restoreCursor()
  59.         term.redirect(win)
  60.         local _,filter = coroutine.resume(co,unpack(event))
  61.       end
  62.     until coroutine.status(co)=='dead'
  63.     windows[id] = nil
  64.   end)
  65.   windows[id] = {
  66.     win = win,
  67.     floating = floating,
  68.     visible = visible,
  69.     monitor = monitor,
  70.     x1 = x,
  71.     y1 = y,
  72.     x2 = x+w-1,
  73.     y2 = y+h-1
  74.   }
  75. end
  76.  
  77. winman = {
  78.   screens = screens,
  79.   run = run
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement