Advertisement
Guest User

menu.lua

a guest
Jun 24th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. local term = require("term")
  2. local fs = require("filesystem")
  3. local comp = require("component")
  4. local computer = require("computer")
  5. local key = require("keyboard")
  6. local event = require("event")
  7. local gpu = comp.gpu
  8.  
  9. resx, resy = gpu.getResolution()
  10. halfresx = math.floor(resx/2)
  11. halfresy = math.floor(resy/2)
  12. quarterresx = math.floor(halfresx/2)
  13. quarterresy = math.floor(halfresy/2)
  14.  
  15. src = 0
  16.  
  17. function printMenu()
  18.  
  19.   term.clear()
  20.   if src == 0 then
  21.     term.setCursor(quarterresx+2,halfresy-2)
  22.     print("[Continue Normally]")
  23.   else
  24.     term.setCursor(quarterresx+3,halfresy-2)
  25.     print("Continue Normally")
  26.   end
  27.   if src == 1 then
  28.     term.setCursor(quarterresx+2,halfresy) -- Will need to change this
  29.     print("[Display Information]")
  30.   else
  31.     term.setCursor(quarterresx+3,halfresy)
  32.     print("Display Information")
  33.   end
  34.   if src == 2 then
  35.     term.setCursor(quarterresx+2,halfresy+2)
  36.     print("[Shutdown Computer]")
  37.   else
  38.     term.setCursor(quarterresx+3,halfresy+2)
  39.     print("Shutdown Computer")
  40.   end
  41.  
  42.    _,_,_,kn = event.pull("key_down")
  43.  
  44.   if kn == 208 then
  45.     if src == 0 then
  46.       src = src +1
  47.     elseif src == 1 then
  48.       src = src +1
  49.     end
  50.   elseif kn == 200 then
  51.     if src == 1 then
  52.       src = src -1
  53.     elseif src == 2 then
  54.       src = src -1
  55.     end
  56.   end
  57.   if kn == 28 then
  58.     if src == 0 then
  59.       term.clear()
  60.       os.exit()
  61.     elseif src == 1 then
  62.       printInfo()
  63.     elseif src == 2 then
  64.       computer.shutdown()
  65.     end
  66.   end
  67.   printMenu()
  68. end
  69.  
  70. function printInfo()
  71.   id = event.timer(0.5,printMem,math.huge)
  72.   term.clear()
  73.   term.setCursor(quarterresx+2,halfresy-2)
  74.   print("Free Memory: " ..computer.freeMemory()/1024 .. "kb")
  75.   term.setCursor(quarterresx+2,halfresy)
  76.   print("Installed memory: " .. computer.totalMemory()/1024 .. "kb")
  77.   term.setCursor(quarterresx+5,halfresy+2)
  78.   event.pull("key_down")
  79.   event.cancel(id)
  80. end
  81.  
  82. function printMem()
  83.   term.setCursor(quarterresx+2,halfresy-2)
  84.   print("Free Memory: " .. computer.freeMemory()/1024 .. "kb")
  85. end
  86.  
  87. printMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement