better startup
This commit is contained in:
@@ -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
|
|
||||||
@@ -394,7 +394,6 @@ local function watchResources(items)
|
|||||||
for rsDevice, sides in pairs(outputs) do
|
for rsDevice, sides in pairs(outputs) do
|
||||||
for side, enable in pairs(sides) do
|
for side, enable in pairs(sides) do
|
||||||
pcall(function()
|
pcall(function()
|
||||||
debug({ rsDevice, side, enable })
|
|
||||||
device[rsDevice].setOutput(side, enable)
|
device[rsDevice].setOutput(side, enable)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
41
apps/mwm.lua
41
apps/mwm.lua
@@ -16,6 +16,7 @@ local parentTerm = term.current()
|
|||||||
local configFile = args[1] or syntax()
|
local configFile = args[1] or syntax()
|
||||||
local defaultEnv = Util.shallowCopy(getfenv(1))
|
local defaultEnv = Util.shallowCopy(getfenv(1))
|
||||||
local monitor
|
local monitor
|
||||||
|
local exitSession
|
||||||
|
|
||||||
if args[2] then
|
if args[2] then
|
||||||
monitor = peripheral.wrap(args[2]) or syntax()
|
monitor = peripheral.wrap(args[2]) or syntax()
|
||||||
@@ -35,7 +36,7 @@ local function nextUID()
|
|||||||
return UID
|
return UID
|
||||||
end
|
end
|
||||||
|
|
||||||
local function saveConfig()
|
local function saveSession()
|
||||||
local t = { }
|
local t = { }
|
||||||
for _,process in pairs(processes) do
|
for _,process in pairs(processes) do
|
||||||
if process.path and not process.isShell then
|
if process.path and not process.isShell then
|
||||||
@@ -133,7 +134,7 @@ function Process:new(args)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
Util.removeByValue(processes, self)
|
Util.removeByValue(processes, self)
|
||||||
saveConfig()
|
saveSession()
|
||||||
redraw()
|
redraw()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -239,7 +240,7 @@ function Process:resizeClick(x, y)
|
|||||||
self:reposition()
|
self:reposition()
|
||||||
self:resume('term_resize')
|
self:resume('term_resize')
|
||||||
self:drawSizers(true)
|
self:drawSizers(true)
|
||||||
saveConfig()
|
saveSession()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Process:resume(event, ...)
|
function Process:resume(event, ...)
|
||||||
@@ -316,10 +317,11 @@ end
|
|||||||
|
|
||||||
function defaultEnv.multishell.openTab(tabInfo)
|
function defaultEnv.multishell.openTab(tabInfo)
|
||||||
local process = Process:new(tabInfo)
|
local process = Process:new(tabInfo)
|
||||||
saveConfig()
|
saveSession()
|
||||||
return process.uid
|
return process.uid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[ Special shell process for launching programs ]]--
|
||||||
local function addShell()
|
local function addShell()
|
||||||
|
|
||||||
local process = setmetatable({
|
local process = setmetatable({
|
||||||
@@ -357,9 +359,11 @@ local function addShell()
|
|||||||
process.terminal = process.window
|
process.terminal = process.window
|
||||||
|
|
||||||
process.co = coroutine.create(function()
|
process.co = coroutine.create(function()
|
||||||
while true do
|
print('To run a program on the monitor, type "fg <program>"')
|
||||||
os.run(Util.shallowCopy(defaultEnv), shell.resolveProgram('shell'))
|
print('To quit, type "exit"')
|
||||||
end
|
print('Press the [ shell ] button on the monitor to return to this shell')
|
||||||
|
os.run(Util.shallowCopy(defaultEnv), shell.resolveProgram('shell'))
|
||||||
|
exitSession = true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
table.insert(processes, process)
|
table.insert(processes, process)
|
||||||
@@ -370,23 +374,25 @@ local function addShell()
|
|||||||
term.redirect(previousTerm)
|
term.redirect(previousTerm)
|
||||||
end
|
end
|
||||||
|
|
||||||
addShell()
|
local function loadSession()
|
||||||
|
if fs.exists(configFile) then
|
||||||
if fs.exists(configFile) then
|
local config = Util.readTable(configFile)
|
||||||
local config = Util.readTable(configFile)
|
if config then
|
||||||
if config then
|
for _,v in pairs(config) do
|
||||||
for _,v in pairs(config) do
|
Process:new(v)
|
||||||
Process:new(v)
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
while true do
|
addShell()
|
||||||
|
loadSession()
|
||||||
|
|
||||||
|
while not exitSession do
|
||||||
|
|
||||||
local event = { os.pullEventRaw() }
|
local event = { os.pullEventRaw() }
|
||||||
|
|
||||||
if event[1] == 'terminate' then
|
if event[1] == 'terminate' then
|
||||||
term.redirect(parentTerm)
|
|
||||||
break
|
break
|
||||||
|
|
||||||
elseif event[1] == "monitor_touch" then
|
elseif event[1] == "monitor_touch" then
|
||||||
@@ -425,7 +431,7 @@ while true do
|
|||||||
process.y = y
|
process.y = y
|
||||||
process:reposition()
|
process:reposition()
|
||||||
process:drawSizers(true)
|
process:drawSizers(true)
|
||||||
saveConfig()
|
saveSession()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -449,5 +455,6 @@ while true do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
term.redirect(parentTerm)
|
||||||
parentTerm.clear()
|
parentTerm.clear()
|
||||||
parentTerm.setCursorPos(1, 1)
|
parentTerm.setCursorPos(1, 1)
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ function page:runFunction(id, script)
|
|||||||
local fn, msg = loadstring(script, 'script')
|
local fn, msg = loadstring(script, 'script')
|
||||||
if not fn then
|
if not fn then
|
||||||
self.notification:error('Error in script')
|
self.notification:error('Error in script')
|
||||||
debug(msg)
|
-- debug(msg)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -502,6 +502,15 @@
|
|||||||
[ 6 ] = "minecraft:iron_ingot:0",
|
[ 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" ] = {
|
[ "minecraft:stained_glass:0" ] = {
|
||||||
count = 8,
|
count = 8,
|
||||||
ingredients = {
|
ingredients = {
|
||||||
@@ -1758,6 +1767,17 @@
|
|||||||
[ 7 ] = "minecraft:stained_glass:9",
|
[ 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" ] = {
|
[ "minecraft:stained_glass_pane:12" ] = {
|
||||||
count = 16,
|
count = 16,
|
||||||
ingredients = {
|
ingredients = {
|
||||||
|
|||||||
Reference in New Issue
Block a user