mirror of
https://github.com/kepler155c/opus
synced 2024-12-24 15:40:26 +00:00
transition to kernel
This commit is contained in:
parent
30dd2a2b16
commit
fd1d10a656
@ -19,7 +19,7 @@ local page = UI.Page {
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2,
|
||||
columns = {
|
||||
{ heading = 'ID', key = 'uid', width = 4 },
|
||||
{ heading = 'ID', key = 'uid', width = 3 },
|
||||
{ heading = 'Title', key = 'title' },
|
||||
{ heading = 'Status', key = 'status' },
|
||||
{ heading = 'Time', key = 'timestamp' },
|
||||
|
@ -38,3 +38,5 @@ os.queueEvent('network_down')
|
||||
Event.pullEvent('network_down')
|
||||
|
||||
Util.clear(network)
|
||||
|
||||
print('Net daemon stopped')
|
||||
|
@ -1,18 +1,18 @@
|
||||
local parentShell = _ENV.shell
|
||||
|
||||
_ENV.shell = { }
|
||||
_ENV.multishell = _ENV.multishell or { }
|
||||
--_ENV.multishell = _ENV.multishell or { }
|
||||
|
||||
local fs = _G.fs
|
||||
local shell = _ENV.shell
|
||||
local multishell = _ENV.multishell
|
||||
--local multishell = _ENV.multishell
|
||||
|
||||
local sandboxEnv = setmetatable({ }, { __index = _G })
|
||||
for k,v in pairs(_ENV) do
|
||||
sandboxEnv[k] = v
|
||||
end
|
||||
sandboxEnv.shell = shell
|
||||
sandboxEnv.multishell = multishell
|
||||
--sandboxEnv.multishell = multishell
|
||||
|
||||
_G.requireInjector()
|
||||
|
||||
@ -63,8 +63,8 @@ local function run(env, ...)
|
||||
error(err)
|
||||
end
|
||||
|
||||
if multishell and multishell.setTitle then
|
||||
multishell.setTitle(multishell.getCurrent(), fs.getName(path))
|
||||
if _ENV.multishell then
|
||||
_ENV.multishell.setTitle(_ENV.multishell.getCurrent(), fs.getName(path))
|
||||
end
|
||||
|
||||
if isUrl then
|
||||
@ -84,15 +84,15 @@ end
|
||||
function shell.run(...)
|
||||
local oldTitle
|
||||
|
||||
if multishell and multishell.getTitle then
|
||||
oldTitle = multishell.getTitle(multishell.getCurrent())
|
||||
if _ENV.multishell then
|
||||
oldTitle = _ENV.multishell.getTitle(_ENV.multishell.getCurrent())
|
||||
end
|
||||
|
||||
local env = setmetatable(Util.shallowCopy(sandboxEnv), { __index = _G })
|
||||
local r = { pcall(run, env, ...) }
|
||||
|
||||
if multishell and multishell.setTitle then
|
||||
multishell.setTitle(multishell.getCurrent(), oldTitle or 'shell')
|
||||
if _ENV.multishell then
|
||||
_ENV.multishell.setTitle(_ENV.multishell.getCurrent(), oldTitle or 'shell')
|
||||
end
|
||||
|
||||
return table.unpack(r)
|
||||
@ -275,6 +275,15 @@ function shell.getRunningProgram()
|
||||
return tProgramStack[#tProgramStack]
|
||||
end
|
||||
|
||||
function shell.setEnv(name, value)
|
||||
_ENV[name] = value
|
||||
sandboxEnv[name] = value
|
||||
end
|
||||
|
||||
function shell.getEnv()
|
||||
return sandboxEnv
|
||||
end
|
||||
|
||||
function shell.setAlias( _sCommand, _sProgram )
|
||||
tAliases[_sCommand] = _sProgram
|
||||
end
|
||||
@ -306,12 +315,13 @@ function shell.newTab(tabInfo, ...)
|
||||
table.insert(tabInfo.args, 1, tabInfo.path)
|
||||
tabInfo.path = 'sys/apps/shell'
|
||||
end
|
||||
return multishell.openTab(tabInfo)
|
||||
return _ENV.multishell.openTab(tabInfo)
|
||||
end
|
||||
return nil, 'No such program'
|
||||
end
|
||||
|
||||
function shell.openTab( ... )
|
||||
-- needs to use multishell.launch .. so we can run with stock multishell
|
||||
return shell.newTab({ }, ...)
|
||||
end
|
||||
|
||||
@ -324,7 +334,7 @@ function shell.openHiddenTab( ... )
|
||||
end
|
||||
|
||||
function shell.switchTab(tabId)
|
||||
multishell.setFocus(tabId)
|
||||
_ENV.multishell.setFocus(tabId)
|
||||
end
|
||||
|
||||
local tArgs = { ... }
|
||||
|
@ -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()
|
||||
|
||||
requireInjector(getfenv(1))
|
||||
_G.requireInjector()
|
||||
|
||||
local Config = require('config')
|
||||
local config = {
|
||||
|
@ -2,7 +2,6 @@
|
||||
local colors = _G.colors
|
||||
local fs = _G.fs
|
||||
local http = _G.http
|
||||
local os = _G.os
|
||||
local term = _G.term
|
||||
local window = _G.window
|
||||
|
||||
@ -14,9 +13,7 @@ local sandboxEnv = setmetatable({ }, { __index = _G })
|
||||
for k,v in pairs(_ENV) do
|
||||
sandboxEnv[k] = v
|
||||
end
|
||||
sandboxEnv.multishell = { }
|
||||
sandboxEnv.BRANCH = BRANCH
|
||||
sandboxEnv.LUA_PATH = 'sys/apis:usr/apis'
|
||||
|
||||
_G.debug = function() end
|
||||
|
||||
@ -34,7 +31,6 @@ local function showStatus(status, ...)
|
||||
splashWindow.clearLine()
|
||||
splashWindow.setCursorPos((w - #str) / 2, h)
|
||||
splashWindow.write(str)
|
||||
os.sleep(.1)
|
||||
end
|
||||
|
||||
local function splash()
|
||||
@ -98,7 +94,6 @@ local function runUrl(file, ...)
|
||||
error('Failed to download ' .. url)
|
||||
end
|
||||
|
||||
|
||||
local args = { ... }
|
||||
|
||||
splash()
|
||||
@ -117,18 +112,18 @@ local s, m = pcall(function()
|
||||
fs.mount('', 'gitfs', GIT_REPO)
|
||||
end
|
||||
|
||||
showStatus('Starting kernel')
|
||||
--showStatus('Starting kernel')
|
||||
run('sys/apps/shell', 'sys/kernel.lua', args[1] and 6 or 7)
|
||||
|
||||
if args[1] then
|
||||
local s, m = kernel.run({
|
||||
local s, m = _G.kernel.run({
|
||||
title = 'startup',
|
||||
path = 'sys/apps/shell',
|
||||
args = args,
|
||||
haltOnExit = true,
|
||||
})
|
||||
if s then
|
||||
kernel.raise(s.uid)
|
||||
_G.kernel.raise(s.uid)
|
||||
else
|
||||
error(m)
|
||||
end
|
||||
|
@ -33,6 +33,6 @@ if config.aliases then
|
||||
end
|
||||
end
|
||||
shell.setPath(config.path)
|
||||
--sandboxEnv.LUA_PATH = config.lua_path
|
||||
shell.setEnv('LUA_PATH', config.lua_path)
|
||||
|
||||
fs.loadTab('usr/etc/fstab')
|
||||
|
@ -7,7 +7,6 @@ local colors = _G.colors
|
||||
local fs = _G.fs
|
||||
local kernel = _G.kernel
|
||||
local keys = _G.keys
|
||||
local multishell = _ENV.multishell
|
||||
local os = _G.os
|
||||
local printError = _G.printError
|
||||
local shell = _ENV.shell
|
||||
@ -19,6 +18,9 @@ local w,h = parentTerm.getSize()
|
||||
local overviewId
|
||||
local tabsDirty = false
|
||||
local closeInd = Util.getVersion() >= 1.76 and '\215' or '*'
|
||||
local multishell = { }
|
||||
|
||||
shell.setEnv('multishell', multishell)
|
||||
|
||||
multishell.term = parentTerm --deprecated
|
||||
|
||||
@ -141,7 +143,7 @@ function multishell.openTab(tab)
|
||||
kernel.launch(routine)
|
||||
|
||||
if tab.focused then
|
||||
multishell.setFocus(tab.uid)
|
||||
multishell.setFocus(routine.uid)
|
||||
else
|
||||
redrawMenu()
|
||||
end
|
||||
@ -349,6 +351,7 @@ local function startup()
|
||||
term.write('[PASS] ')
|
||||
term.setTextColor(colors.white)
|
||||
term.write(fs.combine(directory, file))
|
||||
print()
|
||||
else
|
||||
if term.isColor() then
|
||||
term.setTextColor(colors.red)
|
||||
@ -357,11 +360,10 @@ local function startup()
|
||||
term.setTextColor(colors.white)
|
||||
term.write(fs.combine(directory, file))
|
||||
if err then
|
||||
_G.printError(err)
|
||||
_G.printError('\n' .. err)
|
||||
end
|
||||
success = false
|
||||
end
|
||||
print()
|
||||
end
|
||||
end
|
||||
|
||||
@ -370,20 +372,20 @@ local function startup()
|
||||
runDir('usr/autorun', shell.run)
|
||||
|
||||
if not success then
|
||||
print()
|
||||
error('An autorun program has errored')
|
||||
multishell.setFocus(multishell.getCurrent())
|
||||
printError('\nA startup program has errored')
|
||||
os.pullEvent('terminate')
|
||||
end
|
||||
end
|
||||
|
||||
overviewId = multishell.openTab({
|
||||
path = 'sys/apps/Overview.lua',
|
||||
isOverview = true,
|
||||
focusd = true,
|
||||
focused = true,
|
||||
})
|
||||
kernel.find(overviewId).title = '+'
|
||||
|
||||
multishell.openTab({
|
||||
focused = true,
|
||||
fn = startup,
|
||||
title = 'Autorun',
|
||||
})
|
||||
|
@ -1,8 +1,3 @@
|
||||
local sandboxEnv = { }
|
||||
for k,v in pairs(_ENV) do
|
||||
sandboxEnv[k] = v
|
||||
end
|
||||
|
||||
_G.requireInjector()
|
||||
|
||||
local Util = require('util')
|
||||
@ -18,6 +13,7 @@ _G.kernel = {
|
||||
local fs = _G.fs
|
||||
local kernel = _G.kernel
|
||||
local os = _G.os
|
||||
local shell = _ENV.shell
|
||||
local term = _G.term
|
||||
|
||||
local focusedRoutineEvents = Util.transpose {
|
||||
@ -111,7 +107,7 @@ function kernel.newRoutine(args)
|
||||
local routine = setmetatable(args, { __index = Routine })
|
||||
routine.uid = kernel.UID
|
||||
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.window = args.window or kernel.window
|
||||
|
||||
@ -246,6 +242,7 @@ local function loadExtensions(runLevel)
|
||||
if not s then
|
||||
error(m)
|
||||
end
|
||||
--os.sleep(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -122,5 +122,3 @@ Event.on('modem_message', function(_, _, dport, dhost, msg, distance)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
print('Net transport started')
|
||||
|
Loading…
Reference in New Issue
Block a user