Advertisement
HawkPB

Untitled

Aug 1st, 2024 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. --filax
  2. local component=require("component")
  3. local gpu=component.gpu
  4. local shell=require"shell"
  5. local event=require"event"
  6. local unicode=require"unicode"
  7. local fs = require"filesystem"
  8. local width,height=gpu.getResolution()
  9.  
  10.  
  11. local buttons={}
  12. function addButton(x,y,callback)
  13. table.insert(buttons,{x=x,y=y,c=callback})
  14. end
  15.  
  16. function clearScreen()
  17. gpu.fill(1,1,width,height," ")
  18. end
  19. function setbg(c) gpu.setBackground(c) end
  20. function setfg(c) gpu.setForeground(c) end
  21.  
  22. function drawTopBar(color,title)
  23. setbg(color)
  24. setfg(0xFFFFFF)
  25. gpu.fill(1,1,width,1," ")
  26. gpu.set(width/2-string.len(title)/2,1,title)
  27. setbg(0xFF0000)
  28. gpu.set(width,1,"x")
  29. addButton(width,1,function()
  30. setbg(0x000000)
  31. clearScreen()
  32. os.exit()
  33. end)
  34. setbg(0x00FF00)
  35. gpu.set(width-1,1,"↻")
  36. addButton(width-1,1,function()
  37. shell.execute("pastebin get znAFQAdd "..shell.getWorkingDirectory().."/filax.lua -f")
  38. shell.execute("lua "..shell.getWorkingDirectory().."/filax.lua")
  39. setbg(0x000000)
  40. clearScreen()
  41. io.exit()
  42. end)
  43. end
  44. function rgbToHex(r, g, b)
  45. r = math.min(255, math.max(0, r))
  46. g = math.min(255, math.max(0, g))
  47. b = math.min(255, math.max(0, b))
  48. local hexR = string.format("%02X", r)
  49. local hexG = string.format("%02X", g)
  50. local hexB = string.format("%02X", b)
  51. return "#" .. hexR .. hexG .. hexB
  52. end
  53.  
  54. setbg(0x584475)
  55. clearScreen()
  56. drawTopBar(0x7f8182,"Filax")
  57. setbg(0x423357)
  58. gpu.fill(5,3,4,4," ")
  59. setbg(0x584475)
  60.  
  61. function folderSize(path)
  62. local count = 0
  63. for entry in fs.list(path) do
  64. count = count + 1
  65. end
  66. return count
  67. end
  68. gpu.set(5,5,"┌─root")
  69. local xindx=1
  70. local globalm=5
  71. local globalfamt=0
  72. function searchDir(path, indx,famt)
  73. if fs.isDirectory(path) then
  74. local numEntries = folderSize(path)
  75. local forIndex=0
  76. for e in fs.list(path) do
  77.  
  78. forIndex=forIndex+1
  79. globalm = globalm + 1
  80. local concated=fs.concat(path,e)
  81. local len=unicode.wlen(famt)
  82. if fs.isDirectory(concated) then
  83. if forIndex == numEntries then
  84. if(folderSize(concated)==0) then
  85. gpu.set(4 + indx-len, globalm, famt.."└──" .. e)
  86. else
  87. gpu.set(4 + indx-len, globalm, famt.."└┬─" .. e)
  88. searchDir(fs.concat(path,e),indx+1,famt.." ")
  89. end
  90. else
  91. if(folderSize(concated)==0) then
  92. gpu.set(4 + indx-len, globalm, famt.."├──" .. e)
  93. else
  94. gpu.set(4 + indx-len, globalm, famt.."├┬─" .. e)
  95. searchDir(fs.concat(path,e),indx+1,famt.."│")
  96. end
  97.  
  98. end
  99.  
  100. else
  101. if forIndex == numEntries then
  102. gpu.set(4 + indx-len, globalm, famt.."└─"..e)
  103.  
  104. else
  105. gpu.set(4 + indx-len, globalm, famt.."├─"..e)
  106.  
  107. end
  108. end
  109.  
  110.  
  111. end
  112. end
  113. end
  114.  
  115. searchDir("home/projects",1,"")
  116. setbg(0x51476e)
  117. while true do
  118. local eventType, _, x, y = event.pull("touch")
  119. if eventType == "touch" then
  120.  
  121. for _, button in ipairs(buttons) do
  122.  
  123. if x==button.x and y==button.y then
  124.  
  125. button.c()
  126. end
  127. end
  128. end
  129. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement