From 9cb7180f10349e95fde653bd4206e7e8b313ddd7 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Thu, 28 Sep 2017 18:52:57 -0400 Subject: [PATCH] better colors --- sys/apis/ui.lua | 66 +++++++++++++++++++++++++++++++--------- sys/apis/ui/fileui.lua | 1 - sys/apps/Lua.lua | 1 - sys/apps/Overview.lua | 3 +- sys/apps/System.lua | 5 --- sys/apps/multishell | 2 +- sys/etc/ext.theme | 4 +++ sys/services/network.lua | 10 ++---- 8 files changed, 62 insertions(+), 30 deletions(-) diff --git a/sys/apis/ui.lua b/sys/apis/ui.lua index 862fa83..c86b887 100644 --- a/sys/apis/ui.lua +++ b/sys/apis/ui.lua @@ -1366,6 +1366,37 @@ function UI.StringBuffer:clear() self.buffer = { } end +-- alternate - better ? +local SB = { } +function SB:new(width) + return setmetatable({ + width = width, + buf = string.rep(' ', width) + }, { __index = SB }) +end +function SB:insert(x, str, width) + if x < 1 then + x = self.width + x + 1 + end + width = width or #str + if x + width - 1 > self.width then + width = self.width - x + end + if width > 0 then + self.buf = self.buf:sub(1, x - 1) .. str:sub(1, width) .. self.buf:sub(x + width) + end +end +function SB:fill(x, ch, width) + width = width or self.width - x + 1 + self:insert(x, string.rep(ch, width)) +end +function SB:center(str) + self:insert(math.max(1, math.ceil((self.width - #str + 1) / 2)), str) +end +function SB:get() + return self.buf +end + --[[-- Page (focus manager) --]]-- UI.Page = class(UI.Window) UI.Page.defaults = { @@ -1377,7 +1408,7 @@ UI.Page.defaults = { shiftTab = 'focus_prev', up = 'focus_prev', }, - backgroundColor = colors.black, + backgroundColor = colors.cyan, textColor = colors.white, } function UI.Page:init(args) @@ -2123,8 +2154,11 @@ UI.TitleBar = class(UI.Window) UI.TitleBar.defaults = { UIElement = 'TitleBar', height = 1, - backgroundColor = colors.brown, - title = '' + textColor = colors.lightGray, + backgroundColor = colors.gray, + title = '', + frameChar = '-', + closeInd = '*', } function UI.TitleBar:init(args) local defaults = UI:getDefaults(UI.TitleBar, args) @@ -2132,13 +2166,13 @@ function UI.TitleBar:init(args) end function UI.TitleBar:draw() - self:clear() - local centered = math.ceil((self.width - #self.title) / 2) - self:write(1 + centered, 1, self.title, self.backgroundColor) + local sb = SB:new(self.width) + sb:fill(2, self.frameChar, sb.width - 3) + sb:center(string.format(' %s ', self.title)) if self.previousPage or self.event then - self:write(self.width, 1, '*', self.backgroundColor, colors.black) + sb:insert(-1, self.closeInd) end - --self:write(self.width-1, 1, '?', self.backgroundColor) + self:write(1, 1, sb:get()) end function UI.TitleBar:eventHandler(event) @@ -2186,6 +2220,7 @@ function UI.MenuBar:init(args) x = x, width = #button.text + self.spacing, backgroundColor = self.backgroundColor, + backgroundFocusColor = colors.gray, textColor = self.textColor, centered = false, } @@ -2712,7 +2747,8 @@ end UI.StatusBar = class(UI.GridLayout) UI.StatusBar.defaults = { UIElement = 'StatusBar', - backgroundColor = colors.gray, + backgroundColor = colors.lightGray, + textColor = colors.gray, columns = { { '', 'status', 10 }, }, @@ -2848,7 +2884,7 @@ UI.Button.defaults = { UIElement = 'Button', text = 'button', backgroundColor = colors.gray, - backgroundFocusColor = colors.green, + backgroundFocusColor = colors.lightGray, textFocusColor = colors.black, centered = true, height = 1, @@ -2912,8 +2948,9 @@ UI.TextEntry.defaults = { value = '', shadowText = '', focused = false, - backgroundColor = colors.lightGray, - backgroundFocusColor = colors.lightGray, + textColor = colors.white, + backgroundColor = colors.black, -- colors.lightGray, + backgroundFocusColor = colors.black, --lightGray, height = 1, limit = 6, pos = 0, @@ -3093,8 +3130,8 @@ UI.Chooser.defaults = { UIElement = 'Chooser', choices = { }, nochoice = 'Select', - backgroundColor = colors.lightGray, - backgroundFocusColor = colors.green, + --backgroundColor = colors.lightGray, + backgroundFocusColor = colors.lightGray, height = 1, } function UI.Chooser:init(args) @@ -3320,6 +3357,7 @@ UI.Dialog.defaults = { y = 4, z = 2, height = 7, + textColor = colors.black, backgroundColor = colors.white, } function UI.Dialog:init(args) diff --git a/sys/apis/ui/fileui.lua b/sys/apis/ui/fileui.lua index 4f878e4..5f7442a 100644 --- a/sys/apis/ui/fileui.lua +++ b/sys/apis/ui/fileui.lua @@ -24,7 +24,6 @@ return function(args) -- rey = args.rey or -3, height = args.height, width = args.width, - backgroundColor = colors.brown, title = 'Select file', grid = UI.ScrollingGrid { x = 2, diff --git a/sys/apps/Lua.lua b/sys/apps/Lua.lua index 3a273fd..09df02f 100644 --- a/sys/apps/Lua.lua +++ b/sys/apps/Lua.lua @@ -27,7 +27,6 @@ local page = UI.Page({ prompt = UI.TextEntry({ y = 2, shadowText = 'enter command', - backgroundFocusColor = colors.black, limit = 256, accelerators = { enter = 'command_enter', diff --git a/sys/apps/Overview.lua b/sys/apps/Overview.lua index 57a69d2..bb1c084 100644 --- a/sys/apps/Overview.lua +++ b/sys/apps/Overview.lua @@ -254,6 +254,7 @@ function page.container:setCategory(categoryName) y = 4, text = title, backgroundColor = self.backgroundColor, + --backgroundFocusColor = colors.gray, width = #title + 2, event = 'button', app = program, @@ -414,7 +415,7 @@ function page:eventHandler(event) return true end -local formWidth = math.max(UI.term.width - 14, 26) +local formWidth = math.max(UI.term.width - 8, 26) local editor = UI.Dialog { height = 11, diff --git a/sys/apps/System.lua b/sys/apps/System.lua index 9863d91..a668668 100644 --- a/sys/apps/System.lua +++ b/sys/apps/System.lua @@ -15,10 +15,7 @@ local env = { } Config.load('shell', env) -UI.TextEntry.defaults.backgroundFocusColor = colors.black - local systemPage = UI.Page { - backgroundColor = colors.cyan, tabs = UI.Tabs { pathTab = UI.Window { tabTitle = 'Path', @@ -80,7 +77,6 @@ local systemPage = UI.Page { x = 9, y = 2, rex = -4, limit = 32, value = os.getComputerLabel(), - backgroundFocusColor = colors.black, accelerators = { enter = 'update_label', }, @@ -97,7 +93,6 @@ local systemPage = UI.Page { { name = 'Day', value = tostring(os.day()) }, }, selectable = false, - --backgroundColor = colors.blue, columns = { { key = 'name', width = 12 }, { key = 'value', width = UI.term.width - 15 }, diff --git a/sys/apps/multishell b/sys/apps/multishell index 9f8b6c7..4bafbcc 100644 --- a/sys/apps/multishell +++ b/sys/apps/multishell @@ -114,7 +114,7 @@ local function draw() parentTerm.setTextColor(_colors.focusTextColor) parentTerm.setBackgroundColor(_colors.backgroundColor) parentTerm.setCursorPos( w, 1 ) - parentTerm.write('*') + parentTerm.write('\215') end if currentTab then diff --git a/sys/etc/ext.theme b/sys/etc/ext.theme index 665fdee..c3f66e2 100644 --- a/sys/etc/ext.theme +++ b/sys/etc/ext.theme @@ -12,4 +12,8 @@ focusIndicator = '\183', inverseSortIndicator = '\24', }, + TitleBar = { + frameChar = '\140', + closeInd = '\215', + }, } diff --git a/sys/services/network.lua b/sys/services/network.lua index 36cc3ec..32a9170 100644 --- a/sys/services/network.lua +++ b/sys/services/network.lua @@ -10,13 +10,9 @@ local function netUp() requireInjector(getfenv(1)) local Event = require('event') - local files = fs.list('/sys/network') - - for _,file in pairs(files) do - local fn, msg = loadfile('/sys/network/' .. file, getfenv(1)) - if fn then - fn() - else + for _,file in pairs(fs.list('sys/network')) do + local fn, msg = Util.run(getfenv(1), 'sys/network/' .. file) + if not fn then printError(msg) end end