Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- W, H = term.getSize()
- selected = 1
- scroll = 0
- currentPath = ''
- fileList = fs.list(currentPath)
- while true do
- term.clear()
- term.setCursorPos(3, 1)
- term.write('name')
- term.setCursorPos(W-21, 1)
- term.write('type')
- term.setCursorPos(W-15, 1)
- term.write('dir')
- term.setCursorPos(W-10, 1)
- term.write('size')
- term.setCursorPos(1, 2)
- for n = 1, W do
- term.write('-')
- end
- if #fileList > H-2 then
- term.setCursorPos(W, 2+(H-2)*selected/#fileList)
- term.write('#')
- end
- term.setCursorPos(1, H)
- if selected ~= 0 then
- term.write(currentPath..'/'..(fileList[selected] or ''))
- end
- term.setCursorPos(W-tostring(#fileList):len(), H)
- term.write(#fileList)
- term.setCursorPos(1, selected+3-scroll)
- for n = 1, W do
- term.write('-')
- end
- term.setCursorPos(1, selected+3-scroll)
- if selected == 0 or fs.isDir(currentPath..'/'..(fileList[selected] or '')) then
- term.write('>>')
- else
- term.write('->')
- end
- if 3-scroll < H and 3-scroll > 2 then
- term.setCursorPos(3, 3-scroll)
- term.write('..')
- end
- for n, file in ipairs(fileList) do
- if n+3-scroll < H and n+3-scroll > 2 then
- term.setCursorPos(3, n+3-scroll)
- term.write(file)
- if file:sub(#file-3) == '.nfp' then
- term.setCursorPos(W-21, n+3-scroll)
- term.write('IMG')
- end
- if file:sub(#file-3) == '.lua' then
- term.setCursorPos(W-21, n+3-scroll)
- term.write('LUA')
- end
- if fs.isDir(currentPath..'/'..fileList[n]) then
- term.setCursorPos(W-16, n+3-scroll)
- term.write('[\\_/]')
- end
- term.setCursorPos(W-10, n+3-scroll)
- term.write(fs.getSize(currentPath..'/'..file))
- end
- end
- local event = {os.pullEvent()}
- if event[1] == 'key' then
- if event[2] == keys.up then
- selected = selected - 1
- elseif event[2] == keys.down then
- selected = selected + 1
- end
- if selected > #fileList then
- selected = 0
- scroll = 0
- end
- if selected < 0 then
- selected = #fileList
- if H+3 > #fileList then
- scroll = 0
- else
- scroll = #fileList-H+3
- end
- end
- if selected-scroll > H-4 then
- scroll = scroll + 1
- end
- if selected-scroll < 0 then
- scroll = scroll - 1
- end
- if event[2] == 28 then
- if selected == 0 then
- if currentPath ~= '' then
- currentPath = fs.combine(currentPath, '..')
- fileList = fs.list(currentPath)
- end
- else
- if fs.isDir(currentPath..'/'..fileList[selected]) then
- currentPath = currentPath..'/'..fileList[selected]
- fileList = fs.list(currentPath)
- selected = 1
- scroll = 0
- else
- shell.run(currentPath..'/'..fileList[selected])
- end
- end
- end
- if event[2] == 19 then
- os.pullEvent('char')
- if selected ~= 0 then
- term.clear()
- term.setCursorPos(1, 1)
- term.write('Are you sure you want to delete '..fileList[selected]..'?')
- term.write(' (y/n)')
- term.setCursorPos(1, 2)
- local input = read()
- if string.lower(input) == 'y' then
- shell.run('rm '..currentPath..'/'..fileList[selected])
- fileList = fs.list(currentPath)
- selected = 1
- scroll = 0
- elseif string.lower(input) ~= 'n' then
- term.setCursorPos(1, 3)
- term.write('Incorrect input!')
- end
- end
- end
- if event[2] == 18 then
- os.pullEvent('char')
- if selected ~= 0 and not fs.isDir(currentPath..'/'..fileList[selected]) then
- if fileList[selected]:sub(#fileList[selected]-3) == '.nfp' then
- shell.run('paint '..currentPath..'/'..fileList[selected])
- else
- shell.run('edit '..currentPath..'/'..fileList[selected])
- end
- end
- end
- if event[2] == 50 then
- if selected ~= 0 and not fs.isDir(currentPath..'/'..fileList[selected]) then
- term.clear()
- term.setCursorPos(1, 1)
- shell.run('monitor monitor_0', currentPath..'/'..fileList[selected])
- end
- end
- if event[2] == 16 then
- shell.run('.menu')
- end
- elseif event[1] == 'monitor_touch' or event[1] == 'mouse_click' then
- if event[4] < H-1 and event[4] > 2 then
- if selected == event[4] - 3 then
- if selected == 0 then
- if currentPath ~= '' then
- currentPath = fs.combine(currentPath, '..')
- fileList = fs.list(currentPath)
- end
- else
- if fs.isDir(currentPath..'/'..fileList[selected]) then
- currentPath = currentPath..'/'..fileList[selected]
- fileList = fs.list(currentPath)
- selected = 1
- else
- shell.run(currentPath..'/'..fileList[selected])
- end
- end
- else
- selected = event[4] - 3
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement