Advertisement
LDDestroier

CC Workspaces (test)

Mar 8th, 2016
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. local scr_x,scr_y = term.getSize()
  2.  ws = {
  3.     window.create(term.current(),1,1,scr_x,scr_y,true),
  4.     window.create(term.current(),1,1,scr_x,scr_y,false),
  5.     window.create(term.current(),1,1,scr_x,scr_y,false),
  6.     window.create(term.current(),1,1,scr_x,scr_y,false),
  7. }
  8.  
  9. cws = 1
  10. wslength = 2
  11. swkey = keys.f1
  12.  
  13. local redrawCurrentWorkspace = function()
  14.     while true do
  15.         for a = 1, #ws do
  16.             ws[a].setVisible(a==cws)
  17.         end
  18. --      ws[cws].redraw()
  19.         sleep(0)
  20.     end
  21. end
  22.  
  23. term.redirect(ws[cws])
  24.  
  25. local getInput = function()
  26.     local isDown = false
  27.     while true do
  28.         local evt = {os.pullEvent()}
  29.         local didSwitch = false
  30.         if evt[1] == "key" then
  31.             if evt[2] == swkey then
  32.                 isDown = true
  33.             end
  34.             if isDown then
  35.                 if evt[2] == keys.left then
  36.                     if ws[cws-1] then
  37.                         didSwitch = true
  38.                         cws = cws - 1
  39.                     end
  40.                 elseif evt[2] == keys.right then
  41.                     if ws[cws+1] then
  42.                         didSwitch = true
  43.                         cws = cws + 1
  44.                     end
  45.                 elseif evt[2] == keys.up then
  46.                     if ws[cws-wslength] then
  47.                         didSwitch = true
  48.                         cws = cws - wslength
  49.                     end
  50.                 elseif evt[2] == keys.down then
  51.                     if ws[cws+wslength] then
  52.                         didSwitch = true
  53.                         cws = cws + wslength
  54.                     end
  55.                 end
  56.             end
  57.             if didSwitch then
  58.                 term.redirect(ws[cws])
  59.                 term.clear()
  60.             end
  61.         elseif evt[1] == "key_up" then
  62.             if evt[2] == swkey then
  63.                 isDown = false
  64.             end
  65.         end
  66.     end
  67. end
  68.  
  69. run = function()
  70.     local output = {}
  71.     for a = 1, #ws do
  72.         local f = function()
  73.             os.run(ws[a],"rom/programs/shell")
  74.         end
  75.         table.insert(output,f)
  76.     end
  77.     return output
  78. end
  79.  
  80.  
  81.  
  82. parallel.waitForAny(getInput, redrawCurrentWorkspace, table.unpack(run()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement