transition to kernel

This commit is contained in:
kepler155c@gmail.com 2018-01-15 20:38:30 -05:00
parent bd37d32750
commit d85e9b96b2
6 changed files with 89 additions and 82 deletions

View File

@ -1,9 +1,6 @@
-- Loads the Opus environment regardless if the file system is local or not
local colors = _G.colors
local fs = _G.fs
local http = _G.http
local term = _G.term
local window = _G.window
local BRANCH = 'develop-1.8'
local GIT_REPO = 'kepler155c/opus/' .. BRANCH
@ -17,46 +14,6 @@ sandboxEnv.BRANCH = BRANCH
_G.debug = function() end
local terminal = term.current()
local w, h = term.getSize()
local kernelWindow = window.create(terminal, 1, 1, w, h, false)
term.redirect(kernelWindow)
kernelWindow.parent = terminal
local splashWindow
local function splash()
splashWindow = window.create(terminal, 1, 1, w, h, false)
splashWindow.setTextColor(colors.white)
if splashWindow.isColor() then
splashWindow.setBackgroundColor(colors.black)
splashWindow.clear()
local opus = {
'fffff00',
'ffff07000',
'ff00770b00 4444',
'ff077777444444444',
'f07777744444444444',
'f0000777444444444',
'070000111744444',
'777770000',
'7777000000',
'70700000000',
'077000000000',
}
for k,line in ipairs(opus) do
splashWindow.setCursorPos((w - 18) / 2, k + (h - #opus) / 2)
splashWindow.blit(string.rep(' ', #line), string.rep('a', #line), line)
end
end
local str = 'Loading Opus OS...'
print(str)
splashWindow.setCursorPos((w - #str) / 2, h)
splashWindow.write(str)
splashWindow.setVisible(true)
return splashWindow
end
local function makeEnv()
local env = setmetatable({ }, { __index = _G })
for k,v in pairs(sandboxEnv) do
@ -92,7 +49,6 @@ end
local args = { ... }
splash()
local s, m = pcall(function()
-- Install require shim
if fs.exists('sys/apis/injector.lua') then
@ -106,37 +62,12 @@ local s, m = pcall(function()
fs.mount('', 'gitfs', GIT_REPO)
end
-- runLevel 6 if passed a program to run
-- otherwise, runLevel 7 (multishell)
run('sys/apps/shell', 'sys/kernel.lua', args[1] and 6 or 7)
kernel.hook('kernel_ready', function()
splashWindow.setVisible(false)
kernelWindow.setVisible(true)
if args[1] then
local s, m = _G.kernel.run({
title = 'startup',
path = 'sys/apps/shell',
args = args,
haltOnExit = true,
})
if s then
_G.kernel.raise(s.uid)
else
error(m)
end
end
end)
_G.kernel.start()
run('sys/apps/shell', 'sys/kernel.lua', table.unpack(args))
end)
if not s then
splashWindow.setVisible(false)
kernelWindow.setVisible(true)
print('\nError loading Opus OS\n')
_G.printError(m .. '\n')
term.redirect(terminal)
end
if fs.restore then

View File

@ -0,0 +1,44 @@
if false then
local colors = _G.colors
local term = _G.term
local window = _G.window
local terminal = term.current()
local w, h = term.getSize()
local splashWindow = window.create(terminal.parent, 1, 1, w, h, false)
splashWindow.setTextColor(colors.white)
if splashWindow.isColor() then
splashWindow.setBackgroundColor(colors.black)
splashWindow.clear()
local opus = {
'fffff00',
'ffff07000',
'ff00770b00 4444',
'ff077777444444444',
'f07777744444444444',
'f0000777444444444',
'070000111744444',
'777770000',
'7777000000',
'70700000000',
'077000000000',
}
for k,line in ipairs(opus) do
splashWindow.setCursorPos((w - 18) / 2, k + (h - #opus) / 2)
splashWindow.blit(string.rep(' ', #line), string.rep('a', #line), line)
end
end
local str = 'Loading Opus OS...'
print(str)
splashWindow.setCursorPos((w - #str) / 2, h)
splashWindow.write(str)
terminal.setVisible(false)
splashWindow.setVisible(true)
kernel.hook('kernel_ready', function()
kernel.window.setVisible(true)
end)
end

View File

@ -4,7 +4,7 @@ local Peripheral = require('peripheral')
_G.device = Peripheral.getList()
_G.device.terminal = _G.kernel.terminal.parent
_G.device.terminal = _G.kernel.terminal
_G.device.terminal.side = 'terminal'
_G.device.terminal.type = 'terminal'
_G.device.terminal.name = 'terminal'

View File

@ -1,4 +1,5 @@
local kernel = _G.kernel
local os = _G.os
_G.network = { }
@ -18,4 +19,5 @@ end)
if _G.device.wireless_modem then
startNetwork()
os.sleep(0) -- give the network a cycle to start
end

View File

@ -6,8 +6,6 @@ _G.kernel = {
UID = 0,
hooks = { },
routines = { },
terminal = _G.term.current(),
window = _G.term.current(),
}
local fs = _G.fs
@ -15,6 +13,11 @@ local kernel = _G.kernel
local os = _G.os
local shell = _ENV.shell
local term = _G.term
local window = _G.window
local w, h = term.getSize()
kernel.terminal = term.current()
kernel.window = window.create(kernel.terminal, 1, 1, w, h, false)
local focusedRoutineEvents = Util.transpose {
'char', 'key', 'key_up',
@ -77,6 +80,9 @@ function Routine:resume(event, ...)
self.filter = result
else
_G.printError(result)
if self.haltOnError then
error(result)
end
end
if coroutine.status(self.co) == 'dead' then
Util.removeByValue(kernel.routines, self)
@ -108,7 +114,7 @@ function kernel.newRoutine(args)
routine.uid = kernel.UID
routine.timestamp = os.clock()
routine.env = args.env or Util.shallowCopy(shell.getEnv())
routine.terminal = args.terminal or kernel.terminal
routine.terminal = args.terminal or kernel.window
routine.window = args.window or kernel.window
return routine
@ -127,7 +133,7 @@ function kernel.launch(routine)
end
if not result and err and err ~= 'Terminated' then
_G.printError(tostring(err))
error(err, 2)
end
end)
@ -219,19 +225,22 @@ function kernel.start()
local eventData = { os.pullEventRaw() }
local event = table.remove(eventData, 1)
kernel.event(event, eventData)
until event == 'kernel_halt' or not kernel.routines[1]
until event == 'kernel_halt'
end)
kernel.window.setVisible(true)
if not s then
kernel.window.setVisible(true)
term.redirect(kernel.window)
print('\nCrash detected\n')
_G.printError(m)
end
term.redirect(kernel.terminal)
end
local function init(runLevel)
runLevel = tonumber(runLevel) or error('Invalid run level')
local function init(...)
local args = { ... }
local runLevel = #args > 0 and 6 or 7
local dir = 'sys/extensions'
local files = fs.list(dir)
@ -245,11 +254,32 @@ local function init(runLevel)
end
end
end
os.queueEvent('kernel_ready')
if args[1] then
kernel.hook('kernel_ready', function()
local s, m = kernel.run({
title = args[1],
path = 'sys/apps/shell',
args = args,
haltOnExit = true,
terminal = kernel.terminal,
})
if s then
kernel.raise(s.uid)
else
error(m)
end
end)
end
end
kernel.run({
fn = init,
title = 'init',
haltOnError = true,
args = { ... },
})
kernel.start()

View File

@ -22,7 +22,7 @@ end
-- need: window.getParent()
-- window.copy(target)
local terminal = _G.kernel.terminal.parent
local terminal = _G.kernel.terminal
local w, h = kernel.window.getSize()
local win = window.create(kernel.window, 1, 1, w, h + 50, false)
@ -52,12 +52,12 @@ Terminal.scrollable(win, kernel.window)
-- update kernel with new window, set this tab with the new kernal window
local routine = kernel.getCurrent()
for _,r in pairs(kernel.routines) do
if r.terminal == kernel.terminal then
if r.terminal == kernel.window then
r.terminal = win
r.window = win
end
end
kernel.terminal = win
--kernel.terminal = win
kernel.window = win
routine.terminal = win
routine.window = win