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