Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mainDir = "fe/" -- settings directory for saving and loading colors and settings
- local dir = mainDir.."engine/e.lua" -- change this to the file location of the engine
- if e == nil then if not os.loadAPI(dir) then error("Engine failed to load from "..dir..". Make sure you change this in the file to the appropriate location.") end end -- loads the engine if not already loaded
- local files = {}
- local dir = {"/"}
- local currentDir = ""
- local paste = "!"
- local cutting = false
- scroll = 0
- maxScroll = 0
- local w,h = e.gs()
- if w < 20 or h < 10 then error("Screen is to small.") end
- if not term.isColor() then error("Advanced computer is required.") end
- local cols = {}
- cols["file"] = colors.white -- handling text color
- cols["directory"] = colors.yellow
- cols["rom"] = colors.orange
- cols["..."] = colors.white
- cols["col1"] = colors.black -- handling background color
- cols["col2"] = colors.gray
- cols["info"] = colors.white -- handling info screen text color
- local settings = {}
- settings.run = true
- settings.edit = true
- settings.paint = true
- settings.delete = true
- settings.copy = false
- settings.move = false
- if fs.exists(mainDir.."cols.lua") then
- local file = fs.open(mainDir.."cols.lua", "r")
- local tmp = file.readAll()
- file.close()
- cols = textutils.unserialize(tmp)
- end
- if fs.exists(mainDir.."settings.lua") then
- local file = fs.open(mainDir.."settings.lua", "r")
- local tmp = file.readAll()
- file.close()
- settings = textutils.unserialize(tmp)
- end
- running = true
- local function reloadFiles()
- if #dir == 0 then running = false return false end
- files, scroll, currentDir = {}, 0, ""
- for i=1, #dir do
- currentDir = currentDir..dir[i]
- end
- local fl = fs.list(currentDir)
- local tmp = {{},{},{}}
- for i=1, #fl do
- if fs.isReadOnly(currentDir..fl[i]) then tmp[1][#tmp[1]+1] = fl[i] elseif fs.isDir(currentDir..fl[i]) then tmp[2][#tmp[2]+1] = fl[i] else tmp[3][#tmp[3]+1] = fl[i] end
- end
- fl = {} fl[1] = "..."
- for i=1, #tmp[1] do
- fl[#fl+1] = tmp[1][i]
- end
- for i=1, #tmp[2] do
- fl[#fl+1] = tmp[2][i]
- end
- for i=1, #tmp[3] do
- fl[#fl+1] = tmp[3][i]
- end
- for i=1, #fl do
- if fl[i] ~= "..." then
- local tmp = fl[i]
- if string.len(fl[i]) > math.ceil(w/1.2)-3 then
- tmp = string.sub(fl[i], 1, math.ceil(w/1.2)-3).."..."
- end
- files[i] = {}
- files[i].name = tmp
- files[i].rom = fs.isReadOnly(currentDir..fl[i])
- if fs.isDir(currentDir..fl[i]) then files[i].type = "directory" else files[i].type = "file" end
- files[i].size = fs.getSize(currentDir..fl[i])
- files[i].dir = currentDir..fl[i]
- else
- local tmp = "( "..currentDir.." )"
- if string.len(currentDir) > math.ceil(w/1.2)-3 then
- tmp = "(..."..string.sub(currentDir, math.ceil(w/1.2)-3, -1)..")"
- end
- files[i] = {}
- files[i].name = "... "..tmp
- files[i].rom = false
- files[i].type = "..."
- files[i].size = 0
- files[i].dir = "/"
- end
- end
- if h > #files then maxScroll = 0 else maxScroll = #files-h end
- e.clr() -- for display to draw fresh
- end
- local function display()
- e.cp(1,1) local tmp = 1
- for i=1, math.min(#files, h) do
- term.setBackgroundColor(cols["col"..tmp]) term.clearLine() e.cp(1,i)
- if files[i+scroll].rom then
- term.setTextColor(cols["rom"])
- write("* ")
- end
- term.setTextColor(cols[files[i+scroll].type])
- write(files[i+scroll].name)
- if i ~= math.min(#files, h) then print("") end
- if tmp == 1 then tmp = 2 else tmp = 1 end
- end
- e.setBack("black")
- if scroll == 0 then sleep(.1) end
- end
- local function displayInfo(info)
- if fs.exists(info.dir) then
- e.clr() e.cp(1,1)
- term.setTextColor(cols["info"])
- print(info.name)
- print("Type: "..info.type)
- print("ReadOnly (rom): "..tostring(info.rom))
- print("Dir: "..info.dir)
- print("Size: "..info.size.." byte(s)")
- print("")
- local run, update, menu, sel, s = true, true, {}, 1, false
- if info.type == "file" and settings.run then menu[#menu+1] = "Run" end
- if info.type == "file" and settings.edit then menu[#menu+1] = "Edit" end
- if info.type == "file" and e.notnil(string.find(info.name, ".nfp")) and settings.paint then menu[#menu+1] = "Paint" end
- if info.type ~= "..." and settings.copy then menu[#menu+1] = "Copy" end
- if info.type ~= "..." and settings.move and not info.rom then menu[#menu+1] = "Cut" end
- if info.type ~= "..." and not info.rom and settings.delete then menu[#menu+1] = "Delete" end
- if info.type ~= "file" and settings.copy and paste ~= "!" then menu[#menu+1] = "Paste" end
- menu[#menu+1] = "Exit"
- while run do
- if update then
- for i=1, #menu do
- e.cp(1,h-#menu-1+i) term.clearLine() e.cp(1,h-#menu-1+i)
- if i == sel then
- print("> "..menu[i])
- else
- print(menu[i].." ")
- end
- end
- sleep(.0000001)
- a,i,x,y = os.pullEvent()
- if a == "mouse_click" then
- if i == 1 and y >= h-#menu and y <= h-1 then -- left click
- sel = y-(h-#menu-1) s = true run = false
- end
- elseif a == "key" then
- if i == keys.q then
- run = false
- elseif i == keys.w or i == keys.up then
- if sel == 1 then sel = #menu else sel = sel - 1 end update = true
- elseif i == keys.s or i == keys.down then
- if sel == #menu then sel = 1 else sel = sel + 1 end update = true
- elseif i == keys.e or i == keys.enter then
- s = true run = false
- end
- end
- end
- end
- if s then
- sel = menu[sel]
- if sel == "Run" then
- e.clr() e.cp(1,1) shell.run(info.dir) sleep(2)
- elseif sel == "Edit" then
- shell.run("edit "..info.dir)
- elseif sel == "Paint" then
- shell.run("paint "..info.dir)
- elseif sel == "Delete" then
- fs.delete(info.dir)
- elseif sel == "Copy" then
- paste = info.dir
- elseif sel == "Cut" then
- cutting = true
- paste = info.dir
- elseif sel == "Paste" then
- if cutting then
- cutting = false
- fs.copy(paste, info.dir..fs.getName(paste))
- fs.delete(paste)
- paste = "!"
- else
- print(paste.." "..currentDir) sleep(2)
- --if fs.isDir(paste) then fs.copy("/testing1", currentDir..paste)
- if fs.exists(paste) and fs.exists(currentDir) then
- if fs.isDir(paste) then
- fs.copy(paste, currentDir..paste)
- else
- fs.copy(paste, currentDir..paste)
- end
- end
- end
- elseif sel == "Exit" then
- run = false
- end
- end
- end
- end
- local function manageSettings()
- --
- end
- local function runtime() -- main running script
- reloadFiles()
- local updat = true
- while running do
- if updat then
- updat = false
- display()
- end
- --sleep(.000001) -- to avoid lag and crashes
- local a,b,x,y = os.pullEvent()
- if a == "mouse_scroll" then
- if b == 1 then -- down
- if scroll < maxScroll then
- scroll = scroll + 1
- else
- scroll = 0
- end
- updat = true
- else -- up
- if scroll > 0 then
- scroll = scroll - 1
- else
- scroll = maxScroll
- end
- updat = true
- end
- elseif a == "mouse_click" then
- if b == 1 then
- if e.notnil(files[y+scroll]) then
- if files[y+scroll].type == "directory" then
- dir[#dir+1] = files[y+scroll].name.."/" reloadFiles() updat = true
- elseif files[y+scroll].type == "..." then
- --table.remove(dir, #dir)
- dir[#dir] = nil
- reloadFiles() updat = true
- else
- displayInfo(files[y+scroll]) reloadFiles() updat = true
- end
- end
- elseif b == 2 then
- if e.notnil(files[y+scroll]) then
- if files[y+scroll].type == "..." then
- displayInfo(files[y+scroll]) reloadFiles() updat = true
- else
- displayInfo(files[y+scroll]) reloadFiles() updat = true
- end
- end
- end
- elseif a == "key" then
- if b == keys.q then
- table.remove(dir, #dir) reloadFiles() updat = true
- elseif b == keys.w or b == keys.up then
- if scroll ~= 0 then
- scroll = scroll - 1 updat = true
- end
- elseif b == keys.s or b == keys.down then
- if scroll ~= maxScroll then
- scroll = scroll + 1 updat = true
- end
- elseif b == keys.r then
- e.clr() sleep(.1) reloadFiles() updat = true
- elseif b == keys.f then
- --manageSettings() updat = true
- end
- end
- end
- end
- runtime() -- not run inside pcall because the os is responsible for handling errors
- e.clr() e.cp(1,1)
- sleep(.001)
Advertisement
Add Comment
Please, Sign In to add comment