1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-25 16:10:26 +00:00
This commit is contained in:
kepler155c@gmail.com 2017-10-16 16:54:50 -04:00
parent fe0ca72b8b
commit 39ba226a82
3 changed files with 85 additions and 131 deletions

View File

@ -84,7 +84,7 @@ function input:translate(event, code, p1, p2)
self.ch = 'paste' self.ch = 'paste'
self.pressed[keys.leftCtrl] = nil self.pressed[keys.leftCtrl] = nil
self.pressed[keys.rightCtrl] = nil self.pressed[keys.rightCtrl] = nil
self.fired = input:toCode(0) self.fired = input:toCode(0, self.ch)
return self.fired return self.fired
elseif event == 'mouse_click' then elseif event == 'mouse_click' then

View File

@ -1,55 +0,0 @@
local colors = _G.colors
local fs = _G.fs
local os = _G.os
local shell = _ENV.shell
local term = _G.term
local Opus = { }
local function runDir(directory, open)
if not fs.exists(directory) then
return true
end
local success = true
local files = fs.list(directory)
table.sort(files)
for _,file in ipairs(files) do
os.sleep(0)
local result, err = open(directory .. '/' .. file)
if result then
if term.isColor() then
term.setTextColor(colors.green)
end
term.write('[PASS] ')
term.setTextColor(colors.white)
term.write(fs.combine(directory, file))
else
if term.isColor() then
term.setTextColor(colors.red)
end
term.write('[FAIL] ')
term.setTextColor(colors.white)
term.write(fs.combine(directory, file))
if err then
_G.printError(err)
end
success = false
end
print()
end
return success
end
function Opus.loadServices()
return runDir('sys/services', shell.openHiddenTab)
end
function Opus.autorun()
local s = runDir('sys/autorun', shell.run)
return runDir('usr/autorun', shell.run) and s
end
return Opus

View File

