Advertisement
AquaJD

Window Coroutines Test

Feb 28th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. local bRunning = true
  2.  
  3. local window_key = window.create(term.native(),4,4,10,10,true)
  4. local window_shell = window.create(term.native(),18,4,10,10,true)
  5.  
  6. local function func1()
  7.   shell.run("/rom/programs/shell")
  8. end
  9.  
  10. local function func2()
  11.   shell.run("/rom/programs/shell")
  12. end
  13.  
  14. local activeWindow = window_key
  15.  
  16. local cor1 = coroutine.create(func1)
  17. local cor2 = coroutine.create(func2)
  18. while true do
  19.   local event = { os.pullEvent() }
  20.   if event[1] == "mouse_click" then
  21.     if event[3] >= 4 and event[3] <= 14 and event[4] >= 4 and event[4] <= 14 then
  22.       activeWindow = window_key
  23.     elseif event[3] >= 18 and event[3] <= 28 and event[4] >= 4 and event[4] <= 14 then
  24.       activeWindow = window_shell
  25.     end
  26.   elseif event[1] == "key" then
  27.     if event[2] == keys.space then
  28.       local _x,_y,_w,_h = activeWindow.getPosition()
  29.       activeWindow.reposition(_x+1,_y,_w,_h)
  30.       term.clear()
  31.       window_shell.redraw()
  32.       window_key.redraw()
  33.     end
  34.   end
  35.   term.redirect(activeWindow)
  36.   activeWindow.redraw()
  37.   if activeWindow == window_key then
  38.     coroutine.resume(cor1,unpack(event))
  39.   elseif activeWindow == window_shell then
  40.     coroutine.resume(cor2,unpack(event))
  41.   end
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement