diff --git a/sys/apis/packages.lua b/sys/apis/packages.lua index ffbc803..6148e28 100644 --- a/sys/apis/packages.lua +++ b/sys/apis/packages.lua @@ -39,15 +39,7 @@ function Packages:downloadList() end end -function Packages:getManifest(package) - local fname = 'packages/' .. package .. '/.package' - if fs.exists(fname) then - local c = Util.readTable(fname) - if c then - c.repository = c.repository:gsub('{{OPUS_BRANCH}}', _G.OPUS_BRANCH) - return c - end - end +function Packages:downloadManifest(package) local list = self:list() local url = list and list[package] @@ -63,4 +55,16 @@ function Packages:getManifest(package) end end +function Packages:getManifest(package) + local fname = 'packages/' .. package .. '/.package' + if fs.exists(fname) then + local c = Util.readTable(fname) + if c and c.repository then + c.repository = c.repository:gsub('{{OPUS_BRANCH}}', _G.OPUS_BRANCH) + return c + end + end + return self:downloadManifest(package) +end + return Packages diff --git a/sys/apis/ui.lua b/sys/apis/ui.lua index 11a631a..2646a34 100644 --- a/sys/apis/ui.lua +++ b/sys/apis/ui.lua @@ -35,6 +35,8 @@ end local Manager = class() function Manager:init() self.devices = { } + self.theme = { } + self.extChars = Util.getVersion() >= 1.76 local function keyFunction(event, code, held) local ie = Input:translate(event, code, held) @@ -1195,37 +1197,7 @@ local function loadComponents() end loadComponents() - -UI.theme = { } -if Util.getVersion() >= 1.76 then - UI.theme = { - ScrollBar = { - lineChar = '|', - sliderChar = '\127', - upArrowChar = '\30', - downArrowChar = '\31', - }, - Checkbox = { - checkedIndicator = '\4', - leftMarker = '\124', - rightMarker = '\124', - }, - Chooser = { - leftIndicator = '\17', - rightIndicator = '\16', - }, - Grid = { - focusIndicator = '\183', - inverseSortIndicator = '\24', - }, - TitleBar = { - frameChar = '\140', - closeInd = '\215', - }, - } -end UI:loadTheme('usr/config/ui.theme') - UI:setDefaultDevice(UI.Device({ device = term.current() })) return UI diff --git a/sys/apis/ui/components/Checkbox.lua b/sys/apis/ui/components/Checkbox.lua index 9f0b272..6356ebf 100644 --- a/sys/apis/ui/components/Checkbox.lua +++ b/sys/apis/ui/components/Checkbox.lua @@ -7,9 +7,9 @@ UI.Checkbox = class(UI.Window) UI.Checkbox.defaults = { UIElement = 'Checkbox', nochoice = 'Select', - checkedIndicator = 'X', - leftMarker = '[', - rightMarker = ']', + checkedIndicator = UI.extChars and '\4' or 'X', + leftMarker = UI.extChars and '\124' or '[', + rightMarker = UI.extChars and '\124' or ']', value = false, textColor = colors.white, backgroundColor = colors.black, diff --git a/sys/apis/ui/components/Chooser.lua b/sys/apis/ui/components/Chooser.lua index f6e632d..0284fbf 100644 --- a/sys/apis/ui/components/Chooser.lua +++ b/sys/apis/ui/components/Chooser.lua @@ -11,8 +11,8 @@ UI.Chooser.defaults = { nochoice = 'Select', backgroundFocusColor = colors.lightGray, textInactiveColor = colors.gray, - leftIndicator = '<', - rightIndicator = '>', + leftIndicator = UI.extChars and '\17' or '<', + rightIndicator = UI.extChars and '\16' or '>', height = 1, } function UI.Chooser:setParent() diff --git a/sys/apis/ui/components/Grid.lua b/sys/apis/ui/components/Grid.lua index 331d4ae..262faee 100644 --- a/sys/apis/ui/components/Grid.lua +++ b/sys/apis/ui/components/Grid.lua @@ -65,9 +65,9 @@ UI.Grid.defaults = { headerSortColor = colors.yellow, unfocusedTextSelectedColor = colors.white, unfocusedBackgroundSelectedColor = colors.gray, - focusIndicator = '>', + focusIndicator = UI.extChars and '\183' or '>', sortIndicator = ' ', - inverseSortIndicator = '^', + inverseSortIndicator = UI.extChars and '\24' or '^', values = { }, columns = { }, accelerators = { diff --git a/sys/apis/ui/components/Notification.lua b/sys/apis/ui/components/Notification.lua index 901a68c..ada09cb 100644 --- a/sys/apis/ui/components/Notification.lua +++ b/sys/apis/ui/components/Notification.lua @@ -10,7 +10,9 @@ UI.Notification = class(UI.Window) UI.Notification.defaults = { UIElement = 'Notification', backgroundColor = colors.gray, + closeInd = '\215', height = 3, + timeout = 3, } function UI.Notification:draw() end @@ -49,8 +51,8 @@ end function UI.Notification:display(value, timeout) self.enabled = true - local lines = Util.wordWrap(value, self.width - 2) - self.height = #lines + 1 + local lines = Util.wordWrap(value, self.width - 3) + self.height = #lines self.y = self.parent.height - self.height + 1 if self.canvas then self.canvas:removeLayer() @@ -63,9 +65,22 @@ function UI.Notification:display(value, timeout) for k,v in pairs(lines) do self:write(2, k, v) end + self:write(self.width, 1, self.closeInd) - self.timer = Event.onTimeout(timeout or 3, function() - self:cancel() - self:sync() - end) + timeout = timeout or self.timeout + if timeout > 0 then + self.timer = Event.onTimeout(timeout or self.timeout, function() + self:cancel() + self:sync() + end) + end +end + +function UI.Notification:eventHandler(event) + if event.type == 'mouse_click' then + if event.x == self.width then + self:cancel() + return true + end + end end diff --git a/sys/apis/ui/components/ScrollBar.lua b/sys/apis/ui/components/ScrollBar.lua index 8be6de9..2299502 100644 --- a/sys/apis/ui/components/ScrollBar.lua +++ b/sys/apis/ui/components/ScrollBar.lua @@ -8,9 +8,9 @@ UI.ScrollBar = class(UI.Window) UI.ScrollBar.defaults = { UIElement = 'ScrollBar', lineChar = '|', - sliderChar = '#', - upArrowChar = '^', - downArrowChar = 'v', + sliderChar = UI.extChars and '\127' or '#', + upArrowChar = UI.extChars and '\30' or '^', + downArrowChar = UI.extChars and '\31' or 'v', scrollbarColor = colors.lightGray, width = 1, x = -1, diff --git a/sys/apis/ui/components/TitleBar.lua b/sys/apis/ui/components/TitleBar.lua index 0a464ab..872d78b 100644 --- a/sys/apis/ui/components/TitleBar.lua +++ b/sys/apis/ui/components/TitleBar.lua @@ -41,8 +41,8 @@ UI.TitleBar.defaults = { textColor = colors.white, backgroundColor = colors.cyan, title = '', - frameChar = '-', - closeInd = '*', + frameChar = UI.extChars and '\140' or '-', + closeInd = UI.extChars and '\215' or '*', } function UI.TitleBar:draw() local sb = SB(self.width) diff --git a/sys/apps/Files.lua b/sys/apps/Files.lua index 2e065ba..9b14146 100644 --- a/sys/apps/Files.lua +++ b/sys/apps/Files.lua @@ -83,6 +83,7 @@ local Browser = UI.Page { { key = 'totalSize', width = 6 }, }, }, + notification = UI.Notification { }, associations = UI.SlideOut { backgroundColor = colors.cyan, menuBar = UI.MenuBar { @@ -215,7 +216,7 @@ function Browser.statusBar:draw() end function Browser:setStatus(status, ...) - self.statusBar:timedStatus(string.format(status, ...)) + self.notification:info(string.format(status, ...)) end function Browser:unmarkAll() diff --git a/sys/apps/PackageManager.lua b/sys/apps/PackageManager.lua index cdd1641..6ed2d41 100644 --- a/sys/apps/PackageManager.lua +++ b/sys/apps/PackageManager.lua @@ -37,12 +37,6 @@ local page = UI.Page { x = 16, y = 3, ey = -5, marginRight = 0, marginLeft = 0, }, - load = UI.Button { - x = 22, y = -3, - text = 'Update packages', - event = 'reload', - help = 'Download the latest package list', - }, action = UI.SlideOut { backgroundColor = colors.cyan, titleBar = UI.TitleBar { @@ -144,10 +138,6 @@ function page:eventHandler(event) self.description:draw() self:updateSelection(event.selected) - elseif event.type == 'reload' then - Packages:downloadList() - self:loadPackages() - elseif event.type == 'action' then local selected = self.grid:getSelected() if selected then @@ -178,7 +168,11 @@ function page:eventHandler(event) UI.Page.eventHandler(self, event) end -page:loadPackages() - UI:setPage(page) +page.statusBar:setStatus('Downloading...') +page:sync() +Packages:downloadList() +page:loadPackages() +page:sync() + UI:pullEvents() diff --git a/sys/apps/package.lua b/sys/apps/package.lua index f604e3c..d1e2071 100644 --- a/sys/apps/package.lua +++ b/sys/apps/package.lua @@ -36,7 +36,7 @@ local function progress(max) end local function install(name, isUpdate) - local manifest = Packages:getManifest(name) or error('Invalid package') + local manifest = Packages:downloadManifest(name) or error('Invalid package') if manifest.required then for _, v in pairs(manifest.required) do