@ -7,7 +7,6 @@ _G.requireInjector()
local Config = require('config') local Config = require('config')
local Input = require('input') local Input = require('input')
local Opus = require('opus')
local Util = require('util') local Util = require('util')
local colors = _G.colors local colors = _G.colors
@ -16,6 +15,7 @@ local keys = _G.keys
local multishell = _ENV.multishell local multishell = _ENV.multishell
local os = _G.os local os = _G.os
local printError = _G.printError local printError = _G.printError
local shell = _ENV.shell
local term = _G.term local term = _G.term
local window = _G.window local window = _G.window
@ -24,7 +24,7 @@ local w,h = parentTerm.getSize()
local tabs = { } local tabs = { }
local currentTab local currentTab
local _tabId = 0 local _tabId = 0
local overviewTab local overviewId
local runningTab local runningTab
local tabsDirty = false local tabsDirty = false
local closeInd = '*' local closeInd = '*'
@ -119,7 +119,7 @@ local function selectTab(tab)
end end
if not tab then if not tab then
tab = overviewTab tab = tabs[overviewId]
end end
if currentTab and currentTab ~= tab then if currentTab and currentTab ~= tab then
@ -147,7 +147,6 @@ local function nextTabId()
end end
local function launchProcess(tab) local function launchProcess(tab)
tab.tabId = nextTabId() tab.tabId = nextTabId()
tab.timestamp = os.clock() tab.timestamp = os.clock()
tab.window = window.create(parentTerm, 1, 2, w, h - 1, false) tab.window = window.create(parentTerm, 1, 2, w, h - 1, false)
@ -175,9 +174,6 @@ local function launchProcess(tab)
while true do while true do
local e, code = os.pullEventRaw('key') local e, code = os.pullEventRaw('key')
if e == 'terminate' or e == 'key' and code == keys.enter then if e == 'terminate' or e == 'key' and code == keys.enter then
if tab.isOverview then
-- os.queueEvent('multishell', 'terminate')
end
break break
end end
end end
@ -197,9 +193,7 @@ local function launchProcess(tab)
end) end)
tabs[tab.tabId] = tab tabs[tab.tabId] = tab
resumeTab(tab) resumeTab(tab)
return tab return tab
end end
@ -252,20 +246,6 @@ end
function multishell.terminate(tabId) function multishell.terminate(tabId)
os.queueEvent('multishell_terminate', tabId) os.queueEvent('multishell_terminate', tabId)
--[[
else
tabs[tabId] = nil
if tab == currentTab then
local previousTab
if tab.previousTabId then
previousTab = tabs[tab.previousTabId]
end
selectTab(previousTab)
end
redrawMenu()
end
end
]]
end end
function multishell.getTabs() function multishell.getTabs()
@ -282,11 +262,9 @@ function multishell.launch( tProgramEnv, sProgramPath, ... )
end end
function multishell.openTab(tab) function multishell.openTab(tab)
if not tab.title and tab.path then if not tab.title and tab.path then
tab.title = fs.getName(tab.path) tab.title = fs.getName(tab.path)
end end
tab.title = tab.title or 'untitled' tab.title = tab.title or 'untitled'
local previousTerm = term.current() local previousTerm = term.current()
@ -380,39 +358,51 @@ multishell.hook('multishell_redraw', function()
parentTerm.setCursorPos(1, 1) parentTerm.setCursorPos(1, 1)
parentTerm.clearLine() parentTerm.clearLine()
if currentTab and currentTab.isOverview then
write(1, '+', bg, _colors.focusTextColor)
else
write(1, '+', bg, _colors.tabBarTextColor)
end
local tabX = 2
local function compareTab(a, b) local function compareTab(a, b)
return a.tabId < b.tabId return a.tabId < b.tabId
end end
for _,tab in pairs(tabs) do
if tab.hidden and tab ~= currentTab then
tab.width = 0
else
tab.width = #tab.title + 1
end
end
local function width()
local tw = 0
Util.each(tabs, function(t) tw = tw + t.width end)
return tw
end
while width() > w - 3 do
local tab = select(2,
Util.spairs(tabs, function(a, b) return a.width > b.width end)())
tab.width = tab.width - 1
end
local tabX = 0
for _,tab in Util.spairs(tabs, compareTab) do for _,tab in Util.spairs(tabs, compareTab) do
if tab.hidden and tab ~= currentTab or tab.isOverview then if tab.width > 0 then
tab.sx = nil
tab.ex = nil
else
tab.sx = tabX + 1 tab.sx = tabX + 1
tab.ex = tabX + #tab.title tab.ex = tabX + tab.width
tabX = tabX + #tab.title + 1 tabX = tabX + tab.width
end if tab ~= currentTab then
end write(tab.sx, tab.title:sub(1, tab.width - 1),
for _,tab in Util.spairs(tabs) do _colors.backgroundColor, _colors.textColor)
if tab.sx then
if tab == currentTab then
write(tab.sx, tab.title, _colors.focusBackgroundColor, _colors.focusTextColor)
else
write(tab.sx, tab.title, _colors.backgroundColor, _colors.textColor)
end end
end end
end end
if currentTab and not currentTab.isOverview then if currentTab then
write(currentTab.sx - 1,
' ' .. currentTab.title:sub(1, currentTab.width - 1) .. ' ',
_colors.focusBackgroundColor, _colors.focusTextColor)
if not currentTab.isOverview then
write(w, closeInd, _colors.backgroundColor, _colors.focusTextColor) write(w, closeInd, _colors.backgroundColor, _colors.focusTextColor)
end end
end
if currentTab then if currentTab then
currentTab.window.restoreCursor() currentTab.window.restoreCursor()
@ -425,17 +415,16 @@ multishell.hook('term_resize', function(_, eventData)
if not eventData[1] then --- TEST if not eventData[1] then --- TEST
w,h = parentTerm.getSize() w,h = parentTerm.getSize()
local windowY = 2
local windowHeight = h-1 local windowHeight = h-1
for _,key in pairs(Util.keys(tabs)) do for _,key in pairs(Util.keys(tabs)) do
local tab = tabs[key] local tab = tabs[key]
local x,y = tab.window.getCursorPos() local x,y = tab.window.getCursorPos()
if y > windowHeight then if y > windowHeight then
tab.window.scroll( y - windowHeight ) tab.window.scroll(y - windowHeight)
tab.window.setCursorPos( x, windowHeight ) tab.window.setCursorPos(x, windowHeight)
end end
tab.window.reposition( 1, windowY, w, windowHeight ) tab.window.reposition(1, 2, w, windowHeight)
end end
redrawMenu() redrawMenu()
@ -443,7 +432,6 @@ multishell.hook('term_resize', function(_, eventData)
end) end)
-- downstate should be stored in the tab (maybe) -- downstate should be stored in the tab (maybe)
multishell.hook('key_up', function(_, eventData) multishell.hook('key_up', function(_, eventData)
local code = eventData[1] local code = eventData[1]
@ -480,7 +468,7 @@ multishell.hook('mouse_click', function(_, eventData)
local x, y = eventData[2], eventData[3] local x, y = eventData[2], eventData[3]
if y == 1 then if y == 1 then
if x == 1 then if x == 1 then
multishell.setFocus(overviewTab.tabId) multishell.setFocus(overviewId)
elseif x == w then elseif x == w then
if currentTab then if currentTab then
multishell.terminate(currentTab.tabId) multishell.terminate(currentTab.tabId)
@ -533,43 +521,64 @@ multishell.hook('mouse_scroll', function(_, eventData)
end) end)
local function startup() local function startup()
local hasError local success = true
if not Opus.loadServices() then local function runDir(directory, open)
hasError = true if not fs.exists(directory) then
return true
end end
local overviewId = multishell.openTab({ local files = fs.list(directory)
path = 'sys/apps/Overview.lua', table.sort(files)
focused = true,
hidden = true,
isOverview = true,
})
overviewTab = tabs[overviewId]
if not Opus.autorun() then for _,file in ipairs(files) do
hasError = true os.sleep(0)
local result, err = open(directory .. '/' .. file)
if result then
if term.isColor() then
term.setTextColor(colors.green)
end
term.write('[PASS] ')
term.setTextColor(colors.white)
term.write(fs.combine(directory, file))
else
if term.isColor() then
term.setTextColor(colors.red)
end
term.write('[FAIL] ')
term.setTextColor(colors.white)
term.write(fs.combine(directory, file))
if err then
_G.printError(err)
end
success = false
end
print()
end
end end
if hasError then runDir('sys/services', shell.openHiddenTab)
runDir('sys/autorun', shell.run)
runDir('usr/autorun', shell.run)
if not success then
print() print()
error('An autorun program has errored') error('An autorun program has errored')
end end
end end
overviewId = multishell.openTab({
path = 'sys/apps/Overview.lua',
isOverview = true,
})
tabs[overviewId].title = '+'
multishell.openTab({ multishell.openTab({
focused = true, focused = true,
fn = startup, fn = startup,
env = defaultEnv,
title = 'Autorun', title = 'Autorun',
}) })
if not currentTab then
multishell.setFocus(overviewTab.tabId)
end
redrawMenu()
local currentTabEvents = Util.transpose { local currentTabEvents = Util.transpose {
'char', 'key', 'key_up', 'char', 'key', 'key_up',
'mouse_click', 'mouse_drag', 'mouse_scroll', 'mouse_up', 'mouse_click', 'mouse_drag', 'mouse_scroll', 'mouse_up',