Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

filEx

AKopyl Dec 7th, 2017 (edited) 95 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. W, H = term.getSize()
  2.  
  3. selected = 1
  4. scroll = 0
  5.  
  6. currentPath = ''
  7.  
  8. fileList = fs.list(currentPath)
  9.  
  10. while true do
  11.     term.clear()
  12.    
  13.     term.setCursorPos(3, 1)
  14.     term.write('name')
  15.     term.setCursorPos(W-15, 1)
  16.     term.write('dir')
  17.     term.setCursorPos(W-10, 1)
  18.     term.write('size')
  19.     term.setCursorPos(1, 2)
  20.     for n = 1, W do
  21.         term.write('-')
  22.     end
  23.    
  24.     if #fileList > H-2 then
  25.         term.setCursorPos(W, 2+(H-2)*selected/#fileList)
  26.         term.write('#')
  27.     end
  28.  
  29.     term.setCursorPos(1, H)
  30.     if selected ~= 0 then
  31.         term.write(currentPath..'/'..fileList[selected])
  32.     end
  33.     term.setCursorPos(W-tostring(#fileList):len(), H)
  34.     term.write(#fileList)
  35.  
  36.     term.setCursorPos(1, selected+3-scroll)
  37.     for n = 1, W do
  38.         term.write('-')
  39.     end
  40.     term.setCursorPos(1, selected+3-scroll)
  41.     if selected == 0 or fs.isDir(currentPath..'/'..fileList[selected]) then
  42.         term.write('>>')
  43.     else
  44.         term.write('->')
  45.     end
  46.  
  47.     if 3-scroll < H and 3-scroll > 2 then
  48.         term.setCursorPos(3, 3-scroll)
  49.         term.write('..')
  50.     end
  51.    
  52.     for n, file in ipairs(fileList) do
  53.         if n+3-scroll < H and n+3-scroll > 2 then
  54.             term.setCursorPos(3, n+3-scroll)
  55.             term.write(file)
  56.            
  57.             if fs.isDir(currentPath..'/'..fileList[n]) then
  58.                 term.setCursorPos(W-16, n+3-scroll)
  59.                 term.write('[\\_/]')
  60.             end
  61.            
  62.             term.setCursorPos(W-10, n+3-scroll)
  63.             term.write(fs.getSize(currentPath..'/'..file))
  64.         end
  65.     end
  66.  
  67.     local event = {os.pullEvent()}
  68.  
  69.     if event[1] == 'key' then
  70.         if event[2] == keys.up then
  71.             selected = selected - 1
  72.         elseif event[2] == keys.down then
  73.             selected = selected + 1
  74.         end
  75.         if selected > #fileList then
  76.             selected = 0
  77.             scroll = 0
  78.         end
  79.         if selected < 0 then
  80.             selected = #fileList
  81.             if H+3 > #fileList then
  82.                 scroll = 0
  83.             else
  84.                 scroll = #fileList-H+3
  85.             end
  86.         end
  87.  
  88.         if selected-scroll > H-4 then
  89.             scroll = scroll + 1
  90.         end
  91.  
  92.         if selected-scroll < 0 then
  93.             scroll = scroll - 1
  94.         end
  95.  
  96.         if event[2] == 28 then
  97.             if selected == 0 then
  98.                 if currentPath ~= '' then
  99.                     currentPath = fs.combine(currentPath, '..')
  100.                     fileList = fs.list(currentPath)
  101.                 end
  102.             else
  103.                 if fs.isDir(currentPath..'/'..fileList[selected]) then
  104.                     currentPath = currentPath..'/'..fileList[selected]
  105.                     fileList = fs.list(currentPath)
  106.                     selected = 1
  107.                     scroll = 0
  108.                 else
  109.                     shell.run(currentPath..'/'..fileList[selected])
  110.                 end
  111.             end
  112.         end
  113.  
  114.         if event[2] == 19 then
  115.             if selected ~= 0 then
  116.                 term.clear()
  117.                 term.setCursorPos(1, 1)
  118.                 term.write('Are you sure you want to delete '..fileList[selected]..'?')
  119.                 term.write(' (y/n)')
  120.                 term.setCursorPos(1, 2)
  121.                 local input = read()
  122.                 if input == 'y' then
  123.                     shell.run('rm '..currentPath..'/'..fileList[selected])
  124.                     fileList = fs.list(currentPath)
  125.                     selected = 1
  126.                     scroll = 0
  127.                 elseif input ~= 'n' then
  128.                     term.setCursorPos(1, 3)
  129.                     term.write('Incorrect input!')
  130.                 end
  131.             end
  132.         end
  133.  
  134.         if event[2] == 18 then
  135.             if selected ~= 0 and not fs.isDir(currentPath..'/'..fileList[selected]) then
  136.                 shell.run('edit '..currentPath..'/'..fileList[selected])
  137.             end
  138.         end
  139.  
  140.         if event[2] == 50 then
  141.             if selected ~= 0 and not fs.isDir(currentPath..'/'..fileList[selected]) then
  142.                 term.clear()
  143.                 term.setCursorPos(1, 1)
  144.                 shell.run('monitor monitor_0', currentPath..'/'..fileList[selected])
  145.             end
  146.         end
  147.  
  148.         if event[2] == 16 then
  149.             shell.run('.menu')
  150.             return
  151.         end
  152.     elseif event[1] == 'monitor_touch' or event[1] == 'mouse_click' then
  153.         if event[4] < H-1 and event[4] > 2 then
  154.             if selected == event[4] - 3 then
  155.                 if selected == 0 then
  156.                     if currentPath ~= '' then
  157.                         currentPath = fs.combine(currentPath, '..')
  158.                         fileList = fs.list(currentPath)
  159.                     end
  160.                 else
  161.                     if fs.isDir(currentPath..'/'..fileList[selected]) then
  162.                         currentPath = currentPath..'/'..fileList[selected]
  163.                         fileList = fs.list(currentPath)
  164.                         selected = 1
  165.                     else
  166.                         shell.run(currentPath..'/'..fileList[selected])
  167.                     end
  168.                 end
  169.             else
  170.                 selected = event[4] - 3
  171.             end
  172.         end
  173.     end
  174. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top