Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fol
- local prog
- local dd = false
- local dx, dy = term.getSize()
- local directory = "/"
- local folders = {}
- local programs = {}
- local i
- local selected
- local scroll = 0
- local scrollt = 0
- local var = 0
- local varI = 1
- local srch = false
- local button = {}
- local btns
- local rlib = {}
- button.clear = function()
- btns = {}
- return true
- end
- button.add = function(par2, par3, par4 ,par5 ,par6)
- if par3 == nil or par4 == nil or par5 == nil or par6 == nil then--there is a more efficient way of doing this but I don't know it
- return false
- else
- btns[#btns+1] = {par2, math.ceil(par3), math.ceil(par4), math.ceil(par5), math.ceil(par6)}
- end
- return true, #btns
- end
- button.wait = function()
- if #btns == 0 then
- return false
- end
- while true do
- eve, but, x, y = os.pullEvent("mouse_click")
- for i = 1, #btns do
- local sel = btns[i]
- if sel[1]==but or sel[1] == nil then
- if eve == "mouse_click" and x >= sel[2] and y >= sel[3] and x <= sel[4] and y <= sel[5] then
- return i, but
- end
- end
- end
- end
- end
- button.list = function()
- return btns
- end
- rlib.search = function(search, dir)
- if search == nil then
- search = textBox('Search Item')
- end
- local directory = dir or directory
- local fls = fs.list(directory)
- local all2 = {}
- for i = 1, #fls do
- if fs.isDir(directory..fls[i]) then
- local ind3, ind4 = string.find(fls[i], search)
- if ind[3] ~= nil then
- table.insert(all2, {directory, fls[i], ind[3], ind[4]})
- end
- local ret = rlib.search(search, directory..all[i].."/")
- for i = 1, #ret do
- table.insert(all2, ret[i])
- end
- else
- local ind3, ind4 = string.find(fls[i], search)
- if ind[3] ~= nil then
- table.insert(all2, {directory, fls[i], ind[3], ind[4]})
- end
- end
- end
- end
- rlib.hilite = function(str, ind1, ind2)
- local sub = string.gmatch(str, ".")
- for i = 1, string.len(str) do
- if i >= ind1 and i <= ind2 then
- term.setBackgroundColor(colors.yellow)
- write(sub())
- else
- term.setBackgroundColor(colors.white)
- write(sub())
- end
- end
- end
- rlib.read = function(lmt, start, cvr)
- local col = term.getBackgroundColor()
- local x, y = term.getCursorPos()
- if lmt == nil then
- local xc = term.getCursorPos()
- local x = term.getSize()
- lmt = x - xc
- end
- term.setCursorBlink(true)
- local outstr = {}
- local function Rupdate()
- local x3, y3 = term.getCursorPos()
- paintutils.drawLine(x, y, x+lmt, y, col)
- term.setCursorPos(x+lmt, y)
- for i = 1, lmt do
- term.setCursorPos(x+lmt-i, y)
- if outstr[i] ~= nil then
- if cvr == nil then
- write(outstr[#outstr-i+1])
- else
- write(cvr)
- end
- end
- end
- term.setCursorPos(x+lmt, y)
- end
- if start ~= nil then
- for i in string.gmatch(start, ".") do
- table.insert(outstr, i)
- end
- term.setCursorPos(x, y)
- if #outstr < lmt then
- for i = 1, #outstr do
- if cvr == nil then
- write(outstr[i])
- else
- write(cvr)
- end
- end
- else
- Rupdate()
- end
- end
- while true do
- if lmt == nil then
- return false
- end
- eve, let = os.pullEvent()
- if eve == "char" then
- outstr[#outstr+1] = let
- if #outstr <= lmt then
- if cvr == nil then
- write(let)
- else
- write(cvr)
- end
- else
- Rupdate()
- end
- elseif eve == "key" then
- if let == 14 and outstr ~= {} then
- outstr[#outstr] = nil
- if #outstr <= lmt then
- paintutils.drawLine(x, y, x+lmt, y, col)
- term.setCursorPos(x, y)
- for i = 1, #outstr do
- if cvr == nil then
- write(outstr[i])
- else
- write(cvr)
- end
- end
- else
- Rupdate()
- end
- elseif let == 28 then
- local restr = ""
- for i = 1, #outstr do
- restr = restr..outstr[i]
- end
- return restr
- elseif let == 15 then
- local restr = ""
- for i = 1, #outstr do
- restr = restr..outstr[i]
- end
- return restr, "tab"
- end
- end
- end
- term.setCursorBlink(false)
- end
- local function draw()
- button.clear()
- term.setBackgroundColor(colors.white)
- term.clear()
- paintutils.drawLine(dx, 1, dx, dy, colors.cyan)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.black)
- local x, y = term.getSize()
- term.setCursorPos(x, 1)
- term.write("X")
- button.add(1, x, 1, x, 1)
- term.setCursorPos(x, 2)
- term.setBackgroundColor(colors.blue)
- term.write("+")
- term.setBackgroundColor(colors.yellow)
- term.setCursorPos(51, 3)
- write("/")
- term.setBackgroundColor(colors.white)
- end
- local scroll2 = 0
- local function updateTbl()
- local all
- if srch == false then
- all = fs.list(directory)
- elseif srch == true then
- all = rlib.search()
- end
- folders = {}
- programs = {}
- for i = 1, #all do
- if fs.isDir(directory..all[i]) then
- table.insert(folders, all[i])
- else
- table.insert(programs, all[i])
- end
- end
- end
- local function list()
- term.setTextColor(colors.lime)
- term.setCursorPos(1, 0)
- if scroll == 0 then
- var, varI = 1, 0
- term.setCursorPos(1, 1)
- write("..")
- button.add(1, 1, 1, 51, 1)
- else
- varI, var = 1, 0
- end
- fol = 0
- prog = 0
- for i = 1, #folders do
- if folders[i+scroll-varI] == nil then
- break
- end
- _, y = term.getCursorPos()
- if y >= dy-1 then
- break
- end
- fol = fol+1
- term.setCursorPos(1, y+1)
- button.add(nil, 1, y+1, 50, y+1)
- write(folders[i+scroll-varI])
- end
- term.setTextColor(colors.blue)
- for i = 1, #programs do
- if programs[i+scroll2] == nil then
- break
- end
- _, y = term.getCursorPos()
- if y <= dy-1 then
- prog = prog+1
- term.setCursorPos(1, y+1)
- button.add(nil, 1, y+1, 50, y+1)
- write(programs[i+scroll2])
- end
- end
- button.add(1, 51, 2, 51, 2)
- button.add(1, 51, 3, 51, 3)
- end
- local function update()
- draw()
- updateTbl()
- list()
- end
- local function textbox(top, strt)
- while true do
- paintutils.drawBox(1, 1, 51, 3, colors.cyan)
- term.setCursorPos(1, 1)
- term.setTextColor(colors.black)
- write(top)
- paintutils.drawLine(2, 2, 50, 2, colors.white)
- term.setCursorPos(2, 2)
- term.setTextColor(colors.black)
- local text = rlib.read(48, strt)
- if text ~= nil and text ~= "" then
- term.setCursorBlink(false)
- return text
- else
- term.setCursorBlink(false)
- return false
- end
- end
- end
- local function setDir()
- local dir = textbox("Enter Directory Path", directory)
- if fs.exists(dir) then
- directory = dir
- scroll = 0
- scroll2 = 0
- update()
- end
- end
- local function menu(y, pord, tf)
- if y > 14 then
- y = 14
- end
- if tf == true then
- while true do
- dd = true
- paintutils.drawFilledBox(1, y, 11, y+3, colors.white)
- paintutils.drawLine(12, y+1, 12, y+4, colors.gray)
- paintutils.drawLine(2, y+4, 12, y+4, colors.gray)
- button.clear()
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.black)
- term.setCursorPos(1, y)
- write("<")
- button.add(1, 1, y, 1, y)
- term.setBackgroundColor(colors.white)
- term.setCursorPos(1, y+1)
- write("remove")
- button.add(1, 1, y+1, 10, y+1)
- term.setCursorPos(1, y+2)
- write("rename/move")
- button.add(1, 1, y+2, 10, y+2)
- term.setCursorPos(1, y+3)
- write("copy")
- button.add(1, 1, y+3, 10, y+3)
- local click = button.wait()
- if click == 1 then
- dd = false
- update()
- break
- elseif click == 2 then
- fs.delete(pord)
- dd = false
- update()
- scroll = 0
- scroll2 = 0
- break
- elseif click == 3 then
- local text = textbox("Path/New Name", pord)
- if text then
- fs.move(pord, text)
- end
- dd = false
- scroll = 0
- scroll2 = 0
- update()
- break
- elseif click == 4 then
- local text = textbox("destination", directory)
- if text then
- fs.copy(pord, text)
- end
- dd = false
- scroll = 0
- scroll2 = 0
- update()
- break
- end
- end
- end
- if tf == false then
- while true do
- update()
- dd = true
- paintutils.drawFilledBox(1, y, 11, y+5, colors.white)
- paintutils.drawLine(12, y+1, 12, y+6, colors.gray)
- paintutils.drawLine(2, y+6, 12, y+6, colors.gray)
- button.clear()
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.black)
- term.setCursorPos(1, y)
- write("<")
- button.add(1, 1, y, 1, y)
- term.setBackgroundColor(colors.white)
- term.setCursorPos(1, y+1)
- write("edit")
- button.add(1, 1, y+1, 11, y+1)
- term.setCursorPos(1, y+2)
- write("rename/move")
- button.add(1, 1, y+2, 11, y+2)
- term.setCursorPos(1, y+3)
- write("delete")
- button.add(1, 1, y+3, 11, y+3)
- term.setCursorPos(1, y+4)
- write("copy")
- button.add(1, 1, y+4, 11, y+4)
- term.setCursorPos(1, y+5)
- write("Run w/ args")
- button.add(1, 1, y+5, 11, y+5)
- local click = button.wait()
- if click == 1 then
- dd = false
- update()
- break
- elseif click == 2 then
- term.setBackgroundColor(colors.black)
- shell.run("edit "..pord)
- term.setCursorBlink(false)
- elseif click == 3 then
- local text = textbox("Path/New Name", pord)
- if text ~= false then
- fs.move(pord, text)
- end
- dd = false
- update()
- scroll = 0
- scroll2 = 0
- break
- elseif click == 4 then
- fs.delete(pord)
- dd = false
- update()
- scroll = 0
- scroll2 = 0
- break
- elseif click == 5 then
- local text = textbox("Copy Path")
- fs.copy(pord, text)
- elseif click == 6 then
- local text = textbox("Args")
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.white)
- shell.run(pord.." "..text)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- write("Program finished click anywhere to go back to explorer.")
- os.pullEvent("mouse_click")
- end
- end
- end
- end
- local function scrollBar()
- while true do
- local eve, ud = os.pullEvent("mouse_scroll")
- if eve == "mouse_scroll" and dd == false and scroll+ud >= 0 and scroll+scroll2+ud+19 <= #folders+#programs+1 and #folders+#programs > 19 then
- if scroll-1+ud <= #folders and scroll2 == 0 then
- scroll = scroll+ud
- update()
- elseif scroll2+ud >= 0 then
- scroll2 = scroll2+ud
- update()
- end
- end
- end
- end
- local function main()
- while true do
- update()
- local click, but = button.wait()
- if click == 1 then
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- break
- elseif click == 2 and directory ~= "/" and scroll == 0 then
- if but == 1 then
- if fs.getDir(directory) ~= nil then
- directory = fs.getDir(directory).."/"
- update()
- end
- end
- elseif click >= 1+var and click <= fol+1+var then
- if but == 1 then
- if folders[click-2+scroll] ~= nil then
- directory = directory..folders[click-2+scroll].."/"
- scroll, scroll2 = 0, 0
- update()
- end
- elseif but == 2 then
- menu(click, directory..folders[click-2+scroll], true)
- end
- elseif click > fol+var+1 and click <= fol+var+prog+1 then
- if but == 1 then
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.white)
- dd = true
- shell.run(directory..programs[(click-fol)-var-1+scroll2])
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- local _, y = term.getCursorPos()
- term.setCursorPos(1, y+1)
- write("Program finished click anywhere to go back to explorer.")
- os.pullEvent("mouse_click")
- dd = false
- elseif but == 2 then
- menu(click, directory..programs[(click-fol)-var-1+scroll2], false)
- end
- elseif click == prog+fol+var+2 then
- dd = true
- while true do
- update()
- paintutils.drawFilledBox(43, 1, 51, 19, colors.white)
- paintutils.drawLine(42, 1, 42, 19, colors.cyan)
- term.setTextColor(colors.black)
- term.setCursorPos(42, 1)
- term.setBackgroundColor(colors.red)
- write("<")
- button.clear()
- term.setBackgroundColor(colors.white)
- term.setCursorPos(43, 1)
- button.add(1, 42, 1, 42, 1)
- term.setTextColor(colors.green)
- term.setCursorPos(43, 1)
- write(" Folder")
- button.add(1, 43, 1, 51, 1)
- term.setTextColor(colors.blue)
- term.setCursorPos(43, 2)
- write(" Program")
- button.add(1, 43, 2, 51, 2)
- local click = button.wait()
- if click ~= 1 then
- if click == 2 then
- local text = textbox("Folder Name")
- if fs.exists(directory..text) == false then
- fs.makeDir(directory..text)
- end
- elseif click == 3 then
- local text = textbox("Program Name")
- if fs.exists(directory..text) == false then
- local file = fs.open(directory..text, "w")
- file.write(" ")
- file.close()
- end
- end
- else
- break
- end
- end
- scroll = 0
- scroll2 = 0
- dd = false
- update()
- elseif click == prog+fol+var+3 then
- setDir()
- update()
- end
- end
- end
- update()
- parallel.waitForAny(main, scrollBar)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement