Advertisement
BigSHinyToys

Experementtal light MouseFB

Nov 17th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.82 KB | None | 0 0
  1. --[[
  2.         Light weight mouse FB mini
  3.         by BigSHinyToys
  4. ]]--
  5. local bRun = true
  6. local sSlash = [[\]]
  7. local path = {}
  8. local tItemList = {}
  9. local hight,width = term.getSize()
  10. local listPos = -1
  11.  
  12. local function stringPath()
  13.     local temp = sSlash..table.concat(path,sSlash)
  14.     return temp
  15. end
  16.  
  17. local function newList()
  18.     listPos = -1
  19.     tItemList = {{n = "..", id = "back"}} -- adds a back item at top of list
  20.     sPath = stringPath()
  21.     local folders = {}
  22.     local files = {}
  23.     local disks = {}
  24.    
  25.     local test,list = pcall(fs.list,sPath)
  26.     if list == nil then
  27.         list = {}
  28.     end
  29.     if #path == 0 then
  30.         for i,v in pairs(rs.getSides()) do
  31.             if disk.isPresent(v) then
  32.                 if disk.hasData(v) then
  33.                     table.insert(tItemList,{n = disk.getMountPath(v), id = "disk",s = v})
  34.                     disks[disk.getMountPath(v)] = true
  35.                 elseif disk.hasAudio(v) then
  36.                     table.insert(tItemList,{n = disk.getAudioTitle(v), id = "audio",s = v})
  37.                 end
  38.             end
  39.         end
  40.     end
  41.     for i,v in pairs(list) do
  42.         if fs.isDir(sPath..sSlash..v) then
  43.             table.insert(folders,v)
  44.         else
  45.             table.insert(files,v)
  46.         end
  47.     end
  48.     table.sort(folders)
  49.     table.sort(files)
  50.     for i,v in pairs(folders) do
  51.         if disks[v] == nil then
  52.             table.insert(tItemList,{n = v, id = "folder"})
  53.         end
  54.     end
  55.     for i,v in pairs(files) do
  56.         table.insert(tItemList,{n = v, id = "file"})
  57.     end
  58. end
  59.  
  60. term.clear()
  61. newList()
  62.  
  63. local tIcons = {
  64.     back = {tCol = "lightGray",bCol = "blue",txt = " < "},
  65.     disk = {tCol = "lightGray",bCol = "blue",txt = "[*]"},
  66.     audio = {tCol = "yellow",bCol = "red",txt = "(o)"},
  67.     folder = {tCol = "lightGray",bCol = "blue",txt = "[=]"},
  68.     file = {tCol = "lime",bCol = "green",txt = "   "}
  69. }
  70.  
  71. while bRun do
  72.     term.setBackgroundColor(colors.cyan)
  73.     term.clear()
  74.     for i = 1,hight do
  75.         term.setCursorPos(1,i)
  76.         local sel = i+listPos
  77.         if tItemList[sel] then
  78.             term.setBackgroundColor(colors[tIcons[tItemList[sel].id].bCol])
  79.             term.setTextColor(colors[tIcons[tItemList[sel].id].tCol])
  80.             term.write(tIcons[tItemList[sel].id].txt..tItemList[sel].n)
  81.         end
  82.     end
  83.     term.setBackgroundColor(colors.lightBlue)
  84.     term.setTextColor(colors.blue)
  85.     term.setCursorPos(1,1)
  86.     term.write(stringPath())
  87.     local event = {os.pullEvent()}
  88.     if event[1] == "mouse_scroll" then
  89.         listPos = listPos + event[2]
  90.     elseif event[1] == "mouse_click" then
  91.         if event[2] == 1 then -- left click
  92.             local itemNumber = event[4] + listPos -- to keep it neat
  93.             if tItemList[itemNumber] then
  94.                 if tItemList[itemNumber].id == "folder" or tItemList[itemNumber].id == "disk" then
  95.                     table.insert(path,tItemList[itemNumber].n)
  96.                     newList()
  97.                 elseif tItemList[itemNumber].id == "file" then
  98.                     os.run(getfenv(),stringPath()..sSlash..tItemList[itemNumber].n)
  99.                 elseif tItemList[itemNumber].id == "back" then
  100.                     table.remove(path,#path)
  101.                     newList()
  102.                 end
  103.             end
  104.         else -- right click
  105.         end
  106.     end
  107. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement