From 89f95ca45b5c73855a8266423230b261ed14c0bd Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Thu, 7 Mar 2019 13:14:16 -0500 Subject: [PATCH] stack traces --- sys/apis/util.lua | 17 +++++++---------- sys/apps/Network.lua | 10 ++++++---- sys/apps/shell.lua | 3 ++- sys/extensions/7.multishell.lua | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sys/apis/util.lua b/sys/apis/util.lua index 4e45641..d016feb 100644 --- a/sys/apis/util.lua +++ b/sys/apis/util.lua @@ -567,24 +567,21 @@ function Util.widthify(s, len, align) if slen > len then return _ssub(s, 1, len) + elseif slen == len then return s - end - if align == 'center' then - local space = math.floor((len-slen) / 2) - local filler = _srep(' ', space + 1) - s = _ssub(filler, 1, space) .. s - s = s .. _srep(' ', len - #s) + elseif align == 'center' then + local space = math.floor((len - slen) / 2) + s = _srep(' ', space) .. s + return s .. _srep(' ', len - #s) elseif align == 'right' then - s = _srep(' ', len - #s) .. s + return _srep(' ', len - slen) .. s - else -- 'left' - s = s .. _srep(' ', len - #s) end - return s + return s .. _srep(' ', len - slen) end -- http://snippets.luacode.org/?p=snippets/trim_whitespace_from_string_76 diff --git a/sys/apps/Network.lua b/sys/apps/Network.lua index 5e17d46..c8232ff 100644 --- a/sys/apps/Network.lua +++ b/sys/apps/Network.lua @@ -15,17 +15,17 @@ UI:configure('Network', ...) local gridColumns = { { heading = 'Label', key = 'label' }, - { heading = 'Dist', key = 'distance' }, + { heading = 'Dist', key = 'distance', align = 'right' }, { heading = 'Status', key = 'status' }, } local config = Config.load('network', { }) if UI.term.width >= 30 then - table.insert(gridColumns, { heading = 'Fuel', key = 'fuel', width = 5 }) + table.insert(gridColumns, { heading = 'Fuel', key = 'fuel', width = 5, align = 'right' }) end if UI.term.width >= 40 then - table.insert(gridColumns, { heading = 'Uptime', key = 'uptime' }) + table.insert(gridColumns, { heading = 'Uptime', key = 'uptime', align = 'right' }) end local page = UI.Page { @@ -262,8 +262,10 @@ function page.grid:getDisplayValues(row) if row.uptime then if row.uptime < 60 then row.uptime = string.format("%ds", math.floor(row.uptime)) + elseif row.uptime < 3600 then + row.uptime = string.format("%sm", math.floor(row.uptime / 60)) else - row.uptime = string.format("%sm", math.floor(row.uptime/6)/10) + row.uptime = string.format("%sh", math.floor(row.uptime / 3600)) end end if row.fuel then diff --git a/sys/apps/shell.lua b/sys/apps/shell.lua index 68fc0b3..8946e0a 100644 --- a/sys/apps/shell.lua +++ b/sys/apps/shell.lua @@ -13,6 +13,7 @@ sandboxEnv.shell = shell _G.requireInjector(_ENV) +local trace = require('trace') local Util = require('util') local DIR = (parentShell and parentShell.dir()) or "" @@ -88,7 +89,7 @@ function shell.run(...) local env = setmetatable(Util.shallowCopy(sandboxEnv), { __index = _G }) _G.requireInjector(env) - local r = { pcall(run, env, ...) } + local r = { trace(run, env, ...) } if _ENV.multishell then _ENV.multishell.setTitle(_ENV.multishell.getCurrent(), oldTitle or 'shell') diff --git a/sys/extensions/7.multishell.lua b/sys/extensions/7.multishell.lua index ea7e5c3..d5de390 100644 --- a/sys/extensions/7.multishell.lua +++ b/sys/extensions/7.multishell.lua @@ -139,7 +139,7 @@ function multishell.openTab(tab) if err then printError(tostring(err)) if stacktrace then -- alternatively log stack to _debug - print('\n' .. stacktrace) + --print('\n' .. stacktrace) end end print('\nPress enter to close')