1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-21 18:57:41 +00:00
This commit is contained in:
kepler155c@gmail.com
2017-10-08 17:45:01 -04:00
parent 98ec840db1
commit a625b52bad
46 changed files with 334 additions and 319 deletions

View File

@@ -1,11 +1,15 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Config = require('config')
local Event = require('event')
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local colors = _G.colors
local fs = _G.fs
local multishell = _ENV.multishell
local os = _G.os
local shell = _ENV.shell
multishell.setTitle(multishell.getCurrent(), 'Files')
UI:configure('Files', ...)
@@ -158,7 +162,7 @@ function Browser:setStatus(status, ...)
end
function Browser:unmarkAll()
for k,m in pairs(marked) do
for _,m in pairs(marked) do
m.marked = false
end
Util.clear(marked)
@@ -198,7 +202,6 @@ function Browser:updateDirectory(dir)
dir.size = #files
for _, file in pairs(files) do
file.fullName = fs.combine(dir.name, file.name)
file.directory = directory
file.flags = ''
if not file.isDir then
dir.totalSize = dir.totalSize + file.size
@@ -232,7 +235,7 @@ function Browser:setDir(dirName, noStatus)
if self.dir then
self.dir.index = self.grid:getIndex()
end
DIR = fs.combine('', dirName)
local DIR = fs.combine('', dirName)
shell.setDir(DIR)
local s, dir = self:getDirectory(DIR)
if s then

View File

@@ -1,4 +1,4 @@
requireInjector(getfenv(1))
_G.requireInjector()
local UI = require('ui')
local Util = require('util')

View File

@@ -1,15 +1,18 @@
requireInjector = requireInjector or load(http.get('https://raw.githubusercontent.com/kepler155c/opus/master/sys/apis/injector.lua').readAll())()
requireInjector(getfenv(1))
local injector = _G.requireInjector or load(http.get('https://raw.githubusercontent.com/kepler155c/opus/master/sys/apis/injector.lua').readAll())()
injector()
local Event = require('event')
local History = require('history')
local UI = require('ui')
local Util = require('util')
local Event = require('event')
local History = require('history')
local Peripheral = require('peripheral')
local UI = require('ui')
local Util = require('util')
local sandboxEnv = setmetatable(Util.shallowCopy(getfenv(1)), { __index = _G })
local multishell = _ENV.multishell
local sandboxEnv = setmetatable(Util.shallowCopy(_ENV), { __index = _G })
sandboxEnv.exit = function() Event.exitPullEvents() end
sandboxEnv._echo = function( ... ) return ... end
requireInjector(sandboxEnv)
injector(sandboxEnv)
multishell.setTitle(multishell.getCurrent(), 'Lua')
UI:configure('Lua', ...)
@@ -112,12 +115,12 @@ function page:eventHandler(event)
if event.type == 'global' then
self:setPrompt('', true)
self:executeStatement('getfenv(0)')
self:executeStatement('_G')
command = nil
elseif event.type == 'local' then
self:setPrompt('', true)
self:executeStatement('getfenv(1)')
self:executeStatement('_ENV')
command = nil
elseif event.type == 'autocomplete' then
@@ -129,11 +132,7 @@ function page:eventHandler(event)
elseif event.type == 'device' then
if not _G.device then
sandboxEnv.device = { }
for _,side in pairs(peripheral.getNames()) do
local key = string.format('%s:%s', peripheral.getType(side), side)
sandboxEnv.device[ key ] = peripheral.wrap(side)
end
sandboxEnv.device = Peripheral.getList()
end
self:setPrompt('device', true)
self:executeStatement('device')
@@ -187,8 +186,7 @@ function page:setResult(result)
local t = { }
local function safeValue(v)
local t = type(v)
if t == 'string' or t == 'number' then
if type(v) == 'string' or type(v) == 'number' then
return v
end
return tostring(v)
@@ -205,7 +203,7 @@ function page:setResult(result)
if type(v) == 'table' then
if Util.size(v) == 0 then
entry.value = 'table: (empty)'
else
else
entry.value = 'table'
end
end
@@ -243,7 +241,7 @@ function page.grid:eventHandler(event)
if type(entry.rawName) == 'number' then
return command .. '[' .. entry.name .. ']'
end
if entry.name:match("%W") or
if entry.name:match("%W") or
entry.name:sub(1, 1):match("%d") then
return command .. "['" .. tostring(entry.name) .. "']"
end

