From 8fef5d35803a18348319c12f2a70710ac9dda007 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Wed, 27 May 2020 14:49:51 -0600 Subject: [PATCH] debugger cleanup + ls now supports date --- debugger/apis/init.lua | 12 +++++++----- debugger/debug.lua | 37 ++++++++++++++++++++++++++++++++++++- lfs/.package | 2 +- shellex/apis/filesystem.lua | 6 ++++++ shellex/ls.lua | 32 ++++++++++++++++++++++++++++++-- 5 files changed, 80 insertions(+), 9 deletions(-) diff --git a/debugger/apis/init.lua b/debugger/apis/init.lua index fe9de22..ff1d199 100644 --- a/debugger/apis/init.lua +++ b/debugger/apis/init.lua @@ -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) diff --git a/debugger/debug.lua b/debugger/debug.lua index 5f4f2a2..2afa093 100644 --- a/debugger/debug.lua +++ b/debugger/debug.lua @@ -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) diff --git a/lfs/.package b/lfs/.package index 2354b1d..1f411da 100644 --- a/lfs/.package +++ b/lfs/.package @@ -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', -} +} \ No newline at end of file diff --git a/shellex/apis/filesystem.lua b/shellex/apis/filesystem.lua index 7389faf..248ee40 100644 --- a/shellex/apis/filesystem.lua +++ b/shellex/apis/filesystem.lua @@ -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 } diff --git a/shellex/ls.lua b/shellex/ls.lua index 3e3c990..8168ac4 100644 --- a/shellex/ls.lua +++ b/shellex/ls.lua @@ -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}}