transition to kernel

This commit is contained in:
kepler155c@gmail.com 2018-01-21 05:44:13 -05:00
parent 1c1eb9b782
commit e59400eb2b
16 changed files with 87 additions and 72 deletions

View File

@ -1,6 +1,7 @@
local DEFAULT_UPATH = 'https://raw.githubusercontent.com/kepler155c/opus/' .. _ENV.BRANCH .. '/sys/apis'
local PASTEBIN_URL = 'http://pastebin.com/raw'
local GIT_URL = 'https://raw.githubusercontent.com'
local DEFAULT_PATH = 'sys/apis'
local DEFAULT_UPATH = GIT_URL .. '/kepler155c/opus/' .. _ENV.BRANCH .. '/sys/apis'
local fs = _G.fs
local http = _G.http
@ -128,8 +129,8 @@ local function requireWrapper(env)
-- place package and require function into env
env.package = {
path = env.LUA_PATH or 'sys/apis',
upath = env.LUA_UPATH or DEFAULT_UPATH,
path = env.LUA_PATH or os.getenv('LUA_PATH') or DEFAULT_PATH,
upath = env.LUA_UPATH or os.getenv('LUA_UPATH') or DEFAULT_UPATH,
config = '/\n:\n?\n!\n-',
loaded = {
math = math,

View File

@ -1,4 +1,4 @@
_G.requireInjector()
_G.requireInjector(_ENV)
local Config = require('config')
local Event = require('event')

View File

@ -1,5 +1,4 @@
local injector = _G.requireInjector or load(_G.http.get('https://raw.githubusercontent.com/kepler155c/opus/master/sys/apis/injector.lua').readAll())()
injector()
_G.requireInjector(_ENV)
local Event = require('event')
local History = require('history')
@ -13,7 +12,7 @@ local textutils = _G.textutils
local sandboxEnv = setmetatable(Util.shallowCopy(_ENV), { __index = _G })
sandboxEnv.exit = function() Event.exitPullEvents() end
sandboxEnv._echo = function( ... ) return { ... } end
injector(sandboxEnv)
_G.requireInjector(sandboxEnv)
UI:configure('Lua', ...)

View File

@ -1,4 +1,4 @@
_G.requireInjector()
_G.requireInjector(_ENV)
local Event = require('event')
local Socket = require('socket')

View File

@ -10,12 +10,17 @@ local Tween = require('ui.tween')
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local fs = _G.fs
local multishell = _ENV.multishell or error('This program requires multishell')
local pocket = _G.pocket
local shell = _ENV.shell
local term = _G.term
local turtle = _G.turtle
if not _ENV.multishell then
error('multishell is required')
end
local REGISTRY_DIR = 'usr/.registry'
UI:configure('Overview', ...)
@ -350,32 +355,16 @@ function page:eventHandler(event)
table.remove(config.Recent, maxRecent + 1)
end
Config.update('Overview', config)
multishell.openTab({
title = event.button.app.title,
path = 'sys/apps/shell',
args = { event.button.app.run },
focused = true,
})
shell.switchTab(shell.openTab(event.button.app.run))
elseif event.type == 'shell' then
multishell.openTab({
path = 'sys/apps/shell',
focused = true,
})
shell.switchTab(shell.openTab('sys/apps/shell'))
elseif event.type == 'lua' then
multishell.openTab({
path ='sys/apps/shell',
args = { 'sys/apps/Lua.lua' },
focused = true,
})
shell.switchTab(shell.openTab('sys/apps/Lua.lua'))
elseif event.type == 'files' then
multishell.openTab({
path ='sys/apps/shell',
args = { 'sys/apps/Files.lua' },
focused = true,
})
shell.switchTab(shell.openTab('sys/apps/Files.lua'))
elseif event.type == 'focus_change' then
if event.focused.parent.UIElement == 'Icon' then

View File

@ -1,4 +1,4 @@
_G.requireInjector()
_G.requireInjector(_ENV)
local Event = require('event')
local UI = require('ui')

View File

@ -304,7 +304,7 @@ function shell.newTab(tabInfo, ...)
if path then
tabInfo.path = path
tabInfo.env = sandboxEnv
tabInfo.env = Util.shallowCopy(sandboxEnv)
tabInfo.args = args
tabInfo.title = fs.getName(path):match('([^%.]+)')
@ -319,7 +319,18 @@ end
function shell.openTab( ... )
-- needs to use multishell.launch .. so we can run with stock multishell
return shell.newTab({ }, ...)
local tWords = tokenise( ... )
local sCommand = tWords[1]
if sCommand then
local sPath = shell.resolveProgram(sCommand)
if sPath == "sys/apps/shell" then
return _ENV.multishell.launch(Util.shallowCopy(sandboxEnv), sPath, table.unpack(tWords, 2))
elseif sPath ~= nil then
return _ENV.multishell.launch(Util.shallowCopy(sandboxEnv), "sys/apps/shell", sCommand, table.unpack(tWords, 2))
else
_G.printError( "No such program" )
end
end
end
function shell.openForegroundTab( ... )

View File

@ -1,9 +1,10 @@
_G.requireInjector()
_G.requireInjector(_ENV)
local Util = require('util')
local kernel = _G.kernel
local keyboard = _G.device.keyboard
local os = _G.os
local textutils = _G.textutils
local data
@ -12,11 +13,14 @@ kernel.hook('clipboard_copy', function(_, args)
data = args[1]
end)
keyboard.addHotkey('shift-paste', function(_, args)
keyboard.addHotkey('control-shift-paste', function(_, args)
if type(data) == 'table' then
local s, m = pcall(textutils.serialize, data)
data = (s and m) or Util.tostring(data)
end
-- replace the event paste data with our internal data
args[1] = Util.tostring(data or '')
if data then
os.queueEvent('paste', data)
end
end)

View File

@ -10,20 +10,19 @@ local multishell = _ENV.multishell
local os = _G.os
local term = _G.term
local routine = kernel.getCurrent()
if multishell then
multishell.setTitle(multishell.getCurrent(), 'System Log')
multishell.hideTab(routine.uid)
end
local w, h = kernel.window.getSize()
kernel.window.reposition(1, 2, w, h - 1)
local routine = kernel.getCurrent()
routine.terminal = kernel.window
routine.window = kernel.window
term.redirect(kernel.window)
local previousId
kernel.hook('mouse_scroll', function(_, eventData)
local dir, y = eventData[1], eventData[3]
@ -42,10 +41,9 @@ end)
keyboard.addHotkey('control-d', function()
local current = kernel.getFocused()
if current.uid ~= routine.uid then
previousId = current.uid
kernel.raise(routine.uid)
elseif previousId then
kernel.raise(previousId)
elseif kernel.routines[2] then
kernel.raise(kernel.routines[2].uid)
end
end)

View File

@ -1,6 +1,7 @@
-- Loads the Opus environment regardless if the file system is local or not
local fs = _G.fs
local http = _G.http
local os = _G.os
local BRANCH = 'develop-1.8'
local GIT_REPO = 'kepler155c/opus/' .. BRANCH
@ -44,6 +45,14 @@ local function runUrl(file, ...)
error('Failed to download ' .. url)
end
function os.getenv(varname)
return sandboxEnv[varname]
end
function os.setenv(varname, value)
sandboxEnv[varname] = value
end
-- Install require shim
if fs.exists('sys/apis/injector.lua') then
_G.requireInjector = run('sys/apis/injector.lua')

View File

@ -15,14 +15,6 @@
\0308\031f.\030 \031 \0308\031f.\030 \031 ",
run = "Turtles.lua",
},
[ "81c0d915fa6d82fd30661c5e66e204cea52bb2b5" ] = {
title = "Activity",
category = "Apps",
icon = "\0318/\030f\031 \030 \0318\\\
\030f \0308\0319o\030f\031 \
\0318\\\030f\031 \030 \0318/",
run = "storageActivity.lua",
},
[ "9f46ca3ef617166776ef6014a58d4e66859caa62" ] = {
title = "DJ",
category = "Games",
@ -114,6 +106,15 @@
\030f ",
run = "sys/apps/Lua.lua",
},
--[[
[ "81c0d915fa6d82fd30661c5e66e204cea52bb2b5" ] = {
title = "Activity",
category = "Apps",
icon = "\0318/\030f\031 \030 \0318\\\
\030f \0308\0319o\030f\031 \
\0318\\\030f\031 \030 \0318/",
run = "storageActivity.lua",
},
[ "89307d419a2fe4fbb69af92b3d3af27b6ec14d3e" ] = {
title = "Telnet",
category = "Apps",
@ -122,6 +123,24 @@
\0314>\0310_\031 ",
run = "telnet.lua",
},
[ "8a77613b475e46064321fd7da18d126ee35e5066" ] = {
title = "VNC",
category = "Apps",
icon = "\
\031e\\\031 \031e/\031dn\
\031e\\/\031 \0319c",
run = "vnc.lua",
},
[ "8d59207c8a84153b3e9f035cc3b6ec7a23671323" ] = {
title = "Micropaint",
category = "Apps",
icon = "\030 \031f \030f \
\030 \031f^ \0300 \030f \
\030 \031fv \0300 \030 ",
run = "http://pastebin.com/raw/tMRzJXx2",
requires = "advancedComputer",
},
--]]
df485c871329671f46570634d63216761441bcd6 = {
title = "Devices",
category = "System",
@ -180,14 +199,6 @@
\030 \031b \030e \030 \031f\\",
run = "recorder.lua",
},
[ "8a77613b475e46064321fd7da18d126ee35e5066" ] = {
title = "VNC",
category = "Apps",
icon = "\
\031e\\\031 \031e/\031dn\
\031e\\/\031 \0319c",
run = "vnc.lua",
},
[ "6ce6c512ea433a7fc5c8841628e7696cd0ff7f2b" ] = {
title = "Files",
category = "Apps",
@ -259,15 +270,6 @@
\030 \031f \0300 \0310 ",
run = "https://gist.github.com/LDDestroier/c7528d95bc0103545c2a/raw",
},
[ "8d59207c8a84153b3e9f035cc3b6ec7a23671323" ] = {
title = "Micropaint",
category = "Apps",
icon = "\030 \031f \030f \
\030 \031f^ \0300 \030f \
\030 \031fv \0300 \030 ",
run = "http://pastebin.com/raw/tMRzJXx2",
requires = "advancedComputer",
},
[ "d78f28759f255a0db76604ee560b87c4715a0da5" ] = {
title = "Sketch",
category = "Apps",

View File

@ -1,4 +1,4 @@
_G.requireInjector()
_G.requireInjector(_ENV)
local Peripheral = require('peripheral')

View File

@ -3,6 +3,7 @@ _G.requireInjector()
local Util = require('util')
local fs = _G.fs
local os = _G.os
local shell = _ENV.shell
if not fs.exists('usr/apps') then
@ -12,7 +13,8 @@ if not fs.exists('usr/autorun') then
fs.makeDir('usr/autorun')
end
if not fs.exists('usr/config/fstab') then
Util.writeFile('usr/config/fstab', 'usr gitfs kepler155c/opus-apps/' .. _ENV.BRANCH)
Util.writeFile('usr/config/fstab',
'usr gitfs kepler155c/opus-apps/' .. os.getenv('BRANCH'))
end
if not fs.exists('usr/config/shell') then
@ -33,6 +35,6 @@ if config.aliases then
end
end
shell.setPath(config.path)
shell.setEnv('LUA_PATH', config.lua_path)
os.setenv('LUA_PATH', config.lua_path)
fs.loadTab('usr/config/fstab')

View File

@ -13,7 +13,7 @@ local shell = _ENV.shell
local term = _G.term
local window = _G.window
local parentTerm = _G.device.terminal -- term.current()
local parentTerm = _G.device.terminal
local w,h = parentTerm.getSize()
local overviewId
local tabsDirty = false

View File

@ -1,4 +1,4 @@
_G.requireInjector()
_G.requireInjector(_ENV)
local Terminal = require('terminal')
local Util = require('util')
@ -137,8 +137,8 @@ function kernel.launch(routine)
err = 'kernel: invalid routine'
end
if not result and err and err ~= 'Terminated' then
error(err, 2)
if not result and err ~= 'Terminated' then
error(err or 'Error occurred', 2)
end
end)