View File

@@ -1,10 +1,16 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Event = require('event')
local Socket = require('socket')
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local device = _G.device
local multishell = _ENV.multishell
local network = _G.network
local shell = _ENV.shell
multishell.setTitle(multishell.getCurrent(), 'Network')
UI:configure('Network', ...)
@@ -124,14 +130,14 @@ Event.onInterval(1, function()
page:sync()
end)
Event.on('device_attach', function(h, deviceName)
Event.on('device_attach', function(_, deviceName)
if deviceName == 'wireless_modem' then
page.notification:success('Modem connected')
page:sync()
end
end)
Event.on('device_detach', function(h, deviceName)
Event.on('device_detach', function(_, deviceName)
if deviceName == 'wireless_modem' then
page.notification:error('Wireless modem not attached')
page:sync()

View File

@@ -1,4 +1,4 @@
requireInjector(getfenv(1))
_G.requireInjector()
local class = require('class')
local Config = require('config')
@@ -10,19 +10,13 @@ local Tween = require('ui.tween')
local UI = require('ui')
local Util = require('util')
local REGISTRY_DIR = 'usr/.registry'
local TEMPLATE = [[
local env = { }
for k,v in pairs(getfenv(1)) do
env[k] = v
end
setmetatable(env, { __index = _G })
local fs = _G.fs
local multishell = _ENV.multishell
local pocket = _G.pocket
local term = _G.term
local turtle = _G.turtle
local s, m = os.run(env, 'sys/apps/appRun.lua', %s, ...)
if not s then
error(m)
end
]]
local REGISTRY_DIR = 'usr/.registry'
multishell.setTitle(multishell.getCurrent(), 'Overview')
UI:configure('Overview', ...)
@@ -93,13 +87,14 @@ end
local buttons = { }
local categories = { }
table.insert(buttons, { text = 'Recent', event = 'category' })
for _,f in pairs(applications) do
if not categories[f.category] then
categories[f.category] = true
table.insert(buttons, { text = f.category, event = 'category' })
end
end
table.sort(buttons, function(a, b) return a.text < b.text end)
table.insert(buttons, 1, { text = 'Recent', event = 'category' })
table.insert(buttons, { text = '+', event = 'new' })
local function parseIcon(iconText)
@@ -159,17 +154,11 @@ local page = UI.Page {
f = 'files',
s = 'shell',
l = 'lua',
[ 'control-l' ] = 'refresh',
[ 'control-n' ] = 'new',
delete = 'delete',
},
}
function page:draw()
self.tabBar:draw()
self.container:draw()
end
UI.Icon = class(UI.Window)
function UI.Icon:init(args)
local defaults = {
@@ -194,7 +183,7 @@ function UI.Icon:eventHandler(event)
return UI.Window.eventHandler(self, event)
end
function page.container:setCategory(categoryName)
function page.container:setCategory(categoryName, animate)
-- reset the viewport window
self.children = { }
@@ -223,7 +212,7 @@ function page.container:setCategory(categoryName)
end
else
filtered = filter(applications, function(a)
filtered = filter(applications, function(a)
return a.category == categoryName -- and fs.exists(a.run)
end)
table.sort(filtered, function(a, b) return a.title < b.title end)
@@ -295,6 +284,11 @@ function page.container:setCategory(categoryName)
end
child.tween = Tween.new(6, child, { x = col, y = row }, 'linear')
if not animate then
child.x = col
child.y = row
end
if k < count then
col = col + child.width
if col + self.children[k + 1].width + gutter - 2 > self.width then
@@ -305,32 +299,30 @@ function page.container:setCategory(categoryName)
end
self:initChildren()
local function transition(args)
local i = 1
return function(device)
self:clear()
for _,child in pairs(self.children) do
child.tween:update(1)
child.x = math.floor(child.x)
child.y = math.floor(child.y)
child:draw()
if animate then -- need to fix transitions under layers
local function transition(args)
local i = 1
return function(device)
self:clear()
for _,child in pairs(self.children) do
child.tween:update(1)
child.x = math.floor(child.x)
child.y = math.floor(child.y)
child:draw()
end
args.canvas:blit(device, args, args)
i = i + 1
return i < 7
end
args.canvas:blit(device, args, args)
i = i + 1
return i < 7
end
self:addTransition(transition)
end
self:addTransition(transition)
end
function page.container:draw()
UI.Viewport.draw(self)
end
function page:refresh()
local pos = self.container.offy
self:focusFirst(self)
self.container:setCategory(config.currentCategory)
self.container:setCategory(config.currentCategory)
self.container:setScrollPosition(pos)
end
@@ -343,9 +335,8 @@ function page:eventHandler(event)
if event.type == 'category' then
self.tabBar:selectTab(event.button.text)
self.container:setCategory(event.button.text)
self.container:setCategory(event.button.text, true)
self.container:draw()
self:sync()
config.currentCategory = event.button.text
Config.update('Overview', config)
@@ -392,14 +383,7 @@ function page:eventHandler(event)
event.focused.parent:scrollIntoView()
end
elseif event.type == 'tab_change' then
if event.current > event.last then
--self.container:setTransition(UI.effect.slideLeft)
else
--self.container:setTransition(UI.effect.slideRight)
end
elseif event.type == 'refresh' then
elseif event.type == 'refresh' then -- remove this after fixing notification
loadApplications()
self:refresh()
self:draw()
@@ -458,7 +442,7 @@ local editor = UI.Dialog {
required = true,
},
loadIcon = UI.Button {
x = 11, y = 6,
x = 11, y = 6,
text = 'Icon', event = 'loadIcon', help = 'Select icon'
},
image = UI.NftImage {
@@ -569,5 +553,4 @@ page.tabBar:selectTab(config.currentCategory or 'Apps')
page.container:setCategory(config.currentCategory or 'Apps')
UI:setPage(page)
Event.pullEvents()
UI.term:reset()
UI:pullEvents()

View File

@@ -1,10 +1,14 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Config = require('config')
local Event = require('event')
local UI = require('ui')
local Util = require('util')
local fs = _G.fs
local multishell = _ENV.multishell
local os = _G.os
local shell = _ENV.shell
multishell.setTitle(multishell.getCurrent(), 'System')
UI:configure('System', ...)
@@ -30,7 +34,6 @@ local systemPage = UI.Page {
},
grid = UI.Grid {
y = 4,
values = paths,
disableHeader = true,
columns = { { key = 'value' } },
autospace = true,
@@ -40,7 +43,7 @@ local systemPage = UI.Page {
aliasTab = UI.Window {
tabTitle = 'Aliases',
alias = UI.TextEntry {
x = 2, y = 2, ex = -2,
x = 2, y = 2, ex = -2,
limit = 32,
shadowText = 'Alias',
},
@@ -54,7 +57,6 @@ local systemPage = UI.Page {
},
grid = UI.Grid {
y = 5,
values = aliases,
autospace = true,
sortColumn = 'alias',
columns = {
@@ -87,7 +89,7 @@ local systemPage = UI.Page {
{ name = '', value = '' },
{ name = 'CC version', value = Util.getVersion() },
{ name = 'Lua version', value = _VERSION },
{ name = 'MC version', value = _MC_VERSION or 'unknown' },
{ name = 'MC version', value = _G._MC_VERSION or 'unknown' },
{ name = 'Disk free', value = Util.toBytes(fs.getFreeSpace('/')) },
{ name = 'Computer ID', value = tostring(os.getComputerID()) },
{ name = 'Day', value = tostring(os.day()) },
@@ -129,7 +131,6 @@ end
function systemPage.tabs.aliasTab.grid:draw()
self.values = { }
local aliases = { }
for k,v in pairs(env.aliases) do
table.insert(self.values, { alias = k, path = v })
end
@@ -170,7 +171,7 @@ end
function systemPage:eventHandler(event)
if event.type == 'quit' then
Event.exitPullEvents()
UI:exitPullEvents()
elseif event.type == 'tab_activate' then
event.activated:focusFirst()
else
@@ -180,5 +181,4 @@ function systemPage:eventHandler(event)
end
UI:setPage(systemPage)
Event.pullEvents()
UI.term:reset()
UI:pullEvents()

View File

@@ -1,9 +1,11 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Event = require('event')
local UI = require('ui')
local Util = require('util')
local multishell = _ENV.multishell
multishell.setTitle(multishell.getCurrent(), 'Tabs')
UI:configure('Tabs', ...)

View File

@@ -1,31 +1,22 @@
-- Default label
if not os.getComputerLabel() then
local id = os.getComputerID()
if turtle then
os.setComputerLabel('turtle_' .. id)
elseif pocket then
os.setComputerLabel('pocket_' .. id)
elseif commands then
os.setComputerLabel('command_' .. id)
else
os.setComputerLabel('computer_' .. id)
end
end
multishell.term = term.current()
local defaultEnv = { }
for k,v in pairs(getfenv(1)) do
defaultEnv[k] = v
for k,v in pairs(_ENV) do
defaultEnv[k] = v
end
requireInjector(getfenv(1))
_G.requireInjector()
local Config = require('config')
local Opus = require('opus')
local Util = require('util')
local SESSION_FILE = 'usr/config/multishell.session'
local colors = _G.colors
local fs = _G.fs
local keys = _G.keys
local multishell = _ENV.multishell
local os = _G.os
local printError = _G.printError
local term = _G.term
local window = _G.window
local parentTerm = term.current()
local w,h = parentTerm.getSize()
@@ -37,6 +28,22 @@ local runningTab
local tabsDirty = false
local closeInd = '*'
multishell.term = term.current()
-- Default label
if not os.getComputerLabel() then
local id = os.getComputerID()
if _G.turtle then
os.setComputerLabel('turtle_' .. id)
elseif _G.pocket then
os.setComputerLabel('pocket_' .. id)
elseif _G.commands then
os.setComputerLabel('command_' .. id)
else
os.setComputerLabel('computer_' .. id)
end
end
if Util.getVersion() >= 1.79 then
closeInd = '\215'
end
@@ -59,7 +66,6 @@ local config = {
focusBackgroundColor = colors.gray,
},
}
Config.load('multishell', config)
local _colors = config.standard
@@ -229,7 +235,6 @@ local function launchProcess(tab)
selectTab(previousTab)
end
redrawMenu()
saveSession()
end)
tabs[tab.tabId] = tab
@@ -243,8 +248,7 @@ local function resizeWindows()
local windowY = 2
local windowHeight = h-1
local keys = Util.keys(tabs)
for _,key in pairs(keys) do
for _,key in pairs(Util.keys(tabs)) do
local tab = tabs[key]
local x,y = tab.window.getCursorPos()
if y > windowHeight then
@@ -255,25 +259,11 @@ local function resizeWindows()
end
-- Pass term_resize to all processes
local keys = Util.keys(tabs)
for _,key in pairs(keys) do
for _,key in pairs(Util.keys(tabs)) do
resumeTab(tabs[key], "term_resize")
end
end
local function saveSession()
local t = { }
for _,process in pairs(tabs) do
if process.path and not process.isOverview and not process.hidden then
table.insert(t, {
path = process.path,
args = process.args,
})
end
end
--Util.writeTable(SESSION_FILE, t)
end
local control
local hotkeys = { }
@@ -348,7 +338,6 @@ function multishell.terminate(tabId)
local tab = tabs[tabId]
if tab and not tab.isOverview then
if coroutine.status(tab.co) ~= 'dead' then
--os.queueEvent('multishell', 'terminate', tab)
resumeTab(tab, "terminate")
else
tabs[tabId] = nil
@@ -399,10 +388,6 @@ function multishell.openTab(tab)
redrawMenu()
end
if not tab.hidden then
saveSession()
end
return tab.tabId
end
@@ -423,11 +408,7 @@ function multishell.unhideTab(tabId)
end
function multishell.getCount()
local count
for _,tab in pairs(tabs) do
count = count + 1
end
return count
return Util.size(tabs)
end
-- control-o - overview
@@ -435,6 +416,10 @@ multishell.addHotkey(24, function()
multishell.setFocus(overviewTab.tabId)
end)
multishell.addHotkey(20, function()
clipboard.useInternal(not clipboard.isInternal())
end)
-- control-backspace
multishell.addHotkey(14, function()
local tabId = multishell.getFocus()
@@ -474,7 +459,6 @@ end)
local function startup()
local hasError
local session = Util.readTable(SESSION_FILE)
if not Opus.loadServices() then
hasError = true
@@ -492,12 +476,6 @@ local function startup()
hasError = true
end
if session then
for _,v in pairs(session) do
--multishell.openTab(v)
end
end
if hasError then
print()
error('An autorun program has errored')
@@ -514,10 +492,6 @@ multishell.openTab({
title = 'Autorun',
})
if not overviewTab or coroutine.status(overviewTab.co) == 'dead' then
--error('Overview aborted')
end
if not currentTab then
multishell.setFocus(overviewTab.tabId)
end
@@ -562,13 +536,12 @@ while true do
-- Keyboard event - Passthrough to current process
resumeTab(currentTab, sEvent, tEventData)
elseif sEvent == "mouse_click" then
local button, x, y = tEventData[1], tEventData[2], tEventData[3]
lastClicked = nil
if y == 1 then
-- Switch process
local w, h = parentTerm.getSize()
if x == 1 then
multishell.setFocus(overviewTab.tabId)
elseif x == w then
@@ -616,8 +589,7 @@ while true do
else
-- Other event
-- Passthrough to all processes
local keys = Util.keys(tabs)
for _,key in pairs(keys) do
for _,key in pairs(Util.keys(tabs)) do
resumeTab(tabs[key], sEvent, tEventData)
end
end

View File

@@ -1,4 +1,4 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Security = require('security')
local SHA1 = require('sha1')

View File

@@ -1,10 +1,14 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Event = require('event')
local Socket = require('socket')
local Terminal = require('terminal')
local Util = require('util')
local os = _G.os
local read = _G.read
local term = _G.term
local remoteId
local args = { ... }
if #args == 1 then

View File

@@ -1,4 +1,4 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Crypto = require('crypto')
local Security = require('security')
@@ -6,6 +6,8 @@ local SHA1 = require('sha1')
local Socket = require('socket')
local Terminal = require('terminal')
local os = _G.os
local remoteId
local args = { ... }
@@ -13,7 +15,7 @@ if #args == 1 then
remoteId = tonumber(args[1])
else
print('Enter host ID')
remoteId = tonumber(read())
remoteId = tonumber(_G.read())
end
if not remoteId then
@@ -34,9 +36,8 @@ if not socket then
end
local publicKey = Security.getPublicKey()
local password = SHA1.sha1(password)
socket:write(Crypto.encrypt({ pk = publicKey, dh = os.getComputerID() }, password))
socket:write(Crypto.encrypt({ pk = publicKey, dh = os.getComputerID() }, SHA1.sha1(password)))
local data = socket:read(2)
socket:close()

View File

@@ -1,17 +1,21 @@
requireInjector(getfenv(1))
_G.requireInjector()
local Event = require('event')
local Socket = require('socket')
local Terminal = require('terminal')
local Util = require('util')
local colors = _G.colors
local multishell = _ENV.multishell
local term = _G.term
local remoteId
local args = { ... }
if #args == 1 then
remoteId = tonumber(args[1])
else
print('Enter host ID')
remoteId = tonumber(read())
remoteId = tonumber(_G.read())
end
if not remoteId then
@@ -73,7 +77,7 @@ while true do
print()
print('Connection lost')
print('Press enter to exit')
read()
_G.read()
break
end