debugger cleanup + ls now supports date
This commit is contained in:
@@ -9,7 +9,6 @@ local function breakpointHook(info)
|
||||
if dbg.breakpoints then
|
||||
for _,v in pairs(dbg.breakpoints) do
|
||||
if v.line == info.currentline and v.file == info.short_src then
|
||||
print(v.line, not v.disabled)
|
||||
return not v.disabled
|
||||
end
|
||||
end
|
||||
@@ -96,6 +95,9 @@ local function local_bindings(offset, stack_inspect_offset)
|
||||
if k ~= '(*temporary)' then
|
||||
v.name = k
|
||||
v.value = tostring(v.raw)
|
||||
--if type(v.raw) == 'table' and not next(v.raw) then
|
||||
-- v.value = 'table: (empty)'
|
||||
--end
|
||||
table.insert(t, v)
|
||||
end
|
||||
end
|
||||
@@ -180,11 +182,11 @@ local function hook()
|
||||
end
|
||||
end
|
||||
|
||||
function dbg.call(f, ...)
|
||||
function dbg.call(fn, ...)
|
||||
local args = { ... }
|
||||
return xpcall(
|
||||
function()
|
||||
f(table.unpack(args))
|
||||
fn(table.unpack(args))
|
||||
end,
|
||||
function(err)
|
||||
hookEval = stepHook()
|
||||
@@ -196,9 +198,9 @@ end
|
||||
|
||||
_ENV.coroutine = setmetatable({
|
||||
|
||||
create = function(f)
|
||||
create = function(fn)
|
||||
local co = _G.coroutine.create(function(...)
|
||||
local r = { dbg.call(f, ...) }
|
||||
local r = { dbg.call(fn, ...) }
|
||||
|
||||
if not r[1] then
|
||||
error(r[2], -1)
|
||||
|
||||
@@ -291,7 +291,7 @@ local page = UI.Page {
|
||||
end,
|
||||
},
|
||||
statusBar = UI.StatusBar {
|
||||
ex = -7, y = -1,
|
||||
ex = -12, y = -1,
|
||||
backgroundColor = 'black',
|
||||
textColor = 'orange',
|
||||
},
|
||||
@@ -301,6 +301,12 @@ local page = UI.Page {
|
||||
event = 'open',
|
||||
text = 'Open',
|
||||
},
|
||||
UI.FlatButton {
|
||||
y = -1, x = -10,
|
||||
textColor = 'orange',
|
||||
event = 'edit_file',
|
||||
text = 'Edit',
|
||||
},
|
||||
|
||||
quick_open = UI.QuickSelect {
|
||||
y = '50%',
|
||||
@@ -323,6 +329,18 @@ local page = UI.Page {
|
||||
end,
|
||||
},
|
||||
|
||||
textDisplay = UI.SlideOut {
|
||||
ey = '50%',
|
||||
textArea = UI.TextArea {
|
||||
ey = -2,
|
||||
},
|
||||
UI.Button {
|
||||
x = '50%', y = -1,
|
||||
text = 'Ok',
|
||||
event = 'slide_hide',
|
||||
}
|
||||
},
|
||||
|
||||
openFile = function(self, file, line)
|
||||
if file ~= currentFile then
|
||||
local src = loadSource(file)
|
||||
@@ -342,6 +360,17 @@ local page = UI.Page {
|
||||
end
|
||||
self:draw()
|
||||
end,
|
||||
|
||||
editFile = function(_, file)
|
||||
if fs.exists(file) then
|
||||
multishell.openTab(_ENV, {
|
||||
path = 'sys/apps/shell.lua',
|
||||
args = { 'edit ' .. file },
|
||||
focused = true,
|
||||
})
|
||||
end
|
||||
end,
|
||||
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'cmd' then
|
||||
self.statusBar:setStatus('Running...')
|
||||
@@ -356,6 +385,9 @@ local page = UI.Page {
|
||||
elseif event.type == 'open' then
|
||||
self.quick_open:show()
|
||||
|
||||
elseif event.type == 'edit_file' then
|
||||
self:editFile(currentFile)
|
||||
|
||||
elseif event.type == 'open_file' then
|
||||
self:openFile(event.file, event.line)
|
||||
|
||||
@@ -409,6 +441,9 @@ local page = UI.Page {
|
||||
insert(event.element.orig)
|
||||
event.element:setValues(t)
|
||||
event.element:draw()
|
||||
else
|
||||
self.textDisplay.textArea:setValue(event.selected.value)
|
||||
self.textDisplay:show()
|
||||
end
|
||||
end
|
||||
return UI.Page.eventHandler(self, event)
|
||||
|
||||
@@ -8,4 +8,4 @@ LuaFileSystem is a Lua library developed to complement the set of functions rela
|
||||
|
||||
LuaFileSystem offers a portable way to access the underlying directory structure and file attributes. LuaFileSystem is free software and uses the same license as Lua 5.x (MIT).]],
|
||||
license = 'MIT',
|
||||
}
|
||||
}
|
||||
@@ -65,4 +65,10 @@ return {
|
||||
realPath = function(...) return ... end,
|
||||
remove = function(a) fs.delete(a) return true end,
|
||||
size = fs.getSize,
|
||||
attributes = function(f)
|
||||
local s, m = pcall(fs.attributes, f)
|
||||
if s then
|
||||
return m
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ local unicode = require("shellex.unicode")
|
||||
local tx = require("shellex.transforms")
|
||||
local text = require("shellex.text")
|
||||
|
||||
local term = _G.term.current()
|
||||
|
||||
local dirsArg, ops = shell.parse(...)
|
||||
|
||||
if ops.help then
|
||||
@@ -50,6 +52,8 @@ local function stat(names, index)
|
||||
info.sort_name = info.name:gsub("^%.","")
|
||||
info.isLink, info.link = fs.isLink(info.full_path)
|
||||
info.size = info.isLink and 0 or fs.size(info.full_path)
|
||||
local attrs = fs.attributes(info.full_path)
|
||||
info.time = attrs and (attrs.modification / 1000) or 0
|
||||
info.ext = info.name:match("(%.[^.]+)$") or ""
|
||||
names[index] = info
|
||||
return info
|
||||
@@ -166,6 +170,24 @@ local function formatSize(size)
|
||||
return nod(math.floor(size*10)/10)..sizes[unit]
|
||||
end
|
||||
|
||||
local function pad(txt)
|
||||
txt = tostring(txt)
|
||||
return #txt >= 2 and txt or "0"..txt
|
||||
end
|
||||
|
||||
local function formatDate(epochms)
|
||||
--local day_names={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
|
||||
local month_names={"January","February","March","April","May","June","July","August","September","October","November","December"}
|
||||
if epochms == 0 then return "" end
|
||||
local d = os.date("*t", epochms)
|
||||
local day, hour, min, sec = nod(d.day), pad(nod(d.hour)), pad(nod(d.min)), pad(nod(d.sec))
|
||||
if ops["full-time"] then
|
||||
return string.format("%s-%s-%s %s:%s:%s ", d.year, pad(nod(d.month)), pad(day), hour, min, sec)
|
||||
else
|
||||
return string.format("%s %+2s %+2s:%+2s ", month_names[d.month]:sub(1,3), day, hour, pad(min))
|
||||
end
|
||||
end
|
||||
|
||||
local function filter(names)
|
||||
if ops.a then
|
||||
return names
|
||||
@@ -200,6 +222,9 @@ local function sort(names)
|
||||
table.sort(names, function(a, b)
|
||||
local ast = stat(names, ni(a))
|
||||
local bst = stat(names, ni(b))
|
||||
if ast[key] == bst[key] then
|
||||
return ast.name > bst.name
|
||||
end
|
||||
return ast[key] > bst[key]
|
||||
end)
|
||||
end
|
||||
@@ -239,9 +264,11 @@ local function display(names)
|
||||
if ops.l then
|
||||
lines.n = #names
|
||||
local max_size_width = 1
|
||||
local max_date_width = 0
|
||||
for i=1,lines.n do
|
||||
local info = stat(names, i)
|
||||
max_size_width = math.max(max_size_width, formatSize(info.size):len())
|
||||
max_date_width = math.max(max_date_width, formatDate(info.time):len())
|
||||
end
|
||||
mt.__index = function(_, index)
|
||||
local info = stat(names, index)
|
||||
@@ -252,8 +279,9 @@ local function display(names)
|
||||
end)
|
||||
local write_mode = info.fs and info.fs.isReadOnly() and '-' or 'w'
|
||||
local size = formatSize(info.size)
|
||||
local format = "%s-r%s %+"..tostring(max_size_width)..'s '
|
||||
local meta = string.format(format, file_type, write_mode, size)
|
||||
local modDate = formatDate(info.time)
|
||||
local format = "%s-r%s %+"..tostring(max_size_width)..'s %'..tostring(max_date_width).."s"
|
||||
local meta = string.format(format, file_type, write_mode, size, modDate)
|
||||
local item = info.name..link_target
|
||||
|
||||
return {{name = meta}, {color = colorize(info), name = item}}
|
||||
|
||||
Reference in New Issue
Block a user