Advertisement
Theshadow989

[xOS] Programs

Jan 7th, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. --[[
  2. Programs File
  3. Written by TheShadow989
  4. ]]--
  5.  
  6. os.pullEvent = os.pullEventRaw
  7.  
  8. local verNumber = "Alpha 1.24"
  9. local nOption = 1
  10.  
  11. rRead = fs.open("xos/.usertable", "r")
  12. users = textutils.unserialize(rRead.readAll())
  13. rRead.close()
  14. cu = tonumber(users[1])
  15. cs = tonumber(users[cu+1])
  16. cp = tonumber(users[cu+2])
  17.  
  18. local w,h = term.getSize()
  19.  
  20. local function drawMenu()
  21.         local time = os.time()
  22.         local formattedTime = textutils.formatTime(time, false)
  23.  
  24.         term.clear()
  25.         term.setCursorPos(1,1)
  26.         term.write("Logged in as: ")
  27.         term.setTextColor( colors.red )
  28.         term.write(""..users[cu].."")
  29.         term.setTextColor( colors.white )
  30.         term.setCursorPos(1,2)
  31.         write(formattedTime)
  32.         term.setCursorPos(1,19)
  33.         term.write("xOS "..verNumber.." by TheShadow989")
  34.        
  35.         term.setCursorPos(w-11,1)
  36.         if nOption == 1 then
  37.            term.write("Browser")
  38.         elseif nOption == 2 then
  39.            term.write("Unknown")
  40.         elseif nOption == 3 then
  41.            term.write("Unknown")
  42.         elseif nOption == 4 then
  43.            term.write("Unknown")
  44.         elseif nOption == 5 then
  45.            term.write("Page 2")
  46.         elseif nOption == 6 then
  47.            term.write("Back")
  48.         else
  49.         end
  50. end
  51.  
  52. function printCentered(y,s)
  53.         local x = math.floor((w - string.len(s)) / 2)
  54.         term.setCursorPos(x,y)
  55.         term.clearLine()
  56.         term.write( s )
  57. end
  58.  
  59. term.clear()
  60.  
  61. term.setCursorPos(1,19)
  62. term.write("xOS "..verNumber.." by TheShadow989")
  63.  
  64. local function drawFrontend()
  65.    printCentered( math.floor(h/2) - 4, "")
  66.    printCentered( math.floor(h/2) - 3, "Programs [Page 1 ]" )
  67.    printCentered( math.floor(h/2) - 2, "")
  68.    printCentered( math.floor(h/2) - 1, ((nOption == 1) and "[ Browser ]") or " Browser " )
  69.    printCentered( math.floor(h/2) + 0, ((nOption == 2) and "[ Unknown ]") or " Unknown " )
  70.    printCentered( math.floor(h/2) + 1, ((nOption == 3) and "[ Unknown ]") or " Unknown " )
  71.    printCentered( math.floor(h/2) + 2, ((nOption == 4) and "[ Unknown ]") or " Unknown " )
  72.    printCentered( math.floor(h/2) + 3, "")
  73.    printCentered( math.floor(h/2) + 4, ((nOption == 5) and "[ Page 2  ]") or " Page 2  " )
  74.    printCentered( math.floor(h/2) + 5, ((nOption == 6) and "[  Back   ]") or "  Back   " )
  75. end
  76.  
  77. drawMenu()
  78. drawFrontend()
  79.  
  80. while true do
  81.  local e,p = os.pullEvent()
  82.  if e == "key" then
  83.   local key = p
  84.   if key == 17 or key == 200 then
  85.  
  86.    if nOption > 1 then
  87.     nOption = nOption - 1
  88.     drawMenu()
  89.     drawFrontend()
  90.    end
  91.   elseif key == 31 or key == 208 then
  92.   if nOption < 6 then
  93.   nOption = nOption + 1
  94.   drawMenu()
  95.   drawFrontend()
  96. end
  97. elseif key == 28 then
  98.   break
  99. end
  100. end
  101. end
  102. term.clear()
  103.  
  104. if nOption  == 1 then
  105. shell.run("xos/.browser")
  106. elseif nOption == 2 then
  107. shell.run("xos/.reactor")
  108. elseif nOption == 3 then
  109. os.shutdown()
  110. elseif nOption == 4 then
  111. shell.run("xos/.UninstallDialog")
  112. elseif nOption == 5 then
  113. shell.run("xos/.programs2")
  114. elseif nOption == 6 then
  115. shell.run("back")
  116. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement