moonscript support fixes

This commit is contained in:
kepler155c@gmail.com
2020-06-13 12:19:13 -06:00
parent 1a166bdb22
commit 27c7d2dd18
8 changed files with 17 additions and 195 deletions

View File

@@ -1,7 +0,0 @@
moonscript must be run in compatibility mode:
> compat moon T.moon
> compat moonc T.moon
moon and moonc were modified to allow relative paths:
> cd /packages/moonscript
> compat moonc T.moon

View File

@@ -1,99 +0,0 @@
local Event = require('opus.event')
local UI = require('opus.ui')
local kernel
kernel = _G.kernel
local multishell
multishell = _ENV.multishell
local tasks = multishell and multishell.getTabs and multishell.getTabs() or kernel.routines
UI:configure('Tasks', ...)
local page = UI.Page({
UI.MenuBar({
buttons = {
{
text = 'Activate',
event = 'activate'
},
{
text = 'Terminate',
event = 'terminate'
},
{
text = 'Inspect',
event = 'inspect'
}
}
}),
grid = UI.ScrollingGrid({
y = 2,
columns = {
{
heading = 'ID',
key = 'uid',
width = 3
},
{
heading = 'Title',
key = 'title'
},
{
heading = 'Status',
key = 'status'
},
{
heading = 'Time',
key = 'timestamp'
}
},
values = tasks,
sortColumn = 'uid',
autospace = true,
getDisplayValues = function(self, row)
local elapsed = os.clock() - row.timestamp
return {
uid = row.uid,
title = row.title,
status = row.isDead and 'error' or coroutine.status(row.co),
timestamp = elapsed < 60 and string.format("%ds", math.floor(elapsed)) or string.format("%sm", math.floor(elapsed / 6) / 10)
}
end
}),
accelerators = {
['control-q'] = 'quit',
[' '] = 'activate',
t = 'terminate'
},
eventHandler = function(self, event)
local t = self.grid:getSelected()
local _exp_0 = event.type
if 'activate' == _exp_0 or 'grid_select' == _exp_0 then
if t then
return multishell.setFocus(t.uid)
end
elseif 'terminate' == _exp_0 then
if t then
return multishell.terminate(t.uid)
end
elseif 'inspect' == _exp_0 then
if t then
return multishell.openTab(_ENV, {
path = 'sys/apps/Lua.lua',
args = {
t
},
focused = true
})
end
elseif 'quit' == _exp_0 then
return UI:quit()
else
return UI.Page.eventHandler(self, event)
end
end
})
Event.onInterval(1, function()
page.grid:update()
page.grid:draw()
return page:sync()
end)
UI:setPage(page)
return UI:start()

View File

@@ -1,7 +1,6 @@
local Map = require('opus.map')
local fs = _G.fs
local shell = _ENV.shell
local commands = Map.transpose {
'packages/moonscript/moon',
@@ -16,21 +15,28 @@ local function compatEnv(source)
return env
end
shell.registerHandler(function(args, env)
if args[1]:match('(.+)%.moon$') then
local function fix(env, args)
if #args > 0 then
args[1] = env.shell.resolve(args[1])
end
return args
end
_ENV.shell.registerHandler(function(env, command, args)
if command:match('(.+)%.moon$') then
return {
title = fs.getName(args[1]):match('([^%.]+)'),
title = fs.getName(command):match('([^%.]+)'),
path = 'packages/moonscript/moon',
args = args,
args = { env.shell.resolveProgram(command), table.unpack(args) },
load = loadfile,
env = compatEnv(env),
}
end
local command = shell.resolveProgram(args[1]) or ''
command = env.shell.resolveProgram(command) or ''
return commands[command] and {
title = fs.getName(command),
path = command,
args = { table.unpack(args, 2) },
args = fix(env, args),
load = loadfile,
env = compatEnv(env),
}

View File

@@ -1,5 +1,7 @@
packages/moonscript/repo gitfs leafo/moonscript/master
packages/moonscript/moon linkfs packages/moonscript/repo/bin/moon
packages/moonscript/moonc linkfs packages/moonscript/repo/bin/moonc
rom/modules/main/moonscript linkfs packages/moonscript/repo/moonscript
rom/modules/main/moon linkfs packages/moonscript/repo/moon
rom/modules/main/moonutil gitfs natnat-mc/moonutil/master/moonutil
#rom/modules/main/moonutil gitfs natnat-mc/moonutil/master/moonutil
rom/modules/main/argparse urlfs https://raw.githubusercontent.com/mpeterv/argparse/master/src/argparse.lua