Advertisement
AKopyl

.menu

Dec 6th, 2017
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.60 KB | None | 0 0
  1. require('config')
  2.  
  3. local version = 1.2
  4. local DISK_SIDE = 'bottom'
  5. local W, H = term.getSize()
  6. local totalSpace = 2097152
  7. local totalSpaceFloppy = 524288
  8. local freeSpace = fs.getFreeSpace('/')
  9.  
  10. local debug = false
  11.  
  12. local selected = 1
  13.  
  14. choice = {}
  15. function addChoice(name, path, spacer)
  16.     choice[#choice+1] = {}
  17.     choice[#choice].name = name
  18.     choice[#choice].path = path
  19. end
  20.  
  21. setup_menu()
  22.  
  23. local timeout = os.startTimer(1)
  24.  
  25. while true do
  26.     local dt = 0   
  27.  
  28.     term.clear()
  29.  
  30.     term.setCursorPos(1, 1)
  31.     term.write('bubOS 2019 v'..version)
  32.     term.setCursorPos(W-4, 1)
  33.     term.write(textutils.formatTime(os.time(), true))
  34.  
  35.     term.setCursorPos(W-tostring(freeSpace..'B / '..totalSpace..'B free'):len(), H-1)
  36.     term.write(freeSpace..'B / '..totalSpace..'B free')
  37.     term.setCursorPos(1, H-1)
  38.     term.write('[')
  39.     for n = 1, W/2-2 do
  40.         if n < (W/2-2)*(totalSpace-freeSpace)/totalSpace then
  41.             term.write('|')
  42.         end
  43.     end
  44.     term.setCursorPos(W/2, H-1)
  45.     term.write(']')
  46.    
  47.     if disk.isPresent(DISK_SIDE) and disk.hasData(DISK_SIDE) then
  48.         term.setCursorPos(W-tostring(fs.getFreeSpace('disk')..'B / '..totalSpaceFloppy..'B free'):len(), H)
  49.         term.write(fs.getFreeSpace('disk')..'B / '..totalSpaceFloppy..'B free')
  50.         term.setCursorPos(W/4, H)
  51.         term.write('disk')
  52.         term.setCursorPos(1, H)
  53.         term.write('[')
  54.         for n = 1, W/2-2 do
  55.             if n < (W/2-2)*(totalSpaceFloppy-fs.getFreeSpace('disk'))/totalSpaceFloppy then
  56.                 term.write('|')
  57.             end
  58.         end
  59.         term.setCursorPos(W/2, H)
  60.         term.write(']')
  61.     end
  62.  
  63.     for n = 1, #choice do
  64.         term.setCursorPos(W/2+3-choice[n].name:len(), (H-#choice)/2+n-1)
  65.         term.write(choice[n].name)
  66.         if n == selected then
  67.             term.write(' <-')
  68.         end
  69.     end
  70.  
  71.     term.setCursorPos(1, H)
  72.     if debug then
  73.         term.write('['..selected..'] '..choice[selected].path)
  74.     end
  75.    
  76.     local event = {os.pullEvent()}
  77.  
  78.     if event[1] == 'key' then
  79.         if event[2] == keys.up then
  80.             selected = selected - 1
  81.         elseif event[2] == keys.down then
  82.             selected = selected + 1
  83.         end
  84.         if selected > #choice then
  85.             selected = 1
  86.         end
  87.         if selected < 1 then
  88.             selected = #choice
  89.         end
  90.    
  91.         if event[2] == 28 then
  92.             shell.run(choice[selected].path)
  93.             return
  94.         end
  95.  
  96.         if event[2] == 50 then
  97.             term.clear()
  98.             term.setCursorPos(1, 1)
  99.             peripheral.wrap('top').setTextScale(0.5)
  100.             shell.run('monitor top', choice[selected].path)
  101.             return
  102.         end
  103.  
  104.         if event[2] == 59 then
  105.             debug = not debug
  106.         end
  107.     elseif event[1] == 'monitor_touch' or event[1] == 'mouse_click' then
  108.         --shell.run(choice[selected].path)
  109.         --return
  110.     elseif event[1] == 'timer' and event[2] == timeout then
  111.         timeout = os.startTimer(1)
  112.     end
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement