1
0
mirror of https://github.com/kepler155c/opus synced 2025-01-22 21:26:53 +00:00
This commit is contained in:
kepler155c@gmail.com 2017-10-08 17:45:01 -04:00
parent 98ec840db1
commit a625b52bad
46 changed files with 334 additions and 319 deletions

View File

@ -1,5 +1,5 @@
local Ansi = setmetatable({ }, {
__call = function(self, ...)
__call = function(_, ...)
local str = '\027['
for k,v in ipairs({ ...}) do
if k == 1 then

View File

@ -1,5 +1,7 @@
local Util = require('util')
local fs = _G.fs
local Config = { }
Config.load = function(fname, data)

View File

@ -1,3 +1,5 @@
local os = _G.os
local Event = {
uid = 1, -- unique id for handlers
routines = { }, -- coroutines

View File

@ -1,5 +1,7 @@
local git = require('git')
local fs = _G.fs
local gitfs = { }
function gitfs.mount(dir, repo)

View File

@ -1,3 +1,5 @@
local fs = _G.fs
local linkfs = { }
local methods = { 'exists', 'getFreeSpace', 'getSize',
@ -10,7 +12,7 @@ for _,m in pairs(methods) do
end
end
function linkfs.mount(dir, source)
function linkfs.mount(_, source)
if not source then
error('Source is required')
end

View File

@ -1,11 +1,13 @@
local Socket = require('socket')
local synchronized = require('sync')
local fs = _G.fs
local netfs = { }
local function remoteCommand(node, msg)
for i = 1, 2 do
for _ = 1, 2 do
if not node.socket then
node.socket = Socket.connect(node.id, 139)
end
@ -49,7 +51,7 @@ for _,m in pairs(methods) do
end
end
function netfs.mount(dir, id, directory)
function netfs.mount(_, id, directory)
if not id or not tonumber(id) then
error('ramfs syntax: computerId [directory]')
end

View File

@ -1,8 +1,10 @@
local Util = require('util')
local fs = _G.fs
local ramfs = { }
function ramfs.mount(dir, nodeType)
function ramfs.mount(_, nodeType)
if nodeType == 'directory' then
return {
nodes = { },
@ -34,7 +36,7 @@ function ramfs.isReadOnly()
return false
end
function ramfs.makeDir(node, dir)
function ramfs.makeDir(_, dir)
fs.mount(dir, 'ramfs', 'directory')
end
@ -46,10 +48,10 @@ function ramfs.getDrive()
return 'ram'
end
function ramfs.list(node, dir, full)
function ramfs.list(node, dir)
if node.nodes and node.mountPoint == dir then
local files = { }
for k,v in pairs(node.nodes) do
for k in pairs(node.nodes) do
table.insert(files, k)
end
return files

View File

@ -1,9 +1,11 @@
local synchronized = require('sync')
local Util = require('util')
local fs = _G.fs
local urlfs = { }
function urlfs.mount(dir, url)
function urlfs.mount(_, url)
if not url then
error('URL is required')
end
@ -12,7 +14,7 @@ function urlfs.mount(dir, url)
}
end
function urlfs.delete(node, dir)
function urlfs.delete(_, dir)
fs.unmount(dir)
end

View File

@ -6,9 +6,9 @@ local FILE_URL = 'https://raw.githubusercontent.com/%s/%s/%s/%s'
local git = { }
function git.list(repo)
function git.list(repository)
local t = Util.split(repo, '(.-)/')
local t = Util.split(repository, '(.-)/')
local user = t[1]
local repo = t[2]
@ -33,7 +33,7 @@ function git.list(repo)
local list = { }
for k,v in pairs(data.tree) do
for _,v in pairs(data.tree) do
if v.type == "blob" then
v.path = v.path:gsub("%s","%%20")
list[v.path] = {

View File

@ -1,5 +1,9 @@
local GPS = { }
local device = _G.device
local gps = _G.gps
local turtle = _G.turtle
function GPS.locate(timeout, debug)
local pt = { }
timeout = timeout or 10
@ -14,7 +18,6 @@ function GPS.isAvailable()
end
function GPS.getPoint(timeout, debug)
local pt = GPS.locate(timeout, debug)
if not pt then
return
@ -24,7 +27,7 @@ function GPS.getPoint(timeout, debug)
pt.y = math.floor(pt.y)
pt.z = math.floor(pt.z)
if pocket then
if _G.pocket then
pt.y = pt.y - 1
end
@ -47,7 +50,7 @@ function GPS.getHeading(timeout)
while not turtle.forward() do
turtle.turnRight()
if turtle.getHeading() == heading then
printError('GPS.getPoint: Unable to move forward')
_G.printError('GPS.getPoint: Unable to move forward')
return
end
end
@ -84,7 +87,7 @@ local function trilaterate( A, B, C )
local a2c = C.position - A.position
if math.abs( a2b:normalize():dot( a2c:normalize() ) ) > 0.999 then
return nil
return
end
local d = a2b:length()

View File

@ -2,6 +2,10 @@ local DEFAULT_UPATH = 'https://raw.githubusercontent.com/kepler155c/opus/develop
local PASTEBIN_URL = 'http://pastebin.com/raw'
local GIT_URL = 'https://raw.githubusercontent.com'
local fs = _G.fs
local http = _G.http
local os = _G.os
-- fix broken http get
local syncLocks = { }
@ -44,7 +48,7 @@ end
local function requireWrapper(env)
local function standardSearcher(modname, env, shell)
local function standardSearcher(modname)
if package.loaded[modname] then
return function()
return package.loaded[modname]
@ -52,18 +56,18 @@ local function requireWrapper(env)
end
end
local function shellSearcher(modname, env, shell)
local function shellSearcher(modname)
local fname = modname:gsub('%.', '/') .. '.lua'
if shell and type(shell.dir) == 'function' then
local path = shell.resolve(fname)
if env.shell and type(env.shell.dir) == 'function' then
local path = env.shell.resolve(fname)
if fs.exists(path) and not fs.isDir(path) then
return loadfile(path, env)
end
end
end
local function pathSearcher(modname, env, shell)
local function pathSearcher(modname)
local fname = modname:gsub('%.', '/') .. '.lua'
for dir in string.gmatch(package.path, "[^:]+") do
@ -75,7 +79,7 @@ local function requireWrapper(env)
end
-- require('BniCQPVf')
local function pastebinSearcher(modname, env, shell)
local function pastebinSearcher(modname)
if #modname == 8 and not modname:match('%W') then
local url = PASTEBIN_URL .. '/' .. modname
local c = loadUrl(url)
@ -86,7 +90,7 @@ local function requireWrapper(env)
end
-- require('kepler155c.opus.master.sys.apis.util')
local function gitSearcher(modname, env, shell)
local function gitSearcher(modname)
local fname = modname:gsub('%.', '/') .. '.lua'
local _, count = fname:gsub("/", "")
if count >= 3 then
@ -98,7 +102,7 @@ local function requireWrapper(env)
end
end
local function urlSearcher(modname, env, shell)
local function urlSearcher(modname)
local fname = modname:gsub('%.', '/') .. '.lua'
if fname:sub(1, 1) ~= '/' then
@ -113,7 +117,7 @@ local function requireWrapper(env)
end
-- place package and require function into env
package = {
env.package = {
path = LUA_PATH or 'sys/apis',
upath = LUA_UPATH or DEFAULT_UPATH,
config = '/\n:\n?\n!\n-',
@ -134,14 +138,14 @@ local function requireWrapper(env)
}
}
function require(modname)
function env.require(modname)
for _,searcher in ipairs(package.loaders) do
local fn, msg = searcher(modname, env, shell)
local fn, msg = searcher(modname)
if fn then
local module, msg = fn(modname, env)
local module, msg2 = fn(modname, env)
if not module then
error(msg or (modname .. ' module returned nil'), 2)
error(msg2 or (modname .. ' module returned nil'), 2)
end
package.loaded[modname] = module
return module
@ -153,10 +157,11 @@ local function requireWrapper(env)
error('Unable to find module ' .. modname)
end
return require -- backwards compatible
return env.require -- backwards compatible
end
return function(env)
env = env or getfenv(2)
setfenv(requireWrapper, env)
return requireWrapper(env)
end

View File

@ -189,7 +189,7 @@ function json.parseObject(str)
local val = {}
while str:sub(1, 1) ~= "}" do
local k, v = nil, nil
local k, v
k, v, str = json.parseMember(str)
val[k] = v
str = removeWhite(str)

View File

@ -21,7 +21,6 @@ function NFT.parse(imageText)
}
local num = 1
local index = 1
for _,sLine in ipairs(Util.split(imageText)) do
table.insert(image.fg, { })
table.insert(image.bg, { })
@ -47,7 +46,7 @@ function NFT.parse(imageText)
fgNext = false
else
if nextChar ~= " " and currFG == nil then
currFG = colours.white
currFG = _G.colors.white
end
image.bg[num][writeIndex] = currBG
image.fg[num][writeIndex] = currFG

View File

@ -1,3 +1,9 @@
local colors = _G.colors
local fs = _G.fs
local os = _G.os
--local shell = _ENV.shell
local term = _G.term
local Opus = { }
local function runDir(directory, open)
@ -27,7 +33,7 @@ local function runDir(directory, open)
term.setTextColor(colors.white)
term.write(fs.combine(directory, file))
if err then
printError(err)
_G.printError(err)
end
success = false
end

View File

@ -1,16 +1,14 @@
local Util = require('util')
local Peripheral = { }
local function getDeviceList()
local Peripheral = Util.shallowCopy(_G.peripheral)
function Peripheral.getList()
if _G.device then
return _G.device
end
local deviceList = { }
for _,side in pairs(peripheral.getNames()) do
for _,side in pairs(Peripheral.getNames()) do
Peripheral.addDevice(deviceList, side)
end
@ -19,14 +17,14 @@ end
function Peripheral.addDevice(deviceList, side)
local name = side
local ptype = peripheral.getType(side)
local ptype = Peripheral.getType(side)
if not ptype then
return
end
if ptype == 'modem' then
if peripheral.call(name, 'isWireless') then
if Peripheral.call(name, 'isWireless') then
ptype = 'wireless_modem'
else
ptype = 'wired_modem'
@ -52,10 +50,10 @@ function Peripheral.addDevice(deviceList, side)
name = uniqueName
end
local s, m pcall(function() deviceList[name] = peripheral.wrap(side) end)
local s, m = pcall(function() deviceList[name] = Peripheral.wrap(side) end)
if not s and m then
printError('wrap failed')
printError(m)
_G.printError('wrap failed')
_G.printError(m)
end
if deviceList[name] then
@ -70,15 +68,15 @@ function Peripheral.addDevice(deviceList, side)
end
function Peripheral.getBySide(side)
return Util.find(getDeviceList(), 'side', side)
return Util.find(Peripheral.getList(), 'side', side)
end
function Peripheral.getByType(typeName)
return Util.find(getDeviceList(), 'type', typeName)
return Util.find(Peripheral.getList(), 'type', typeName)
end
function Peripheral.getByMethod(method)
for _,p in pairs(getDeviceList()) do
for _,p in pairs(Peripheral.getList()) do
if p[method] then
return p
end
@ -92,8 +90,6 @@ function Peripheral.get(args)
args = { type = args }
end
args = args or { type = pType }
if args.type then
local p = Peripheral.getByType(args.type)
if p then

View File

@ -149,7 +149,7 @@ end
function Point.adjacentPoints(pt)
local pts = { }
for _, hi in pairs(turtle.getHeadings()) do
for _, hi in pairs(_G.turtle.getHeadings()) do
table.insert(pts, { x = pt.x + hi.xd, y = pt.y + hi.yd, z = pt.z + hi.zd })
end

View File

@ -28,7 +28,7 @@ function Security.getPublicKey()
local function modexp(base, exponent, modulo)
local remainder = base
for i = 1, exponent-1 do
for _ = 1, exponent-1 do
remainder = remainder * remainder
if remainder >= modulo then
remainder = remainder % modulo

View File

@ -3,6 +3,10 @@ local Logger = require('logger')
local Security = require('security')
local Util = require('util')
local device = _G.device
local os = _G.os
local transport = _G.transport
local socketClass = { }
function socketClass:read(timeout)
@ -165,7 +169,7 @@ function Socket.server(port)
Logger.log('socket', 'Waiting for connections on port ' .. port)
while true do
local e, _, sport, dport, msg = os.pullEvent('modem_message')
local _, _, sport, dport, msg = os.pullEvent('modem_message')
if sport == port and
msg and

View File

@ -1,5 +1,7 @@
local syncLocks = { }
local os = _G.os
return function(obj, fn)
local key = tostring(obj)
if syncLocks[key] then

View File

@ -1,14 +1,15 @@
local Util = require('util')
local colors = _G.colors
local term = _G.term
local _gsub = string.gsub
local Terminal = { }
local _sgsub = string.gsub
function Terminal.scrollable(ct, size)
local size = size or 25
local w, h = ct.getSize()
local win = window.create(ct, 1, 1, w, h + size, true)
local win = _G.window.create(ct, 1, 1, w, h + size, true)
local oldWin = Util.shallowCopy(win)
local scrollPos = 0
@ -110,7 +111,7 @@ function Terminal.toGrayscale(ct)
local function translate(s)
if s then
s = _sgsub(s, "%w", bcolors)
s = _gsub(s, "%w", bcolors)
end
return s
end
@ -162,7 +163,7 @@ function Terminal.readPassword(prompt)
local fn = term.current().write
term.current().write = function() end
local s
pcall(function() s = read(prompt) end)
pcall(function() s = _G.read(prompt) end)
term.current().write = fn
if s == '' then

View File

@ -1,19 +1,21 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Grid = require ("jumper.grid")
local Pathfinder = require ("jumper.pathfinder")
local Point = require('point')
local Util = require('util')
local turtle = _G.turtle
local WALKABLE = 0
local function createMap(dim)
local map = { }
for z = 1, dim.ez do
for _ = 1, dim.ez do
local row = {}
for x = 1, dim.ex do
for _ = 1, dim.ex do
local col = { }
for y = 1, dim.ey do
for _ = 1, dim.ey do
table.insert(col, WALKABLE)
end
table.insert(row, col)
@ -169,7 +171,7 @@ local function pathTo(dest, options)
end
-- Creates a pathfinder object
local myFinder = Pathfinder(grid, 'ASTAR', walkable)
local myFinder = Pathfinder(grid, 'ASTAR', WALKABLE)
myFinder:setMode('ORTHOGONAL')
myFinder:setHeuristic(heuristic)
@ -208,12 +210,14 @@ local function pathTo(dest, options)
local endPt = pointToMap(dim, dest)
-- Calculates the path, and its length
local path = myFinder:getPath(startPt.x, startPt.y, startPt.z, turtle.point.heading, endPt.x, endPt.y, endPt.z, dest.heading)
local path = myFinder:getPath(
startPt.x, startPt.y, startPt.z, turtle.point.heading,
endPt.x, endPt.y, endPt.z, dest.heading)
if not path then
Util.removeByValue(dests, dest)
else
for node, count in path:nodes() do
for node in path:nodes() do
local pt = nodeToPoint(dim, node)
if turtle.abort then

View File

@ -1320,7 +1320,7 @@ end
function UI.Grid:adjustWidth()
local t = { } -- cols without width
local w = self.width - #self.columns - 1 - self.marginRight -- width remaing
local w = self.width - #self.columns - 1 - self.marginRight -- width remaining
for _,c in pairs(self.columns) do
if c.width then

View File

@ -1,6 +1,9 @@
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local fs = _G.fs
return function(args)
local columns = {
@ -86,7 +89,7 @@ return function(args)
return row
end
function selectFile.grid:getRowTextColor(file, selected)
function selectFile.grid:getRowTextColor(file)
if file.isDir then
return colors.cyan
end

View File

@ -162,7 +162,7 @@ end
function Util.findAll(t, name, value)
local rt = { }
for k,v in pairs(t) do
for _,v in pairs(t) do
if v[name] == value then
table.insert(rt, v)
end
@ -317,7 +317,7 @@ function Util.writeLines(fname, lines)
local file = fs.open(fname, 'w')
if file then
for _,line in ipairs(lines) do
line = file.writeLine(line)
file.writeLine(line)
end
file.close()
return true
@ -548,7 +548,7 @@ end
function Util.showOptions(options)
print('Arguments: ')
for k, v in pairs(options) do
for _, v in pairs(options) do
print(string.format('-%s %s', v.arg, v.desc))
end
end
@ -561,7 +561,6 @@ function Util.getOptions(options, args, ignoreInvalid)
end
end
local rawOptions = getopt(args, argLetters)
local argCount = 0
for k,ro in pairs(rawOptions) do
local found = false

View File

@ -1,4 +1,4 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Config = require('config')
local Event = require('event')
@ -6,6 +6,10 @@ local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local fs = _G.fs
local multishell = _ENV.multishell
local os = _G.os
local shell = _ENV.shell
multishell.setTitle(multishell.getCurrent(), 'Files')
UI:configure('Files', ...)
@ -158,7 +162,7 @@ function Browser:setStatus(status, ...)
end
function Browser:unmarkAll()
for k,m in pairs(marked) do
for _,m in pairs(marked) do
m.marked = false
end
Util.clear(marked)
@ -198,7 +202,6 @@ function Browser:updateDirectory(dir)
dir.size = #files
for _, file in pairs(files) do
file.fullName = fs.combine(dir.name, file.name)
file.directory = directory
file.flags = ''
if not file.isDir then
dir.totalSize = dir.totalSize + file.size
@ -232,7 +235,7 @@ function Browser:setDir(dirName, noStatus)
if self.dir then
self.dir.index = self.grid:getIndex()
end
DIR = fs.combine('', dirName)
local DIR = fs.combine('', dirName)
shell.setDir(DIR)
local s, dir = self:getDirectory(DIR)
if s then

View File

@ -1,4 +1,4 @@
requireInjector(getfenv(1))
_G.requireInjector()
local UI = require('ui')
local Util = require('util')

View File

@ -1,15 +1,18 @@
requireInjector = requireInjector or load(http.get('https://raw.githubusercontent.com/kepler155c/opus/master/sys/apis/injector.lua').readAll())()
requireInjector(getfenv(1))
local injector = _G.requireInjector or load(http.get('https://raw.githubusercontent.com/kepler155c/opus/master/sys/apis/injector.lua').readAll())()
injector()
local Event = require('event')
local History = require('history')
local Peripheral = require('peripheral')
local UI = require('ui')
local Util = require('util')
local sandboxEnv = setmetatable(Util.shallowCopy(getfenv(1)), { __index = _G })
local multishell = _ENV.multishell
local sandboxEnv = setmetatable(Util.shallowCopy(_ENV), { __index = _G })
sandboxEnv.exit = function() Event.exitPullEvents() end
sandboxEnv._echo = function( ... ) return ... end
requireInjector(sandboxEnv)
injector(sandboxEnv)
multishell.setTitle(multishell.getCurrent(), 'Lua')
UI:configure('Lua', ...)
@ -112,12 +115,12 @@ function page:eventHandler(event)
if event.type == 'global' then
self:setPrompt('', true)
self:executeStatement('getfenv(0)')
self:executeStatement('_G')
command = nil
elseif event.type == 'local' then
self:setPrompt('', true)
self:executeStatement('getfenv(1)')
self:executeStatement('_ENV')
command = nil
elseif event.type == 'autocomplete' then
@ -129,11 +132,7 @@ function page:eventHandler(event)
elseif event.type == 'device' then
if not _G.device then
sandboxEnv.device = { }
for _,side in pairs(peripheral.getNames()) do
local key = string.format('%s:%s', peripheral.getType(side), side)
sandboxEnv.device[ key ] = peripheral.wrap(side)
end
sandboxEnv.device = Peripheral.getList()
end
self:setPrompt('device', true)
self:executeStatement('device')
@ -187,8 +186,7 @@ function page:setResult(result)
local t = { }
local function safeValue(v)
local t = type(v)
if t == 'string' or t == 'number' then
if type(v) == 'string' or type(v) == 'number' then
return v
end
return tostring(v)

View File

@ -1,10 +1,16 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Event = require('event')
local Socket = require('socket')
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local device = _G.device
local multishell = _ENV.multishell
local network = _G.network
local shell = _ENV.shell
multishell.setTitle(multishell.getCurrent(), 'Network')
UI:configure('Network', ...)
@ -124,14 +130,14 @@ Event.onInterval(1, function()
page:sync()
end)
Event.on('device_attach', function(h, deviceName)
Event.on('device_attach', function(_, deviceName)
if deviceName == 'wireless_modem' then
page.notification:success('Modem connected')
page:sync()
end
end)
Event.on('device_detach', function(h, deviceName)
Event.on('device_detach', function(_, deviceName)
if deviceName == 'wireless_modem' then
page.notification:error('Wireless modem not attached')
page:sync()

View File

@ -1,4 +1,4 @@
requireInjector(getfenv(1))
_G.requireInjector()
local class = require('class')
local Config = require('config')
@ -10,19 +10,13 @@ local Tween = require('ui.tween')
local UI = require('ui')
local Util = require('util')
local REGISTRY_DIR = 'usr/.registry'
local TEMPLATE = [[
local env = { }
for k,v in pairs(getfenv(1)) do
env[k] = v
end
setmetatable(env, { __index = _G })
local fs = _G.fs
local multishell = _ENV.multishell
local pocket = _G.pocket
local term = _G.term
local turtle = _G.turtle
local s, m = os.run(env, 'sys/apps/appRun.lua', %s, ...)
if not s then
error(m)
end
]]
local REGISTRY_DIR = 'usr/.registry'
multishell.setTitle(multishell.getCurrent(), 'Overview')
UI:configure('Overview', ...)
@ -93,13 +87,14 @@ end
local buttons = { }
local categories = { }
table.insert(buttons, { text = 'Recent', event = 'category' })
for _,f in pairs(applications) do
if not categories[f.category] then
categories[f.category] = true
table.insert(buttons, { text = f.category, event = 'category' })
end
end
table.sort(buttons, function(a, b) return a.text < b.text end)
table.insert(buttons, 1, { text = 'Recent', event = 'category' })
table.insert(buttons, { text = '+', event = 'new' })
local function parseIcon(iconText)
@ -159,17 +154,11 @@ local page = UI.Page {
f = 'files',
s = 'shell',
l = 'lua',
[ 'control-l' ] = 'refresh',
[ 'control-n' ] = 'new',
delete = 'delete',
},
}
function page:draw()
self.tabBar:draw()
self.container:draw()
end
UI.Icon = class(UI.Window)
function UI.Icon:init(args)
local defaults = {
@ -194,7 +183,7 @@ function UI.Icon:eventHandler(event)
return UI.Window.eventHandler(self, event)
end
function page.container:setCategory(categoryName)
function page.container:setCategory(categoryName, animate)
-- reset the viewport window
self.children = { }
@ -295,6 +284,11 @@ function page.container:setCategory(categoryName)
end
child.tween = Tween.new(6, child, { x = col, y = row }, 'linear')
if not animate then
child.x = col
child.y = row
end
if k < count then
col = col + child.width
if col + self.children[k + 1].width + gutter - 2 > self.width then
@ -305,6 +299,7 @@ function page.container:setCategory(categoryName)
end
self:initChildren()
if animate then -- need to fix transitions under layers
local function transition(args)
local i = 1
return function(device)
@ -322,9 +317,6 @@ function page.container:setCategory(categoryName)
end
self:addTransition(transition)
end
function page.container:draw()
UI.Viewport.draw(self)
end
function page:refresh()
@ -343,9 +335,8 @@ function page:eventHandler(event)
if event.type == 'category' then
self.tabBar:selectTab(event.button.text)
self.container:setCategory(event.button.text)
self.container:setCategory(event.button.text, true)
self.container:draw()
self:sync()
config.currentCategory = event.button.text
Config.update('Overview', config)
@ -392,14 +383,7 @@ function page:eventHandler(event)
event.focused.parent:scrollIntoView()
end
elseif event.type == 'tab_change' then
if event.current > event.last then
--self.container:setTransition(UI.effect.slideLeft)
else
--self.container:setTransition(UI.effect.slideRight)
end
elseif event.type == 'refresh' then
elseif event.type == 'refresh' then -- remove this after fixing notification
loadApplications()
self:refresh()
self:draw()
@ -569,5 +553,4 @@ page.tabBar:selectTab(config.currentCategory or 'Apps')
page.container:setCategory(config.currentCategory or 'Apps')
UI:setPage(page)
Event.pullEvents()
UI.term:reset()
UI:pullEvents()

View File

@ -1,10 +1,14 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Config = require('config')
local Event = require('event')
local UI = require('ui')
local Util = require('util')
local fs = _G.fs
local multishell = _ENV.multishell
local os = _G.os
local shell = _ENV.shell
multishell.setTitle(multishell.getCurrent(), 'System')
UI:configure('System', ...)
@ -30,7 +34,6 @@ local systemPage = UI.Page {
},
grid = UI.Grid {
y = 4,
values = paths,
disableHeader = true,
columns = { { key = 'value' } },
autospace = true,
@ -54,7 +57,6 @@ local systemPage = UI.Page {
},
grid = UI.Grid {
y = 5,
values = aliases,
autospace = true,
sortColumn = 'alias',
columns = {
@ -87,7 +89,7 @@ local systemPage = UI.Page {
{ name = '', value = '' },
{ name = 'CC version', value = Util.getVersion() },
{ name = 'Lua version', value = _VERSION },
{ name = 'MC version', value = _MC_VERSION or 'unknown' },
{ name = 'MC version', value = _G._MC_VERSION or 'unknown' },
{ name = 'Disk free', value = Util.toBytes(fs.getFreeSpace('/')) },
{ name = 'Computer ID', value = tostring(os.getComputerID()) },
{ name = 'Day', value = tostring(os.day()) },
@ -129,7 +131,6 @@ end
function systemPage.tabs.aliasTab.grid:draw()
self.values = { }
local aliases = { }
for k,v in pairs(env.aliases) do
table.insert(self.values, { alias = k, path = v })
end
@ -170,7 +171,7 @@ end
function systemPage:eventHandler(event)
if event.type == 'quit' then
Event.exitPullEvents()
UI:exitPullEvents()
elseif event.type == 'tab_activate' then
event.activated:focusFirst()
else
@ -180,5 +181,4 @@ function systemPage:eventHandler(event)
end
UI:setPage(systemPage)
Event.pullEvents()
UI.term:reset()
UI:pullEvents()

View File

@ -1,9 +1,11 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Event = require('event')
local UI = require('ui')
local Util = require('util')
local multishell = _ENV.multishell
multishell.setTitle(multishell.getCurrent(), 'Tabs')
UI:configure('Tabs', ...)

View File

@ -1,31 +1,22 @@
-- Default label
if not os.getComputerLabel() then
local id = os.getComputerID()
if turtle then
os.setComputerLabel('turtle_' .. id)
elseif pocket then
os.setComputerLabel('pocket_' .. id)
elseif commands then
os.setComputerLabel('command_' .. id)
else
os.setComputerLabel('computer_' .. id)
end
end
multishell.term = term.current()
local defaultEnv = { }
for k,v in pairs(getfenv(1)) do
for k,v in pairs(_ENV) do
defaultEnv[k] = v
end
requireInjector(getfenv(1))
_G.requireInjector()
local Config = require('config')
local Opus = require('opus')
local Util = require('util')
local SESSION_FILE = 'usr/config/multishell.session'
local colors = _G.colors
local fs = _G.fs
local keys = _G.keys
local multishell = _ENV.multishell
local os = _G.os
local printError = _G.printError
local term = _G.term
local window = _G.window
local parentTerm = term.current()
local w,h = parentTerm.getSize()
@ -37,6 +28,22 @@ local runningTab
local tabsDirty = false
local closeInd = '*'
multishell.term = term.current()
-- Default label
if not os.getComputerLabel() then
local id = os.getComputerID()
if _G.turtle then
os.setComputerLabel('turtle_' .. id)
elseif _G.pocket then
os.setComputerLabel('pocket_' .. id)
elseif _G.commands then
os.setComputerLabel('command_' .. id)
else
os.setComputerLabel('computer_' .. id)
end
end
if Util.getVersion() >= 1.79 then
closeInd = '\215'
end
@ -59,7 +66,6 @@ local config = {
focusBackgroundColor = colors.gray,
},
}
Config.load('multishell', config)
local _colors = config.standard
@ -229,7 +235,6 @@ local function launchProcess(tab)
selectTab(previousTab)
end
redrawMenu()
saveSession()
end)
tabs[tab.tabId] = tab
@ -243,8 +248,7 @@ local function resizeWindows()
local windowY = 2
local windowHeight = h-1
local keys = Util.keys(tabs)
for _,key in pairs(keys) do
for _,key in pairs(Util.keys(tabs)) do
local tab = tabs[key]
local x,y = tab.window.getCursorPos()
if y > windowHeight then
@ -255,25 +259,11 @@ local function resizeWindows()
end
-- Pass term_resize to all processes
local keys = Util.keys(tabs)
for _,key in pairs(keys) do
for _,key in pairs(Util.keys(tabs)) do
resumeTab(tabs[key], "term_resize")
end
end
local function saveSession()
local t = { }
for _,process in pairs(tabs) do
if process.path and not process.isOverview and not process.hidden then
table.insert(t, {
path = process.path,
args = process.args,
})
end
end
--Util.writeTable(SESSION_FILE, t)
end
local control
local hotkeys = { }
@ -348,7 +338,6 @@ function multishell.terminate(tabId)
local tab = tabs[tabId]
if tab and not tab.isOverview then
if coroutine.status(tab.co) ~= 'dead' then
--os.queueEvent('multishell', 'terminate', tab)
resumeTab(tab, "terminate")
else
tabs[tabId] = nil
@ -399,10 +388,6 @@ function multishell.openTab(tab)
redrawMenu()
end
if not tab.hidden then
saveSession()
end
return tab.tabId
end
@ -423,11 +408,7 @@ function multishell.unhideTab(tabId)
end
function multishell.getCount()
local count
for _,tab in pairs(tabs) do
count = count + 1
end
return count
return Util.size(tabs)
end
-- control-o - overview
@ -435,6 +416,10 @@ multishell.addHotkey(24, function()
multishell.setFocus(overviewTab.tabId)
end)
multishell.addHotkey(20, function()
clipboard.useInternal(not clipboard.isInternal())
end)
-- control-backspace
multishell.addHotkey(14, function()
local tabId = multishell.getFocus()
@ -474,7 +459,6 @@ end)
local function startup()
local hasError
local session = Util.readTable(SESSION_FILE)
if not Opus.loadServices() then
hasError = true
@ -492,12 +476,6 @@ local function startup()
hasError = true
end
if session then
for _,v in pairs(session) do
--multishell.openTab(v)
end
end
if hasError then
print()
error('An autorun program has errored')
@ -514,10 +492,6 @@ multishell.openTab({
title = 'Autorun',
})
if not overviewTab or coroutine.status(overviewTab.co) == 'dead' then
--error('Overview aborted')
end
if not currentTab then
multishell.setFocus(overviewTab.tabId)
end
@ -568,7 +542,6 @@ while true do
lastClicked = nil
if y == 1 then
-- Switch process
local w, h = parentTerm.getSize()
if x == 1 then
multishell.setFocus(overviewTab.tabId)
elseif x == w then
@ -616,8 +589,7 @@ while true do
else
-- Other event
-- Passthrough to all processes
local keys = Util.keys(tabs)
for _,key in pairs(keys) do
for _,key in pairs(Util.keys(tabs)) do
resumeTab(tabs[key], sEvent, tEventData)
end
end

View File

@ -1,4 +1,4 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Security = require('security')
local SHA1 = require('sha1')

View File

@ -1,10 +1,14 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Event = require('event')
local Socket = require('socket')
local Terminal = require('terminal')
local Util = require('util')
local os = _G.os
local read = _G.read
local term = _G.term
local remoteId
local args = { ... }
if #args == 1 then

View File

@ -1,4 +1,4 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Crypto = require('crypto')
local Security = require('security')
@ -6,6 +6,8 @@ local SHA1 = require('sha1')
local Socket = require('socket')
local Terminal = require('terminal')
local os = _G.os
local remoteId
local args = { ... }
@ -13,7 +15,7 @@ if #args == 1 then
remoteId = tonumber(args[1])
else
print('Enter host ID')
remoteId = tonumber(read())
remoteId = tonumber(_G.read())
end
if not remoteId then
@ -34,9 +36,8 @@ if not socket then
end
local publicKey = Security.getPublicKey()
local password = SHA1.sha1(password)
socket:write(Crypto.encrypt({ pk = publicKey, dh = os.getComputerID() }, password))
socket:write(Crypto.encrypt({ pk = publicKey, dh = os.getComputerID() }, SHA1.sha1(password)))
local data = socket:read(2)
socket:close()

View File

@ -1,17 +1,21 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Event = require('event')
local Socket = require('socket')
local Terminal = require('terminal')
local Util = require('util')
local colors = _G.colors
local multishell = _ENV.multishell
local term = _G.term
local remoteId
local args = { ... }
if #args == 1 then
remoteId = tonumber(args[1])
else
print('Enter host ID')
remoteId = tonumber(read())
remoteId = tonumber(_G.read())
end
if not remoteId then
@ -73,7 +77,7 @@ while true do
print()
print('Connection lost')
print('Press enter to exit')
read()
_G.read()
break
end

View File

@ -33,7 +33,7 @@ local BASE = 'https://raw.githubusercontent.com/' .. GIT_REPO
local function makeEnv()
local env = setmetatable({ }, { __index = _G })
for k,v in pairs(getfenv(1)) do
for k,v in pairs(_ENV) do
env[k] = v
end
return env
@ -53,7 +53,7 @@ local function runUrl(file, ...)
local h = http.get(url)
if h then
local fn, m = load(h.readAll(), url, nil, makeEnv())
local fn = load(h.readAll(), url, nil, makeEnv())
h.close()
if fn then
return fn(...)

View File

@ -2,11 +2,11 @@ if _G.clipboard then
return
end
requireInjector(getfenv(1))
_G.requireInjector()
local Util = require('util')
local os = _G.os
_G.clipboard = { internal, data }
local clipboard = { }
function clipboard.getData()
return clipboard.data
@ -36,8 +36,4 @@ function clipboard.useInternal(mode)
end
end
if multishell and multishell.addHotkey then
multishell.addHotkey(20, function()
clipboard.useInternal(not clipboard.isInternal())
end)
end
_G.clipboard = clipboard

View File

@ -1,13 +1,5 @@
if _G.device then
return
end
requireInjector(getfenv(1))
_G.requireInjector()
local Peripheral = require('peripheral')
_G.device = { }
for _,side in pairs(peripheral.getNames()) do
Peripheral.addDevice(device, side)
end
_G.device = Peripheral.getList()

View File

@ -1,8 +1,10 @@
local turtle = _G.turtle
if not turtle or turtle.enableGPS then
return
end
requireInjector(getfenv(1))
_G.requireInjector()
local GPS = require('gps')
local Config = require('config')

View File

@ -1,8 +1,12 @@
local os = _G.os
local peripheral = _G.peripheral
local turtle = _G.turtle
if not turtle or turtle.getPoint then
return
end
requireInjector(getfenv(1))
_G.requireInjector()
local Point = require('point')
local synchronized = require('sync')
@ -1058,25 +1062,25 @@ local actionsAt = {
}
local function _actionAt(action, pt, ...)
local pt = turtle.moveAgainst(pt)
pt = turtle.moveAgainst(pt)
if pt then
return action[pt.direction](...)
end
end
function _actionDownAt(action, pt, ...)
local function _actionDownAt(action, pt, ...)
if turtle.pathfind(Point.above(pt)) then
return action.down(...)
end
end
function _actionForwardAt(action, pt, ...)
local function _actionForwardAt(action, pt, ...)
if turtle.faceAgainst(pt) then
return action.forward(...)
end
end
function _actionUpAt(action, pt, ...)
local function _actionUpAt(action, pt, ...)
if turtle.pathfind(Point.below(pt)) then
return action.up(...)
end

View File

@ -2,9 +2,11 @@ if fs.native then
return
end
requireInjector(getfenv(1))
_G.requireInjector()
local Util = require('util')
local fs = _G.fs
fs.native = Util.shallowCopy(fs)
local fstypes = { }
@ -18,7 +20,7 @@ for k,fn in pairs(fs) do
end
end
function nativefs.list(node, dir, full)
function nativefs.list(node, dir)
local files
if fs.native.isDir(dir) then

View File

@ -111,7 +111,7 @@ device.wireless_modem.open(999)
print('discovery: listening on port 999')
Event.on('modem_message', function(e, s, sport, id, info, distance)
debug(info)
if sport == 999 and tonumber(id) and type(info) == 'table' then
if not network[id] then
network[id] = { }
@ -151,6 +151,7 @@ end
-- every 10 seconds, send out this computer's info
Event.onInterval(10, function()
debug('timer')
sendInfo()
for _,c in pairs(_G.network) do
local elapsed = os.clock()-c.timestamp

View File

@ -1,9 +1,15 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Event = require('event')
local Peripheral = require('peripheral')
local Util = require('util')
local colors = _G.colors
local device = _G.device
local multishell = _ENV.multishell
local os = _G.os
local term = _G.term
multishell.setTitle(multishell.getCurrent(), 'Devices')
local attachColor = colors.green
@ -14,7 +20,7 @@ if not term.isColor() then
detachColor = colors.lightGray
end
Event.on('peripheral', function(event, side)
Event.on('peripheral', function(_, side)
if side then
local dev = Peripheral.addDevice(device, side)
if dev then
@ -25,7 +31,7 @@ Event.on('peripheral', function(event, side)
end
end)
Event.on('peripheral_detach', function(event, side)
Event.on('peripheral_detach', function(_, side)
if side then
local dev = Util.find(device, 'side', side)
if dev then

View File

@ -1,6 +1,6 @@
if device.wireless_modem then
requireInjector(getfenv(1))
_G.requireInjector()
local Config = require('config')
local config = { }

View File

@ -1,14 +1,17 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Terminal = require('terminal')
local Util = require('util')
local multishell = _ENV.multishell
local os = _G.os
local term = _G.term
multishell.setTitle(multishell.getCurrent(), 'Debug')
term.redirect(Terminal.scrollable(term.current(), 50))
local tabId = multishell.getCurrent()
local tab = multishell.getTab(tabId)
local terminal = term.current()
local previousId