minor cleanup

This commit is contained in:
kepler155c@gmail.com 2020-05-30 20:05:53 -06:00
parent b6f439e8dc
commit 2105799524
9 changed files with 104 additions and 13 deletions

View File

@ -97,6 +97,7 @@ local page = UI.Page {
width = 8,
selectedBackgroundColor = 'primary',
backgroundColor = 'tertiary',
unselectedTextColor = 'lightGray',
layout = function(self)
self.height = nil
UI.TabBar.layout(self)

View File

@ -2,5 +2,4 @@ sys/apps/pain.lua urlfs https://github.com/LDDestroier/CC/raw/master/pain.lua
sys/apps/update.lua urlfs http://pastebin.com/raw/UzGHLbNC
sys/apps/Enchat.lua urlfs https://raw.githubusercontent.com/LDDestroier/enchat/master/enchat3.lua
sys/apps/cloud.lua urlfs https://cloud-catcher.squiddev.cc/cloud.lua
sys/apps/nfttrans.lua urlfs https://pastebin.com/raw/e8XrzeDY
rom/modules/main/opus linkfs sys/modules/opus

View File

@ -100,13 +100,33 @@ function multishell.launch(env, path, ...)
})
end
local function chain(orig, fn)
if not orig then
return fn
end
if type(orig) == 'table' then
table.insert(orig, fn)
return orig
end
return setmetatable({ orig, fn }, {
__call = function(self, ...)
for _,v in pairs(self) do
v(...)
end
end
})
end
function multishell.openTab(env, tab)
if not tab.title and tab.path then
tab.title = fs.getName(tab.path):match('([^%.]+)')
end
tab.title = tab.title or 'untitled'
tab.window = tab.window or window.create(parentTerm, 1, 2, w, h - 1, false)
tab.onExit = tab.onExit or function(self, result, err, stack)
-- require('opus.terminal').window(parentTerm, 1, 2, w, h - 1, false)
tab.onExit = chain(tab.onExit, function(self, result, err, stack)
if not result and err and err ~= 'Terminated' then
self.terminal.setTextColor(colors.white)
self.terminal.setCursorBlink(false)
@ -144,10 +164,7 @@ function multishell.openTab(env, tab)
end
end
end
if tab.chainExit then
tab.chainExit(self, result, err, stack)
end
end
end)
local routine, message = kernel.run(env, tab)

View File

@ -29,10 +29,8 @@ local focusedRoutineEvents = Util.transpose {
}
_G._syslog = function(pattern, ...)
local oldTerm = term.redirect(kernel.window)
kernel.window.scrollBottom()
Util.print(pattern, ...)
term.redirect(oldTerm)
kernel.window.print(Util.tostring(pattern, ...))
end
-- any function that runs in a kernel hook does not run in

View File

@ -277,6 +277,79 @@ function Terminal.window(parent, sx, sy, w, h, isVisible)
return parent
end
function win.writeX(sText)
-- expect(1, sText, "string", "number")
local nLinesPrinted = 0
local function newLine()
if cy + 1 <= win.canvas.height then
cx, cy = 1, cy + 1
else
cx, cy = 1, win.canvas.height
win.scroll(1)
end
nLinesPrinted = nLinesPrinted + 1
end
-- Print the line with proper word wrapping
sText = tostring(sText)
while #sText > 0 do
local whitespace = string.match(sText, "^[ \t]+")
if whitespace then
-- Print whitespace
win.write(whitespace)
sText = string.sub(sText, #whitespace + 1)
end
local newline = string.match(sText, "^\n")
if newline then
-- Print newlines
newLine()
sText = string.sub(sText, 2)
end
local text = string.match(sText, "^[^ \t\n]+")
if text then
sText = string.sub(sText, #text + 1)
if #text > win.canvas.width then
-- Print a multiline word
while #text > 0 do
if cx > win.canvas.width then
newLine()
end
win.write(text)
text = string.sub(text, win.canvas.width - cx + 2)
end
else
-- Print a word normally
if cx + #text - 1 > win.canvas.width then
newLine()
end
win.write(text)
end
end
end
return nLinesPrinted
end
function win.print(...)
local vis = isVisible
isVisible = false
local nLinesPrinted = 0
local nLimit = select("#", ...)
for n = 1, nLimit do
local s = tostring(select(n, ...))
if n < nLimit then
s = s .. "\t"
end
nLinesPrinted = nLinesPrinted + win.writeX(s)
end
nLinesPrinted = nLinesPrinted + win.writeX("\n")
isVisible = vis
update()
return nLinesPrinted
end
win.canvas:clear()
return win

View File

@ -763,7 +763,7 @@ function UI.Window:fillArea(x, y, width, height, fillChar, bg, fg)
end
end
UI.Window.docs.write = [[write(NUMBER x, NUMBER y, String text, opt COLOR bg, opt COLOR fg)
UI.Window.docs.write = [[write(NUMBER x, NUMBER y, STRING text, opt COLOR bg, opt COLOR fg)
Write text to the canvas.
If colors are not specified, the colors from the base class will be used.
If the base class does not have colors defined, colors will be inherited from the parent container.]]

View File

@ -7,8 +7,6 @@ UI.TabBar.defaults = {
UIElement = 'TabBar',
buttonClass = 'TabBarMenuItem',
backgroundColor = 'black',
selectedBackgroundColor = 'primary',
unselectedBackgroundColor = 'tertiary',
}
function UI.TabBar:enable()
UI.MenuBar.enable(self)

View File

@ -5,15 +5,16 @@ UI.TabBarMenuItem = class(UI.Button)
UI.TabBarMenuItem.defaults = {
UIElement = 'TabBarMenuItem',
event = 'tab_select',
textInactiveColor = 'lightGray',
}
function UI.TabBarMenuItem:draw()
if self.selected then
self.backgroundColor = self:getProperty('selectedBackgroundColor')
self.backgroundFocusColor = self.backgroundColor
self.textColor = self:getProperty('selectedTextColor')
else
self.backgroundColor = self:getProperty('unselectedBackgroundColor')
self.backgroundFocusColor = self.backgroundColor
self.textColor = self:getProperty('unselectedTextColor')
end
UI.Button.draw(self)
end

View File

@ -6,6 +6,10 @@ UI.Tabs = class(UI.Window)
UI.Tabs.docs = { }
UI.Tabs.defaults = {
UIElement = 'Tabs',
selectedBackgroundColor = 'primary',
unselectedBackgroundColor = 'tertiary',
unselectedTextColor = 'lightGray',
selectedTextColor = 'black',
}
function UI.Tabs:postInit()
self:add(self)