Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- "tree" script for CC
- The MIT License (MIT)
- Copyright (c) 2017 CrazedProgrammer
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- associated documentation files (the "Software"), to deal in the Software without restriction,
- including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
- and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do
- so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all copies or
- substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- ]]
- local tree = { }
- local function scan(path, depth)
- local entries = fs.list(path)
- for i = 1, #entries do
- local epath = path.."/"..entries[i]
- tree[#tree + 1] = {depth, fs.isDir(epath), entries[i]}
- if fs.isDir(epath) then
- scan(epath, depth + 1)
- end
- end
- end
- scan(#({...}) == 0 and shell.dir() or shell.resolve(({...})[1]), 0)
- local sw, sh = term.getSize()
- for i = 1, #tree do
- local cx, cy = term.getCursorPos()
- if cy == sh and i >= sh then
- term.write("...")
- os.pullEvent("key")
- term.setCursorPos(1, cy)
- term.write(" ")
- term.setCursorPos(1, cy)
- end
- write(("- "):rep(tree[i][1]))
- term.setTextColor(term.isColor() and (tree[i][2] and colors.green or colors.white) or colors.white)
- print(tree[i][3])
- term.setTextColor(colors.white)
- end
Add Comment
Please, Sign In to add comment