Advertisement
Alakazard12

alOS

Nov 14th, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.00 KB | None | 0 0
  1. local sizeX, sizeY = term.getSize()
  2.  
  3. local color = colors.blue
  4.  
  5. local olds = term.getSize
  6. local oldp = term.setCursorPos
  7. local oldg = term.getCursorPos
  8. local oldw = term.write
  9. local oldc = term.clear
  10. local oldst = term.setTextColor
  11. local oldsc = term.scroll
  12. local olde = os.pullEvent
  13.  
  14. local dido = false
  15. local curcol = 1
  16. local shbl = true
  17.  
  18. local menu = {
  19.     ["Preferences"] = {};
  20.     ["Settings"] = {};
  21.     ["Update"] = {};
  22.     ["Shutdown"] = {};
  23.     ["Terminal"] = {};
  24.     ["Files"] = {};
  25. }
  26.  
  27. if not fs.exists("/home") then
  28.     fs.makeDir("/home")
  29. end
  30.  
  31. shell.setDir("home")
  32.  
  33. function round(num)
  34.     if num-math.floor(num) > 0.5 then
  35.         return math.ceil(num)
  36.     else
  37.         return math.floor(num)
  38.     end
  39. end
  40.  
  41. function clear()
  42.     term.clear()
  43.     term.setCursorPos(1, 1)
  44.     term.setTextColor(1)
  45. end
  46.  
  47. function os.pullEvent(req)
  48.     local e, p1, p2, p3, p4, p5, p6 = olde(req)
  49.     if e == "mouse_click" then
  50.         p3 = p3 - 2
  51.     elseif e == "mouse_scroll" then
  52.         p3 = p3 - 2
  53.     elseif e == "mouse_drag" then
  54.         p3 = p3 - 2
  55.     end
  56.     return e, p1, p2, p3, p4, p5, p6
  57. end
  58.  
  59. function term.setTextColor(col)
  60.     curcol = col
  61.     oldst(col)
  62. end
  63.  
  64. function term.clear()
  65.     oldc()
  66.     drawTop()
  67. end
  68.  
  69. --[[
  70. function term.write(txt)
  71.     local oldx, oldy = term.getCursorPos()
  72.     oldw(txt)
  73.     if dido == true then return end
  74.     drawTop()
  75.     dido = true
  76.     local newx, newy = term.getCursorPos()
  77.     term.setCursorPos(oldx, oldy)
  78.     term.write(string.sub(txt, 1, 1))
  79.     term.setCursorPos(newx, newy)
  80.     term.setTextColor(curcol)
  81.     dido = false
  82. end
  83. ]]
  84.  
  85. function term.scroll(num)
  86.     oldsc(num)
  87.     drawTop()
  88. end
  89.  
  90. function term.getCursorPos()
  91.     local x, y = oldg()
  92.     return x, y - 2
  93. end
  94.  
  95. function term.setCursorPos(x, y)
  96.     oldp(x, y + 2)
  97. end
  98.  
  99. function term.getSize()
  100.     local x, y = olds()
  101.     return x, y - 2
  102. end
  103.  
  104. function drawTop()
  105.     dido = true
  106.     local oldpx, oldpy = term.getCursorPos()
  107.     for i = 1, sizeX do
  108.         paintutils.drawPixel(i, -1, color)
  109.     end
  110.     term.setCursorPos(2, -1)
  111.     term.setTextColor(colors.lime)
  112.     term.write("Settings Files Shutdown")
  113.     local tm = os.time()
  114.     tm = round(tm*100)
  115.     tm = tm/2
  116.     tm = round(tm)
  117.     local mins = 0
  118.     local lped = 0
  119.     for i = 1, tm do
  120.         lped = lped + 1
  121.         if lped == 60 then
  122.             mins = mins + 1
  123.             lped = 0
  124.         end
  125.     end
  126.     tm = mins..":"..lped
  127.     term.setCursorPos(sizeX-#tm+1, -1)
  128.     term.write(tm)
  129.     paintutils.drawPixel(oldpx, oldpy, colors.black)
  130.     term.setCursorPos(oldpx, oldpy)
  131.     term.setTextColor(colors.orange)
  132.     for i = 1, sizeX do
  133.         term.setCursorPos(i, 0)
  134.         write("=")
  135.     end
  136.     paintutils.drawPixel(oldpx, oldpy, colors.black)
  137.     term.setTextColor(colors.white)
  138.     term.setCursorPos(oldpx, oldpy)
  139.     dido = false
  140. end
  141.  
  142. function drawList(title, list, num)
  143.     clear()
  144.     print(title.."\n")
  145.     for i,v in pairs(list) do
  146.         if i == num then
  147.             print("> "..v)
  148.         else
  149.             print("  "..v)
  150.         end
  151.     end
  152. end
  153.  
  154. function getKey()
  155.     local rt = nil
  156.     function tl()
  157.         local e, a1 = os.pullEvent("key")
  158.         if a1 == 200 then
  159.             rt = "up"
  160.         elseif a1 == 208 then
  161.             rt = "down"
  162.         elseif a1 == 28 then
  163.             rt = "enter"
  164.         else
  165.             tl()
  166.         end
  167.     end
  168.     tl()
  169.     repeat sleep(0) until rt ~= nil
  170.     return rt
  171. end
  172.  
  173. function ch(title, list, type)
  174.     clear()
  175.     local ind = 1
  176.     drawList(title, list, ind)
  177.     local rt = nil
  178.     cycle = function()
  179.         local ke = getKey()
  180.         if ke == "up" then
  181.             if ind > 1 then
  182.                 ind = ind - 1
  183.             else
  184.                 ind = #list
  185.             end
  186.             drawList(title, list, ind)
  187.             cycle()
  188.         elseif ke == "down" then
  189.             if ind < #list then
  190.                 ind = ind + 1
  191.             else
  192.                 ind = 1
  193.             end
  194.             drawList(title, list, ind)
  195.             cycle()
  196.         elseif ke == "enter" then
  197.             rt = ind
  198.         end
  199.     end
  200.     cycle()
  201.     repeat sleep(0) until rt ~= nil
  202.     return ind
  203. end
  204.  
  205. function dtime()
  206.     while true do
  207.         sleep(1)
  208.         drawTop()
  209.     end
  210. end
  211.  
  212. function f1()
  213.     term.clear()
  214.     term.setCursorPos(1, 1)
  215.     local newc = {}
  216.     for i,v in pairs(menu) do
  217.         table.insert(newc, i)
  218.     end
  219.     local pc = ch("Main menu", newc)
  220.     ch("List", menu[newc[pc]])
  221.     term.clear()
  222.     term.setCursorPos(1, 1)
  223.     shell.run("shell")
  224. end
  225.  
  226.  
  227. clear()
  228.  
  229. parallel.waitForAny(f1, dtime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement