1
0
mirror of https://github.com/kepler155c/opus synced 2025-01-12 16:51:05 +00:00

transition to kernel

This commit is contained in:
kepler155c@gmail.com 2018-01-14 18:28:23 -05:00
parent 30dd2a2b16
commit fd1d10a656
9 changed files with 45 additions and 39 deletions

View File

@ -19,7 +19,7 @@ local page = UI.Page {
grid = UI.ScrollingGrid { grid = UI.ScrollingGrid {
y = 2, y = 2,
columns = { columns = {
{ heading = 'ID', key = 'uid', width = 4 }, { heading = 'ID', key = 'uid', width = 3 },
{ heading = 'Title', key = 'title' }, { heading = 'Title', key = 'title' },
{ heading = 'Status', key = 'status' }, { heading = 'Status', key = 'status' },
{ heading = 'Time', key = 'timestamp' }, { heading = 'Time', key = 'timestamp' },

View File

@ -38,3 +38,5 @@ os.queueEvent('network_down')
Event.pullEvent('network_down') Event.pullEvent('network_down')
Util.clear(network) Util.clear(network)
print('Net daemon stopped')

View File

@ -1,18 +1,18 @@
local parentShell = _ENV.shell local parentShell = _ENV.shell
_ENV.shell = { } _ENV.shell = { }
_ENV.multishell = _ENV.multishell or { } --_ENV.multishell = _ENV.multishell or { }
local fs = _G.fs local fs = _G.fs
local shell = _ENV.shell local shell = _ENV.shell
local multishell = _ENV.multishell --local multishell = _ENV.multishell
local sandboxEnv = setmetatable({ }, { __index = _G }) local sandboxEnv = setmetatable({ }, { __index = _G })
for k,v in pairs(_ENV) do for k,v in pairs(_ENV) do
sandboxEnv[k] = v sandboxEnv[k] = v
end end
sandboxEnv.shell = shell sandboxEnv.shell = shell
sandboxEnv.multishell = multishell --sandboxEnv.multishell = multishell
_G.requireInjector() _G.requireInjector()
@ -63,8 +63,8 @@ local function run(env, ...)
error(err) error(err)
end end
if multishell and multishell.setTitle then if _ENV.multishell then
multishell.setTitle(multishell.getCurrent(), fs.getName(path)) _ENV.multishell.setTitle(_ENV.multishell.getCurrent(), fs.getName(path))
end end
if isUrl then if isUrl then
@ -84,15 +84,15 @@ end
function shell.run(...) function shell.run(...)
local oldTitle local oldTitle
if multishell and multishell.getTitle then if _ENV.multishell then
oldTitle = multishell.getTitle(multishell.getCurrent()) oldTitle = _ENV.multishell.getTitle(_ENV.multishell.getCurrent())
end end
local env = setmetatable(Util.shallowCopy(sandboxEnv), { __index = _G }) local env = setmetatable(Util.shallowCopy(sandboxEnv), { __index = _G })
local r = { pcall(run, env, ...) } local r = { pcall(run, env, ...) }
if multishell and multishell.setTitle then if _ENV.multishell then
multishell.setTitle(multishell.getCurrent(), oldTitle or 'shell') _ENV.multishell.setTitle(_ENV.multishell.getCurrent(), oldTitle or 'shell')
end end
return table.unpack(r) return table.unpack(r)
@ -275,6 +275,15 @@ function shell.getRunningProgram()
return tProgramStack[#tProgramStack] return tProgramStack[#tProgramStack]
end end
function shell.setEnv(name, value)
_ENV[name] = value
sandboxEnv[name] = value
end
function shell.getEnv()
return sandboxEnv
end
function shell.setAlias( _sCommand, _sProgram ) function shell.setAlias( _sCommand, _sProgram )
tAliases[_sCommand] = _sProgram tAliases[_sCommand] = _sProgram
end end
@ -306,12 +315,13 @@ function shell.newTab(tabInfo, ...)
table.insert(tabInfo.args, 1, tabInfo.path) table.insert(tabInfo.args, 1, tabInfo.path)
tabInfo.path = 'sys/apps/shell' tabInfo.path = 'sys/apps/shell'
end end
return multishell.openTab(tabInfo) return _ENV.multishell.openTab(tabInfo)
end end
return nil, 'No such program' return nil, 'No such program'
end end
function shell.openTab( ... ) function shell.openTab( ... )
-- needs to use multishell.launch .. so we can run with stock multishell
return shell.newTab({ }, ...) return shell.newTab({ }, ...)
end end
@ -324,7 +334,7 @@ function shell.openHiddenTab( ... )
end end
function shell.switchTab(tabId) function shell.switchTab(tabId)
multishell.setFocus(tabId) _ENV.multishell.setFocus(tabId)
end end
local tArgs = { ... } local tArgs = { ... }

View File

@ -1,8 +1,10 @@
if turtle and device.wireless_modem then local modem = _G.device.wireless_modem
local turtle = _G.turtle
if turtle and modem then
local s, m = turtle.run(function() local s, m = turtle.run(function()
requireInjector(getfenv(1)) _G.requireInjector()
local Config = require('config') local Config = require('config')
local config = { local config = {

View File

@ -2,7 +2,6 @@
local colors = _G.colors local colors = _G.colors
local fs = _G.fs local fs = _G.fs
local http = _G.http local http = _G.http
local os = _G.os
local term = _G.term local term = _G.term
local window = _G.window local window = _G.window
@ -14,9 +13,7 @@ local sandboxEnv = setmetatable({ }, { __index = _G })
for k,v in pairs(_ENV) do for k,v in pairs(_ENV) do
sandboxEnv[k] = v sandboxEnv[k] = v
end end
sandboxEnv.multishell = { }
sandboxEnv.BRANCH = BRANCH sandboxEnv.BRANCH = BRANCH
sandboxEnv.LUA_PATH = 'sys/apis:usr/apis'
_G.debug = function() end _G.debug = function() end
@ -34,7 +31,6 @@ local function showStatus(status, ...)
splashWindow.clearLine() splashWindow.clearLine()
splashWindow.setCursorPos((w - #str) / 2, h) splashWindow.setCursorPos((w - #str) / 2, h)
splashWindow.write(str) splashWindow.write(str)
os.sleep(.1)
end end
local function splash() local function splash()
@ -98,7 +94,6 @@ local function runUrl(file, ...)
error('Failed to download ' .. url) error('Failed to download ' .. url)
end end
local args = { ... } local args = { ... }
splash() splash()
@ -117,18 +112,18 @@ local s, m = pcall(function()
fs.mount('', 'gitfs', GIT_REPO) fs.mount('', 'gitfs', GIT_REPO)
end end
showStatus('Starting kernel') --showStatus('Starting kernel')
run('sys/apps/shell', 'sys/kernel.lua', args[1] and 6 or 7) run('sys/apps/shell', 'sys/kernel.lua', args[1] and 6 or 7)
if args[1] then if args[1] then
local s, m = kernel.run({ local s, m = _G.kernel.run({
title = 'startup', title = 'startup',
path = 'sys/apps/shell', path = 'sys/apps/shell',
args = args, args = args,
haltOnExit = true, haltOnExit = true,
}) })
if s then if s then
kernel.raise(s.uid) _G.kernel.raise(s.uid)
else else
error(m) error(m)
end end

View File

@ -33,6 +33,6 @@ if config.aliases then
end end
end end
shell.setPath(config.path) shell.setPath(config.path)
--sandboxEnv.LUA_PATH = config.lua_path shell.setEnv('LUA_PATH', config.lua_path)
fs.loadTab('usr/etc/fstab') fs.loadTab('usr/etc/fstab')

View File

@ -7,7 +7,6 @@ local colors = _G.colors
local fs = _G.fs local fs = _G.fs
local kernel = _G.kernel local kernel = _G.kernel
local keys = _G.keys local keys = _G.keys
local multishell = _ENV.multishell
local os = _G.os local os = _G.os
local printError = _G.printError local printError = _G.printError
local shell = _ENV.shell local shell = _ENV.shell
@ -19,6 +18,9 @@ local w,h = parentTerm.getSize()
local overviewId local overviewId
local tabsDirty = false local tabsDirty = false
local closeInd = Util.getVersion() >= 1.76 and '\215' or '*' local closeInd = Util.getVersion() >= 1.76 and '\215' or '*'
local multishell = { }
shell.setEnv('multishell', multishell)
multishell.term = parentTerm --deprecated multishell.term = parentTerm --deprecated
@ -141,7 +143,7 @@ function multishell.openTab(tab)
kernel.launch(routine) kernel.launch(routine)
if tab.focused then if tab.focused then
multishell.setFocus(tab.uid) multishell.setFocus(routine.uid)
else else
redrawMenu() redrawMenu()
end end
@ -349,6 +351,7 @@ local function startup()
term.write('[PASS] ') term.write('[PASS] ')
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.write(fs.combine(directory, file)) term.write(fs.combine(directory, file))
print()
else else
if term.isColor() then if term.isColor() then
term.setTextColor(colors.red) term.setTextColor(colors.red)
@ -357,11 +360,10 @@ local function startup()
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.write(fs.combine(directory, file)) term.write(fs.combine(directory, file))
if err then if err then
_G.printError(err) _G.printError('\n' .. err)
end end
success = false success = false
end end
print()
end end
end end
@ -370,20 +372,20 @@ local function startup()
runDir('usr/autorun', shell.run) runDir('usr/autorun', shell.run)
if not success then if not success then
print() multishell.setFocus(multishell.getCurrent())
error('An autorun program has errored') printError('\nA startup program has errored')
os.pullEvent('terminate')
end end
end end
overviewId = multishell.openTab({ overviewId = multishell.openTab({
path = 'sys/apps/Overview.lua', path = 'sys/apps/Overview.lua',
isOverview = true, isOverview = true,
focusd = true, focused = true,
}) })
kernel.find(overviewId).title = '+' kernel.find(overviewId).title = '+'
multishell.openTab({ multishell.openTab({
focused = true,
fn = startup, fn = startup,
title = 'Autorun', title = 'Autorun',
}) })

View File

@ -1,8 +1,3 @@
local sandboxEnv = { }
for k,v in pairs(_ENV) do
sandboxEnv[k] = v
end
_G.requireInjector() _G.requireInjector()
local Util = require('util') local Util = require('util')
@ -18,6 +13,7 @@ _G.kernel = {
local fs = _G.fs local fs = _G.fs
local kernel = _G.kernel local kernel = _G.kernel
local os = _G.os local os = _G.os
local shell = _ENV.shell
local term = _G.term local term = _G.term
local focusedRoutineEvents = Util.transpose { local focusedRoutineEvents = Util.transpose {
@ -111,7 +107,7 @@ function kernel.newRoutine(args)
local routine = setmetatable(args, { __index = Routine }) local routine = setmetatable(args, { __index = Routine })
routine.uid = kernel.UID routine.uid = kernel.UID
routine.timestamp = os.clock() routine.timestamp = os.clock()
routine.env = args.env or Util.shallowCopy(sandboxEnv) routine.env = args.env or Util.shallowCopy(shell.getEnv())
routine.terminal = args.terminal or kernel.terminal routine.terminal = args.terminal or kernel.terminal
routine.window = args.window or kernel.window routine.window = args.window or kernel.window
@ -246,6 +242,7 @@ local function loadExtensions(runLevel)
if not s then if not s then
error(m) error(m)
end end
--os.sleep(0)
end end
end end
end end

View File

@ -122,5 +122,3 @@ Event.on('modem_message', function(_, _, dport, dhost, msg, distance)
end end
end end
end) end)
print('Net transport started')