package manager update + UI built-in extended char detection

This commit is contained in:
kepler155c@gmail.com 2019-03-26 00:31:25 -04:00
parent 3f9c219f6b
commit daa86d50b2
11 changed files with 57 additions and 71 deletions

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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()

View File

@ -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 = {

View File

@ -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

View File

@ -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,

View File

@ -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)

View File

@ -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()

View File

@ -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()

View File

@ -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