Advertisement
Guest User

Untitled

a guest
Jul 11th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1.  
  2. --[[---------
  3. ufie Browser
  4.  
  5. V 0.1
  6. --]]---------
  7.  
  8. local size = {term.getSize()} --//Terminal Size
  9. local root = "/" --//...Root?
  10. local oldRoot = "/" --//..Old Root?
  11. local selected --//Selected File
  12. local clipboard --//..I guess Its not a clipboard.
  13. local optS = 10 --//Size of the Menu
  14. local txColor = colors.gray --//I dont know where this came from, ima check it out later
  15. local cp = --//SLightly unused text colors. Ill remove them. One Day.
  16. {
  17. ["bar"] = colors.gray;
  18. ["bar2"] = colors.lightGray;
  19. ["menu"] = colors.lightGray;
  20. ["suc"] = colors.cyan;
  21. ["tBar"] = colors.white;
  22. ["fail"] = colors.red;
  23. ["tFile"] = colors.lightGray;
  24. ["tDir"] = colors.lime;
  25. }
  26.  
  27. local permOpt = --//The ol' options that stay. foreva.
  28. {
  29. "Copy";
  30. "Paste";
  31. }
  32. local fileOpt = --//Meh, Options for when A file is selected.
  33. {
  34. "Copy";
  35. "Delete";
  36. "Open";
  37. "Edit";
  38. "Rename";
  39. }
  40. local txtOpt = --//You guessed it.
  41. {
  42. "Copy";
  43. "Delete";
  44. "Open";
  45. "Rename";
  46. }
  47.  
  48. function drawGUI()
  49. term.setBackgroundColor(colors.white)
  50. term.clear()
  51.  
  52. paintutils.drawLine(1,1,size[1],1,cp.bar)
  53. paintutils.drawLine(1,2,size[1],2,cp.bar2)
  54.  
  55. for x = size[1], size[1]-optS, -1 do
  56. paintutils.drawLine(x, 3, x, size[2], cp.bar2)
  57. end
  58. paintutils.drawLine(size[1]-(optS+1), 3, size[1]-(optS+1), size[2], cp.bar)
  59.  
  60. term.setCursorPos(2, 1)
  61. term.setTextColor(cp.tBar)
  62. write("ufile")
  63. term.setCursorPos(size[1], 1)
  64. term.setTextColor(cp.fail)
  65. write("*")
  66.  
  67. paintutils.drawLine(1, size[2], size[1]-optS-1, size[2], colors.lightGray)
  68. term.setCursorPos(2,size[2])
  69. term.setTextColor(cp.tBar)
  70. write("..")
  71.  
  72. term.setTextColor(cp.tBar)
  73. term.setBackgroundColor(cp.bar)
  74. term.setCursorPos(1,2)
  75. write("@ ")
  76.  
  77. term.setBackgroundColor(cp.bar2)
  78. if #root-2 > size[1] then
  79. for i = 1, size[1]-5 do
  80. local c = root:sub(i, i)
  81. write(c)
  82. end
  83. write("...")
  84.  
  85. else
  86. write(root)
  87. end
  88. end
  89.  
  90.  
  91. while true do
  92. list = fs.list(root)
  93. drawGUI()
  94. for k, v in pairs(list) do
  95. if v == selected then
  96. txColor = cp.tBar
  97. paintutils.drawLine(1, k+2, size[1]-optS-1, k+2, cp.bar)
  98. else
  99. term.setBackgroundColor(colors.white)
  100. txColor = colors.gray
  101. end
  102.  
  103. if fs.isDir(root.."/"..v) then
  104. term.setCursorPos(1, k+2)
  105. term.setTextColor(cp.tDir)
  106. write("* ")
  107. term.setTextColor(txColor)
  108. write(v)
  109.  
  110. elseif not fs.isDir(root.."/"..v) then
  111. term.setCursorPos(1, k+2)
  112. term.setTextColor(cp.tFile)
  113. write("* ")
  114. term.setTextColor(txColor)
  115. write(v)
  116. end
  117. end
  118.  
  119. local e, b, x, y = os.pullEvent()
  120. if e == "mouse_click" and x >= 2 and x <= 3 and y == size[2] then
  121. root = fs.getDir(root)
  122.  
  123. elseif e == "mouse_click" and x >= 3 and y == 2 then
  124. term.setBackgroundColor(cp.bar2)
  125. term.setTextColor(colors.white)
  126. for x = 3, size[1] do --Doing this so I dont wipe off the whole line, parts are needed.
  127. term.setCursorPos(x, 2)
  128. write(" ")
  129. end
  130. term.setCursorPos(3,2)
  131. local newRoot = read()
  132. if fs.isDir(newRoot) then
  133. root = newRoot
  134. term.setBackgroundColor(cp.suc)
  135. term.setTextColor(cp.tBar)
  136. term.setCursorPos(1,2)
  137. write("@ ")
  138. sleep(0.1)
  139. elseif not fs.isDir(newRoot) or not fs.exsits(newRoot) then
  140. term.setBackgroundColor(cp.fail)
  141. term.setTextColor(colors.white)
  142. term.setCursorPos(1,2)
  143. write("@ ")
  144. sleep(0.1)
  145. end
  146.  
  147. elseif e == "mouse_click" and x < size[1]-optS-1 and y-2 <= #list and selected == list[y-2] and fs.isDir(root.."/"..selected)then
  148. root = root.."/"..selected
  149.  
  150. elseif e == "mouse_click" and b == 1 and x < size[1]-optS-1 and y-2 <= #list and selected == list[y-2] and not fs.isDir(root.."/"..selected) then
  151. shell.run(root.."/"..selected)
  152.  
  153. elseif e == "mouse_click" and b == 2 and x < size[1]-optS-1 and y-2 <= #list and selected == list[y-2] and not fs.isDir(root.."/"..selected) then
  154. shell.run("edit "..root.."/"..selected)
  155.  
  156. elseif e == "mouse_click" and x < size[1]-optS-1 and y-2 > #list then
  157. selected = nil
  158.  
  159. elseif e == "mouse_click" and x < size[1]-optS-1 and y-2 <= #list and y ~= 1 and y ~= 2 then
  160. selected = list[y-2]
  161.  
  162. elseif e == "mouse_click" and x == size[1] and y == 1 then
  163. term.setBackgroundColor(colors.black)
  164. term.clear()
  165. term.setCursorPos(1,1)
  166. break
  167.  
  168. elseif e == "mouse_drag" then
  169. optS = size[1]-x
  170.  
  171. end
  172. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement