run lua commands from shell and other tweaks

This commit is contained in:
kepler155c@gmail.com
2020-07-25 18:52:13 -06:00
parent cb1126e216
commit d6f61acace
5 changed files with 61 additions and 21 deletions

View File

@@ -30,15 +30,8 @@ local page = UI.Page {
getDisplayValues = function(_, row)
row = Util.shallowCopy(row)
local function tovalue(s)
if type(s) == 'table' then
return 'table'
end
return s
end
for k,v in pairs(row) do
row[k] = tovalue(v)
row[k] = type(v) == 'table' and 'table' or v
end
return row
@@ -95,30 +88,25 @@ local page = UI.Page {
end,
}
local updated = false
local timerId = os.startTimer(1)
Event.addRoutine(function()
while true do
local _, id = os.pullEvent('timer')
if id == timerId then
if updated then
while #page.grid.values > 100 do -- page.grid.height do
table.remove(page.grid.values, 100) -- #page.grid.values)
end
updated = false
page.grid:update()
page.grid:draw()
page:sync()
while #page.grid.values > 100 do
table.remove(page.grid.values)
end
timerId = os.startTimer(1)
timerId = nil
page.grid:update()
page.grid:draw()
page:sync()
end
end
end)
local hookFunction = function(event, e)
if not page.filtered[event] and not page.paused and not (event == 'timer' and e[1] == timerId) then
updated = true
table.insert(page.grid.values, 1, {
event = event,
p1 = e[1],
@@ -127,6 +115,7 @@ local hookFunction = function(event, e)
p4 = e[4],
p5 = e[5],
})
timerId = timerId or os.startTimer(.1)
end
end

View File

@@ -6,3 +6,49 @@ end
_ENV.shell.setCompletionFunction("packages/common/edit.lua", c)
_ENV.shell.setCompletionFunction("packages/common/hexedit.lua", c)
_ENV.shell.registerHandler(function(env, command, args)
if command:match('^!') then
return {
title = 'lua',
path = table.concat({ command:match('^!(.+)'), table.unpack(args) }, ' '),
args = args,
load = function(s)
return function()
local fn, m
local wrapped
fn = load('return (' ..s.. ')', 'lua', nil, env)
if fn then
fn = load('return {' ..s.. '}', 'lua', nil, env)
wrapped = true
end
if fn then
fn, m = pcall(fn)
if #m <= 1 and wrapped then
m = m[1]
end
else
fn, m = load(s, 'lua', nil, env)
if fn then
fn, m = pcall(fn)
end
end
if fn then
if m or wrapped then
require('opus.util').print(m or 'nil')
else
print()
end
else
_G.printError(m)
end
end
end,
env = env,
}
end
end)

View File

@@ -3,4 +3,6 @@ packages/common/hexedit.lua urlfs https://pastebin.com/raw/Ds9ajsp4
packages/common/colors.lua urlfs https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/ignore/colors.lua
packages/common/cowsay.lua urlfs https://pastebin.com/raw/n00VQJsw
packages/common/calc.lua urlfs https://pastebin.com/raw/nAinUn1h
packages/common/write.lua urlfs https://pastebin.com/raw/RSyhCjqv
packages/common/write.lua urlfs https://pastebin.com/raw/RSyhCjqv
# pretty output
rom/modules/main/inpsect.lua urlfs https://raw.githubusercontent.com/kikito/inspect.lua/master/inspect.lua