Files
LeonOS/data/computercraft/lua/rom/programs/list.lua
Leonmmcoset 214bcecf7b refactor(programs/list): 简化目录列表显示逻辑
移除详细显示模式(-l参数)和文件类型颜色区分
将文件和目录分开显示,使用更简洁的表格输出
修改错误信息格式,移除多余的双引号
2025-08-31 19:05:26 +08:00

46 lines
1.0 KiB
Lua

-- list
local args = {...}
local fs = require("fs")
local shell = require("shell")
local colors = require("colors")
local settings = require("settings")
local textutils = require("textutils")
if #args == 0 then args[1] = shell.dir() end
local show_hidden = settings.get("list.show_hidden")
local function list_dir(dir)
if not fs.exists(dir) then
error(dir .. ": that directory does not exist", 0)
elseif not fs.isDir(dir) then
error(dir .. ": not a directory", 0)
end
local raw_files = fs.list(dir)
local files, dirs = {}, {}
for i=1, #raw_files, 1 do
local full = fs.combine(dir, raw_files[i])
if raw_files[i]:sub(1,1) ~= "." or show_hidden then
if fs.isDir(full) then
dirs[#dirs+1] = raw_files[i]
else
files[#files+1] = raw_files[i]
end
end
end
textutils.pagedTabulate(colors.green, dirs, colors.white, files)
end
for i=1, #args, 1 do
if #args > 1 then
textutils.coloredPrint(colors.yellow, args[i]..":\n", colors.white)
end
list_dir(args[i])
end