Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cmp = require('component')
- local event = require('event')
- local serialization = require('serialization')
- local gpu=cmp.gpu
- local term =require('term')
- local computer = require('computer')
- local filesystem=require('filesystem')
- local unicode = require('unicode')
- local sides = require("sides")
- local keyboard = require("keyboard")
- local thread = require('thread')
- local tunnel = cmp.tunnel
- local draw = require('draw')
- ----
- local oldBack=gpu.getBackground()
- local oldFore=gpu.getForeground()
- pathArr={'../'}
- sel=0
- ----
- function exit()
- gpu.setBackground(oldBack)
- gpu.setForeground(oldFore)
- term.clear()
- os.exit()
- end
- function checkEvent()
- key,_,x,y,clickMouse,name=event.pull()
- return key , x , y , clickMouse
- end
- function getPath()
- path=''
- for i=1,#pathArr do
- path=path..pathArr[i]
- end
- return path
- end
- function drawMenu()
- draw.field(1,1,80,25,' ',0x222222,0xFFFFFF) -- <frame>
- draw.field(1,2,18,24,' ',0xAAAAAA,0xFFFFFF)
- draw.field(19,2,62,24,' ',0xFFFFFF,0xFFFFFF)
- draw.field(39,2,1,24,"▌",0xFFFFFF,0x00FF00)
- draw.field(60,2,1,24,"▌",0xFFFFFF,0x00FF00)
- draw.field(3,1,3,1,' ',0x0000FF,0xFFFFFF)
- draw.field(4,1,1,1,'←',0x0000FF,0xFFFFFF)
- draw.field(8,1,3,1,' ',0x0000FF,0xFFFFFF)
- draw.field(9,1,1,1,'→',0x0000FF,0xFFFFFF)
- draw.field(1,1,1,1,'X',0xFF0000,0xFFFFFF)
- end
- function getFiles(path)
- arr={} arr2={}
- for val,val2 in filesystem.list(path) do if val~= nil then arr[#arr+1]=val end end
- for i=1,#arr do if unicode.sub(arr[i],unicode.len(arr[i]),unicode.len(arr[i])) == '/' then arr2[#arr2+1]=arr[i] end end
- for i=1,#arr do if unicode.sub(arr[i],unicode.len(arr[i]),unicode.len(arr[i])) ~= '/' then arr2[#arr2+1]=arr[i] end end
- arr=arr2
- return arr
- end
- function drawName(x,arr,i,deb)
- j=i-deb
- if unicode.sub(arr[i],unicode.len(arr[i]),unicode.len(arr[i])) == '/' then
- gpu.setForeground(0xBBBB00)
- gpu.set(x,1+j,arr[i])
- else
- gpu.setForeground(0)
- gpu.set(x,1+j,arr[i])
- end
- gpu.setForeground(0)
- gpu.setBackground(0xFFFFFF)
- end
- function drawSelect(x,arr,sel,deb)
- j=sel-deb
- if oldClickFile ~= nil then
- l=oldSelect[3]-oldSelect[4]
- if oldClickFile ~= sel and arr[oldClickFile]~= nil then
- if unicode.sub(arr[oldClickFile],unicode.len(arr[oldClickFile]),unicode.len(arr[oldClickFile])) == '/' then
- gpu.setForeground(0xBBBB00)
- gpu.setBackground(0xFFFFFF)
- gpu.fill(oldSelect[1],1+l,20,1,' ')
- gpu.set(oldSelect[1],1+l,arr[oldClickFile])
- else
- gpu.setBackground(0xFFFFFF)
- gpu.fill(oldSelect[1],1+l,20,1,' ')
- gpu.setForeground(0)
- gpu.set(oldSelect[1],1+l,arr[oldClickFile])
- end
- end
- end
- if unicode.sub(arr[sel],unicode.len(arr[sel]),unicode.len(arr[sel])) == '/' then
- gpu.setForeground(0xBBBB00)
- gpu.setBackground(0x55AAEE)
- gpu.fill(x,1+j,20,1,' ')
- gpu.set(x,1+j,arr[sel])
- else
- gpu.setBackground(0x55AAEE)
- gpu.fill(x,1+j,20,1,' ')
- gpu.setForeground(0)
- gpu.set(x,1+j,arr[sel])
- end
- gpu.setForeground(0)
- gpu.setBackground(0xFFFFFF)
- oldSelect={x,arr,sel,deb}
- end
- function drawFiles(k,v,path)
- drawPath()
- draw.field(19,2,62,24,' ',0xFFFFFF,0xFFFFFF)
- draw.field(39,2,1,24,"▌",0xFFFFFF,0x00FF00)
- draw.field(60,2,1,24,"▌",0xFFFFFF,0x00FF00)
- arr=getFiles(path)
- for i=k,v do
- if i < 25 then
- if arr[i] ~= nil then
- drawName(19,arr,i,0)
- end
- elseif i >24 and i < 49 then
- if arr[i] ~= nil then
- drawName(40,arr,i,24)
- end
- elseif i > 48 and i < 73 then
- if arr[i] ~= nil then
- drawName(61,arr,i,48)
- end
- end
- end
- gpu.setForeground(0)
- gpu.setBackground(0xFFFFFF)
- end
- --55AAEE
- function drawPath()
- draw.field(20,1,40,1,' ',0x222222,0xFFFFFF)
- path=getPath()
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x222222)
- if unicode.len(path) > 40 then
- path2=unicode.sub(path,unicode.len(path)-40,unicode.len(path))
- else
- path2=path
- end
- gpu.set(20,1,path2)
- gpu.setForeground(0)
- gpu.setBackground(0xFFFFFF)
- end
- function menu()
- drawMenu()
- drawFiles(1,72,getPath())
- while true do
- key , x , y , clickMouse = checkEvent()
- if key == 'touch' then
- if x > 18 and x < 39 then
- if arr[y-1] ~= nil then
- clickFile=y-1
- end
- elseif x > 39 and x < 60 then
- if arr[(y-1)+24] ~= nil then
- clickFile=(y-1)+24
- end
- elseif x > 60 and x < 81 then
- if arr[(y-1)+48] ~= nil then
- clickFile=(y-1)+48
- end
- elseif x > 2 and x < 7 and y == 1 then
- if #pathArr > 1 then
- pathArr2={}
- for i=1,#pathArr-1 do
- pathArr2[#pathArr2+1]=pathArr[i]
- end
- pathArr=pathArr2
- sel=0
- oldClickFile=nil
- clickFile=0
- drawFiles(1,72,getPath())
- end
- elseif x==1 and y==1 then exit()
- end
- if oldClickFile ~= clickFile then
- sel=clickFile
- if sel < 25 then
- if arr[sel] ~= nil then
- drawSelect(19,arr,sel,0)
- end
- elseif sel >24 and sel < 49 then
- if arr[sel] ~= nil then
- drawSelect(40,arr,sel,24)
- end
- elseif sel > 48 and sel < 73 then
- if arr[sel] ~= nil then
- drawSelect(61,arr,sel,48)
- end
- end
- elseif oldClickFile == clickFile then
- if arr[clickFile] ~= nil and unicode.sub(arr[clickFile],unicode.len(arr[clickFile]),unicode.len(arr[clickFile])) == '/' then
- pathArr[#pathArr+1]=tostring(arr[clickFile])
- sel=0
- oldClickFile=nil
- clickFile=0
- drawFiles(1,72,getPath())
- else
- --
- end
- end
- oldClickFile=clickFile
- end
- end
- end
- menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement