better startup

This commit is contained in:
kepler155c
2017-09-25 22:49:25 -04:00
parent 8d1acbbd7c
commit 08acd126c8
6 changed files with 45 additions and 87 deletions

View File

@@ -1,16 +0,0 @@
requireInjector(getfenv(1))
local Util = require('util')
local Configurator = { }
function Configurator.get()
print('Select device')
for k,v in pairs(device) do
Util.print('%s [%s]', v.name, v.side)
end
end
Configurator.get()
return Configurator

View File

@@ -394,7 +394,6 @@ local function watchResources(items)
for rsDevice, sides in pairs(outputs) do
for side, enable in pairs(sides) do
pcall(function()
debug({ rsDevice, side, enable })
device[rsDevice].setOutput(side, enable)
end)
end

View File

@@ -16,6 +16,7 @@ local parentTerm = term.current()
local configFile = args[1] or syntax()
local defaultEnv = Util.shallowCopy(getfenv(1))
local monitor
local exitSession
if args[2] then
monitor = peripheral.wrap(args[2]) or syntax()
@@ -35,7 +36,7 @@ local function nextUID()
return UID
end
local function saveConfig()
local function saveSession()
local t = { }
for _,process in pairs(processes) do
if process.path and not process.isShell then
@@ -133,7 +134,7 @@ function Process:new(args)
end
end
Util.removeByValue(processes, self)
saveConfig()
saveSession()
redraw()
end)
@@ -239,7 +240,7 @@ function Process:resizeClick(x, y)
self:reposition()
self:resume('term_resize')
self:drawSizers(true)
saveConfig()
saveSession()
end
function Process:resume(event, ...)
@@ -316,10 +317,11 @@ end
function defaultEnv.multishell.openTab(tabInfo)
local process = Process:new(tabInfo)
saveConfig()
saveSession()
return process.uid
end
--[[ Special shell process for launching programs ]]--
local function addShell()
local process = setmetatable({
@@ -357,9 +359,11 @@ local function addShell()
process.terminal = process.window
process.co = coroutine.create(function()
while true do
os.run(Util.shallowCopy(defaultEnv), shell.resolveProgram('shell'))
end
print('To run a program on the monitor, type "fg <program>"')
print('To quit, type "exit"')
print('Press the [ shell ] button on the monitor to return to this shell')
os.run(Util.shallowCopy(defaultEnv), shell.resolveProgram('shell'))
exitSession = true
end)
table.insert(processes, process)
@@ -370,23 +374,25 @@ local function addShell()
term.redirect(previousTerm)
end
addShell()
if fs.exists(configFile) then
local config = Util.readTable(configFile)
if config then
for _,v in pairs(config) do
Process:new(v)
local function loadSession()
if fs.exists(configFile) then
local config = Util.readTable(configFile)
if config then
for _,v in pairs(config) do
Process:new(v)
end
end
end
end
while true do
addShell()
loadSession()
while not exitSession do
local event = { os.pullEventRaw() }
if event[1] == 'terminate' then
term.redirect(parentTerm)
break
elseif event[1] == "monitor_touch" then
@@ -425,7 +431,7 @@ while true do
process.y = y
process:reposition()
process:drawSizers(true)
saveConfig()
saveSession()
end
end
@@ -449,5 +455,6 @@ while true do
end
end
term.redirect(parentTerm)
parentTerm.clear()
parentTerm.setCursorPos(1, 1)

View File

@@ -327,7 +327,7 @@ function page:runFunction(id, script)
local fn, msg = loadstring(script, 'script')
if not fn then
self.notification:error('Error in script')
debug(msg)
-- debug(msg)
return
end

View File

@@ -1,52 +0,0 @@
local args = { ... }
local GIT_REPO = 'kepler155c/opus/master'
local BASE = 'https://raw.githubusercontent.com/' .. GIT_REPO
local function dourl(env, url)
local h = http.get(url)
if h then
local fn, m = load(h.readAll(), url, nil, env)
h.close()
if fn then
return fn()
end
end
error('Failed to download ' .. url)
end
local s, m = pcall(function()
_G.requireInjector = dourl(getfenv(1), BASE .. '/sys/apis/injector.lua')
local function mkenv()
local env = { }
for k,v in pairs(getfenv(1)) do
env[k] = v
end
setmetatable(env, { __index = _G })
return env
end
-- install vfs
dourl(mkenv(), BASE .. '/sys/extensions/vfs.lua')
-- install filesystem
fs.mount('', 'gitfs', GIT_REPO)
fs.mount('usr', 'gitfs', 'kepler155c/opus-apps/master')
-- start program
local file = table.remove(args, 1)
local s, m = os.run(mkenv(), file or 'startup', unpack(args))
if not s and m then
error(m)
end
end)
if not s and m then
printError(m)
end
if fs.restore then
fs.restore()
end

View File

@@ -502,6 +502,15 @@
[ 6 ] = "minecraft:iron_ingot:0",
},
},
[ "minecraft:brewing_stand:0" ] = {
count = 1,
ingredients = {
[ 7 ] = "minecraft:cobblestone:0",
[ 2 ] = "minecraft:blaze_rod:0",
[ 5 ] = "minecraft:cobblestone:0",
[ 6 ] = "minecraft:cobblestone:0",
},
},
[ "minecraft:stained_glass:0" ] = {
count = 8,
ingredients = {
@@ -1758,6 +1767,17 @@
[ 7 ] = "minecraft:stained_glass:9",
},
},
[ "minecraft:iron_door:0" ] = {
count = 3,
ingredients = {
"minecraft:iron_ingot:0",
"minecraft:iron_ingot:0",
[ 9 ] = "minecraft:iron_ingot:0",
[ 10 ] = "minecraft:iron_ingot:0",
[ 5 ] = "minecraft:iron_ingot:0",
[ 6 ] = "minecraft:iron_ingot:0",
},
},
[ "minecraft:stained_glass_pane:12" ] = {
count = 16,
ingredients = {