mirror of
https://github.com/kepler155c/opus
synced 2025-03-31 12:46:56 +00:00
transparent compatiblity for moonscript
This commit is contained in:
parent
4f39604c63
commit
2fdcc338ad
sys
@ -13,13 +13,12 @@ Util.merge(env, _ENV)
|
|||||||
env._G = env
|
env._G = env
|
||||||
|
|
||||||
env.arg = { ... }
|
env.arg = { ... }
|
||||||
env.arg[0] = shell.resolveProgram(table.remove(env.arg, 1))
|
env.arg[0] = shell.resolveProgram(table.remove(env.arg, 1) or error('file name is required'))
|
||||||
|
|
||||||
_G.requireInjector(env, fs.getDir(env.arg[0]))
|
_G.requireInjector(env, fs.getDir(env.arg[0]))
|
||||||
|
|
||||||
local s, m = Util.run(env, env.arg[0], table.unpack(env.arg))
|
local s, m = Util.run(env, env.arg[0], table.unpack(env.arg))
|
||||||
|
|
||||||
if not s then
|
if not s then
|
||||||
error(m)
|
error(m, -1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,8 +6,6 @@ local fs = _G.fs
|
|||||||
local settings = _G.settings
|
local settings = _G.settings
|
||||||
local shell = _ENV.shell
|
local shell = _ENV.shell
|
||||||
|
|
||||||
--_G.requireInjector(_ENV)
|
|
||||||
|
|
||||||
local trace = require('opus.trace')
|
local trace = require('opus.trace')
|
||||||
local Util = require('opus.util')
|
local Util = require('opus.util')
|
||||||
|
|
||||||
@ -37,43 +35,72 @@ local function tokenise( ... )
|
|||||||
return tWords
|
return tWords
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local defaultHandlers = {
|
||||||
|
urlHandler = function(args, env)
|
||||||
|
return args[1]:match("^(https?:)") and {
|
||||||
|
title = fs.getName(args[1]),
|
||||||
|
path = table.remove(args, 1),
|
||||||
|
args = args,
|
||||||
|
load = Util.loadUrl,
|
||||||
|
env = env,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
|
||||||
|
pathHandler = function(args, env)
|
||||||
|
local command = table.remove(args, 1)
|
||||||
|
return {
|
||||||
|
title = fs.getName(command):match('([^%.]+)'),
|
||||||
|
path = shell.resolveProgram(command) or error('No such program'),
|
||||||
|
args = args,
|
||||||
|
load = loadfile,
|
||||||
|
env = env,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
function shell.getHandlers()
|
||||||
|
if parentShell and parentShell.getHandlers then
|
||||||
|
return parentShell.getHandlers()
|
||||||
|
end
|
||||||
|
return defaultHandlers
|
||||||
|
end
|
||||||
|
|
||||||
|
local handlers = shell.getHandlers()
|
||||||
|
|
||||||
|
function shell.registerHandler(fn)
|
||||||
|
table.insert(handlers, 1, fn)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function handleCommand(args, env)
|
||||||
|
for _,v in pairs(handlers) do
|
||||||
|
local pi = v(args, env)
|
||||||
|
if pi then
|
||||||
|
return pi
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function run(...)
|
local function run(...)
|
||||||
local args = tokenise(...)
|
local args = tokenise(...)
|
||||||
local command = table.remove(args, 1) or error('No such program')
|
if #args == 0 then
|
||||||
local isUrl = not not command:match("^(https?:)")
|
error('No such program')
|
||||||
local env = shell.makeEnv(_ENV)
|
|
||||||
|
|
||||||
if command:match('(.+)%.moon$') then
|
|
||||||
table.insert(args, 1, command)
|
|
||||||
command = 'moon'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local path, loadFn
|
local pi = handleCommand(args, shell.makeEnv(_ENV))
|
||||||
if isUrl then
|
|
||||||
path = command
|
|
||||||
loadFn = Util.loadUrl
|
|
||||||
else
|
|
||||||
path = shell.resolveProgram(command) or error('No such program')
|
|
||||||
loadFn = loadfile
|
|
||||||
end
|
|
||||||
|
|
||||||
local O_v_O, err = loadFn(path, env)
|
local O_v_O, err = pi.load(pi.path, pi.env)
|
||||||
if not O_v_O then
|
if not O_v_O then
|
||||||
error(err, -1)
|
error(err, -1)
|
||||||
end
|
end
|
||||||
|
|
||||||
if _ENV.multishell then
|
if _ENV.multishell then
|
||||||
_ENV.multishell.setTitle(_ENV.multishell.getCurrent(), fs.getName(path):match('([^%.]+)'))
|
_ENV.multishell.setTitle(_ENV.multishell.getCurrent(), pi.title)
|
||||||
end
|
end
|
||||||
|
|
||||||
tProgramStack[#tProgramStack + 1] = {
|
tProgramStack[#tProgramStack + 1] = pi
|
||||||
path = path, -- path:match("^https?://([^/:]+:?[0-9]*/?.*)$")
|
|
||||||
env = env,
|
|
||||||
args = args,
|
|
||||||
}
|
|
||||||
|
|
||||||
env[ "arg" ] = { [0] = path, table.unpack(args) }
|
pi.env[ "arg" ] = { [0] = pi.path, table.unpack(pi.args) }
|
||||||
local r = { O_v_O(table.unpack(args)) }
|
local r = { O_v_O(table.unpack(pi.args)) }
|
||||||
|
|
||||||
tProgramStack[#tProgramStack] = nil
|
tProgramStack[#tProgramStack] = nil
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ Map.merge = Util.merge
|
|||||||
Map.shallowCopy = Util.shallowCopy
|
Map.shallowCopy = Util.shallowCopy
|
||||||
Map.find = Util.find
|
Map.find = Util.find
|
||||||
Map.filter = Util.filter
|
Map.filter = Util.filter
|
||||||
|
Map.transpose = Util.transpose
|
||||||
|
|
||||||
function Map.removeMatches(t, values)
|
function Map.removeMatches(t, values)
|
||||||
local function matchAll(entry)
|
local function matchAll(entry)
|
||||||
|
@ -58,8 +58,8 @@ function UI.QuickSelect:applyFilter(filter)
|
|||||||
self.grid:setIndex(1)
|
self.grid:setIndex(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.QuickSelect:enable()
|
function UI.QuickSelect.getFiles()
|
||||||
self.grid.values = { }
|
local t = { }
|
||||||
local function recurse(dir)
|
local function recurse(dir)
|
||||||
local files = fs.list(dir)
|
local files = fs.list(dir)
|
||||||
for _,f in ipairs(files) do
|
for _,f in ipairs(files) do
|
||||||
@ -70,7 +70,7 @@ function UI.QuickSelect:enable()
|
|||||||
recurse(fullName)
|
recurse(fullName)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
_insert(self.grid.values, {
|
_insert(t, {
|
||||||
name = f,
|
name = f,
|
||||||
dir = dir,
|
dir = dir,
|
||||||
lname = f:lower(),
|
lname = f:lower(),
|
||||||
@ -80,6 +80,11 @@ function UI.QuickSelect:enable()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
recurse('')
|
recurse('')
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
function UI.QuickSelect:enable()
|
||||||
|
self.grid.values = self:getFiles()
|
||||||
self:applyFilter()
|
self:applyFilter()
|
||||||
self.filterEntry:reset()
|
self.filterEntry:reset()
|
||||||
UI.Window.enable(self)
|
UI.Window.enable(self)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user