Posted 30 April 2012 - 04:06 AM
I was bored for 2 minutes and needed to make something simple, so I made a quick alternative to list.
This alternative provides the ability to see hidden items (Items with a "." infront of them cannot be seen by the normal list command.) and scrolling if there are too many items.
There are indicators for: Access to the item(Read/Write), Visibility of that item(Hidden/Visible), and that item's type(File/Directory) through the use of tokens.
Here are some examples:
And here is the simple messy(Yay 2 mins..) source:
Minor code change.
Also, don't scan a dir with a file over 34 chars long.
Hopefully there are no bugs I did not catch on something so short.
This alternative provides the ability to see hidden items (Items with a "." infront of them cannot be seen by the normal list command.) and scrolling if there are too many items.
There are indicators for: Access to the item(Read/Write), Visibility of that item(Hidden/Visible), and that item's type(File/Directory) through the use of tokens.
Spoiler
Spoiler
Spoiler
tArgs = { ... }
iCounth, iCountv, iCountd, iCountf, iCountr, iCountw = 0, 0, 0, 0, 0, 0
function spit(key,file,path)
if fs.isReadOnly(path..file) == true then rom = "-"; iCountr = iCountr + 1 else rom = "+" ; iCountw = iCountw + 1 end
if string.match(file,"^.") == "." then vis = "H"; iCounth = iCounth + 1 else vis = "V" ; iCountv = iCountv + 1 end
if fs.isDir(path..file) then type = "D"; iCountd = iCountd + 1 else type = "F"; iCountf = iCountf + 1 end
write(
" "..
string.rep("0",(3-string.len(key)))..key..": "..
string.rep(" ",(34-string.len(file)))..file..
"["..rom.."]".."["..vis.."]".."["..type.."]".."n"
)
end
function scan(dir)
local w,h = term.getSize()
local nLinesPrinted = 0
for key,file in ipairs(fs.list(dir)) do
if nLinesPrinted >= h - 2 then
term.write(" "..string.rep("-",48))
x,y=os.pullEvent( "key" )
term.clearLine()
term.setCursorPos(1,h)
end
spit(key,file,dir.."/")
nLinesPrinted = nLinesPrinted+1
end
write(
" "..
"([-]: "..iCountr..")"..
"([+]: "..iCountw..")"..
"([H]: "..iCounth..")"..
"([V]: "..iCountv..")"..
"([D]: "..iCountd..")"..
"([F]: "..iCountf..")"..
"n"
)
end
function tokens()
tokens = "[+] = Write accessn[-] = Read onlyn[H] = Hiddenn[V] = Visiblen[D] = Directoryn[F] = Filen"
write("Usage: scan <dir>nnTokens:n"..tokens)
end
if tArgs[1] == nil then
scan(shell.dir())
else
if fs.isDir(tArgs[1]) then
scan(tArgs[1])
else
tokens()
end
end
Also, don't scan a dir with a file over 34 chars long.
Hopefully there are no bugs I did not catch on something so short.