1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-21 10:47:40 +00:00

ui overhaul

This commit is contained in:
kepler155c@gmail.com
2019-02-05 23:03:57 -05:00
parent 89400ac1bd
commit 915085ac5f
47 changed files with 2879 additions and 3199 deletions

View File

@@ -1,457 +0,0 @@
local colors = _G.colors
local fs = _G.fs
local http = _G.http
local install = _ENV.install
local os = _G.os
local injector
if not install.testing then
_G.OPUS_BRANCH = 'master-1.8'
local url ='https://raw.githubusercontent.com/kepler155c/opus/master-1.8/sys/apis/injector.lua'
injector = load(http.get(url).readAll(), 'injector.lua', nil, _ENV)()
else
injector = _G.requireInjector
end
injector(_ENV)
if not install.testing then
if package then
for _ = 1, 4 do
table.remove(package.loaders, 1)
end
end
end
local Git = require('git')
local UI = require('ui')
local Util = require('util')
local currentFile = ''
local currentProgress = 0
local cancelEvent
local args = { ... }
local steps = install.steps[args[1] or 'install']
if not steps then
error('Invalid install type')
end
local mode = steps[#steps]
if UI.term.width < 32 then
cancelEvent = 'quit'
end
local page = UI.Page {
backgroundColor = colors.cyan,
titleBar = UI.TitleBar {
event = cancelEvent,
},
wizard = UI.Wizard {
y = 2, ey = -2,
},
notification = UI.Notification(),
accelerators = {
q = 'quit',
},
}
local pages = {
splash = UI.Viewport { },
review = UI.Viewport { },
license = UI.Viewport {
backgroundColor = colors.black,
},
branch = UI.Window {
grid = UI.ScrollingGrid {
ey = -3,
columns = {
{ heading = 'Branch', key = 'branch' },
{ heading = 'Description', key = 'description' },
},
values = install.branches,
autospace = true,
},
},
files = UI.Window {
grid = UI.ScrollingGrid {
ey = -3,
columns = {
{ heading = 'Files', key = 'file' },
},
sortColumn = 'file',
},
},
install = UI.Window {
progressBar = UI.ProgressBar {
y = -1,
},
},
uninstall = UI.Window {
progressBar = UI.ProgressBar {
y = -1,
},
},
}
local function getFileList()
if install.gitRepo then
local gitFiles = Git.list(string.format('%s/%s', install.gitRepo, install.gitBranch or 'master'))
install.files = { }
install.diskspace = 0
for path, entry in pairs(gitFiles) do
install.files[path] = entry.url
install.diskspace = install.diskspace + entry.size
end
end
if not install.files or Util.empty(install.files) then
error('File list is missing or empty')
end
end
--[[ Splash ]]--
function pages.splash:enable()
page.titleBar.title = 'Installer v1.0'
UI.Viewport.enable(self)
end
function pages.splash:draw()
self:clear()
self:setCursorPos(1, 1)
self:print(
string.format('%s v%s\n', install.title, install.version), nil, colors.yellow)
self:print(
string.format('By: %s\n\n%s\n', install.author, install.description))
self.ymax = self.cursorY
end
--[[ License ]]--
function pages.license:enable()
page.titleBar.title = 'License Review'
page.wizard.nextButton.text = 'Accept'
UI.Viewport.enable(self)
end
function pages.license:draw()
self:clear()
self:setCursorPos(1, 1)
self:print(
string.format('Copyright (c) %s %s\n\n', install.copyrightYear,
install.copyrightHolders),
nil, colors.yellow)
self:print(install.license)
self.ymax = self.cursorY + 1
end
--[[ Review ]]--
function pages.review:enable()
if mode == 'uninstall' then
page.nextButton.text = 'Remove'
page.titleBar.title = 'Remove Installed Files'
else
page.wizard.nextButton.text = 'Begin'
page.titleBar.title = 'Download and Install'
end
UI.Viewport.enable(self)
end
function pages.review:draw()
self:clear()
self:setCursorPos(1, 1)
local text = 'Ready to begin installation.\n\nProceeding will download and install the files to the hard drive.'
if mode == 'uninstall' then
text = 'Ready to begin.\n\nProceeding will remove the files previously installed.'
end
self:print(text)
self.ymax = self.cursorY + 1
end
--[[ Files ]]--
function pages.files:enable()
page.titleBar.title = 'Review Files'
self.grid.values = { }
for k,v in pairs(install.files) do
table.insert(self.grid.values, { file = k, code = v })
end
self.grid:update()
UI.Window.enable(self)
end
function pages.files:draw()
self:clear()
local function formatSize(size)
if size >= 1000000 then
return string.format('%dM', math.floor(size/1000000, 2))
elseif size >= 1000 then
return string.format('%dK', math.floor(size/1000, 2))
end
return size
end
if install.diskspace then
local bg = self.backgroundColor
local diskFree = fs.getFreeSpace('/')
if install.diskspace > diskFree then
bg = colors.red
end
local text = string.format('Space Required: %s, Free: %s',
formatSize(install.diskspace), formatSize(diskFree))
if #text > self.width then
text = string.format('Space: %s Free: %s',
formatSize(install.diskspace), formatSize(diskFree))
end
self:write(1, self.height, Util.widthify(text, self.width), bg)
end
self.grid:draw()
end
--[[
function pages.files:view(url)
local s, m = pcall(function()
page.notification:info('Downloading')
page:sync()
Util.download(url, '/.source')
end)
page.notification:disable()
if s then
shell.run('edit /.source')
fs.delete('/.source')
page:draw()
page.notification:cancel()
else
page.notification:error(m:gsub('.*: (.*)', '%1'))
end
end
function pages.files:eventHandler(event)
if event.type == 'grid_select' then
self:view(event.selected.code)
return true
end
end
--]]
local function drawCommon(self)
if currentFile then
self:write(1, 3, 'File:')
self:write(1, 4, Util.widthify(currentFile, self.width))
else
self:write(1, 3, 'Finished')
end
if self.failed then
self:write(1, 5, Util.widthify(self.failed, self.width), colors.red)
end
self:write(1, self.height - 1, 'Progress')
self.progressBar.value = currentProgress
self.progressBar:draw()
self:sync()
end
--[[ Branch ]]--
function pages.branch:enable()
page.titleBar.title = 'Select Branch'
UI.Window.enable(self)
end
function pages.branch:eventHandler(event)
-- user is navigating to next view (not previous)
if event.type == 'enable_view' and event.next then
install.gitBranch = self.grid:getSelected().branch
getFileList()
end
end
--[[ Install ]]--
function pages.install:enable()
page.wizard.cancelButton:disable()
page.wizard.previousButton:disable()
page.wizard.nextButton:disable()
page.titleBar.title = 'Installing...'
page.titleBar.event = nil
UI.Window.enable(self)
page:draw()
page:sync()
local i = 0
local numFiles = Util.size(install.files)
for filename,url in pairs(install.files) do
currentFile = filename
currentProgress = i / numFiles * 100
self:draw(self)
self:sync()
local s, m = pcall(function()
Util.download(url, fs.combine(install.directory or '', filename))
end)
if not s then
self.failed = m:gsub('.*: (.*)', '%1')
break
end
i = i + 1
end
if not self.failed then
currentProgress = 100
currentFile = nil
if install.postInstall then
local s, m = pcall(function() install.postInstall(page, UI) end)
if not s then
self.failed = m:gsub('.*: (.*)', '%1')
end
end
end
page.wizard.nextButton.text = 'Exit'
page.wizard.nextButton.event = 'quit'
if not self.failed and install.rebootAfter then
page.wizard.nextButton.text = 'Reboot'
page.wizard.nextButton.event = 'reboot'
end
page.wizard.nextButton:enable()
page:draw()
page:sync()
if not self.failed and Util.key(args, 'automatic') then
if install.rebootAfter then
os.reboot()
else
UI:exitPullEvents()
end
end
end
function pages.install:draw()
self:clear()
local text = 'The files are being installed'
if #text > self.width then
text = 'Installing files'
end
self:write(1, 1, text, nil, colors.yellow)
drawCommon(self)
end
--[[ Uninstall ]]--
function pages.uninstall:enable()
page.wizard.cancelButton:disable()
page.wizard.previousButton:disable()
page.wizard.nextButton:disable()
page.titleBar.title = 'Uninstalling...'
page.titleBar.event = nil
page:draw()
page:sync()
UI.Window.enable(self)
local function pruneDir(dir)
if #dir > 0 then
if fs.exists(dir) then
local files = fs.list(dir)
if #files == 0 then
fs.delete(dir)
pruneDir(fs.getDir(dir))
end
end
end
end
local i = 0
local numFiles = Util.size(install.files)
for k in pairs(install.files) do
currentFile = k
currentProgress = i / numFiles * 100
self:draw()
self:sync()
fs.delete(k)
pruneDir(fs.getDir(k))
i = i + 1
end
currentProgress = 100
currentFile = nil
page.wizard.nextButton.text = 'Exit'
page.wizard.nextButton.event = 'quit'
page.wizard.nextButton:enable()
page:draw()
page:sync()
end
function pages.uninstall:draw()
self:clear()
self:write(1, 1, 'Uninstalling files', nil, colors.yellow)
drawCommon(self)
end
function page:eventHandler(event)
if event.type == 'cancel' then
UI:exitPullEvents()
elseif event.type == 'reboot' then
os.reboot()
elseif event.type == 'quit' then
UI:exitPullEvents()
else
return UI.Page.eventHandler(self, event)
end
return true
end
function page:enable()
UI.Page.enable(self)
self:setFocus(page.wizard.nextButton)
if UI.term.width < 32 then
page.wizard.cancelButton:disable()
page.wizard.previousButton.x = 2
end
end
getFileList()
local wizardPages = { }
for k,v in ipairs(steps) do
if not pages[v] then
error('Invalid step: ' .. v)
end
wizardPages[k] = pages[v]
wizardPages[k].index = k
wizardPages[k].x = 2
wizardPages[k].y = 2
wizardPages[k].ey = -3
wizardPages[k].ex = -2
end
page.wizard:add(wizardPages)
if Util.key(steps, 'install') and install.preInstall then
install.preInstall(page, UI)
end
UI:setPage(page)
local s, m = pcall(function() UI:pullEvents() end)
if not s then
UI.term:reset()
_G.printError(m)
end

View File

@@ -58,6 +58,7 @@ local page = UI.Page {
},
output = UI.Embedded {
y = -6,
visible = true,
backgroundColor = colors.gray,
},
}
@@ -328,6 +329,7 @@ function page:executeStatement(statement)
local s, m
local oterm = term.redirect(self.output.win)
self.output.win.scrollBottom()
pcall(function()
s, m = self:rawExecute(command)
end)

View File

@@ -252,7 +252,7 @@ end
function page.container:setCategory(categoryName, animate)
-- reset the viewport window
self.children = { }
self.offy = 0
self:reset()
local function filter(it, f)
local ot = { }
@@ -334,10 +334,10 @@ function page.container:setCategory(categoryName, animate)
for k,child in ipairs(self.children) do
if r == 1 then
child.x = math.random(1, self.width)
child.y = math.random(1, self.height)
child.y = math.random(1, self.height - 3)
elseif r == 2 then
child.x = self.width
child.y = self.height
child.y = self.height - 3
elseif r == 3 then
child.x = math.floor(self.width / 2)
child.y = math.floor(self.height / 2)
@@ -349,7 +349,7 @@ function page.container:setCategory(categoryName, animate)
child.y = row
if k == #self.children then
child.x = self.width
child.y = self.height
child.y = self.height - 3
end
end
child.tween = Tween.new(6, child, { x = col, y = row }, 'linear')
@@ -369,10 +369,10 @@ function page.container:setCategory(categoryName, animate)
end
self:initChildren()
if animate then -- need to fix transitions under layers
local function transition(args)
if animate then
local function transition()
local i = 1
return function(device)
return function()
self:clear()
for _,child in pairs(self.children) do
child.tween:update(1)
@@ -380,7 +380,6 @@ function page.container:setCategory(categoryName, animate)
child.y = math.floor(child.y)
child:draw()
end
args.canvas:blit(device, args, args)
i = i + 1
return i < 7
end

View File

@@ -45,8 +45,10 @@ local page = UI.Page {
help = 'Download the latest package list',
},
action = UI.SlideOut {
backgroundColor = colors.cyan,
backgroundColor = colors.brown,
y = 3,
titleBar = UI.TitleBar {
backgroundColor = colors.brown,
event = 'hide-action',
},
button = UI.Button {
@@ -56,9 +58,6 @@ local page = UI.Page {
output = UI.Embedded {
y = 5, ey = -2, x = 2, ex = -2,
},
statusBar = UI.StatusBar {
backgroundColor = colors.cyan,
},
},
statusBar = UI.StatusBar { },
}
@@ -101,9 +100,10 @@ function page.grid:getRowTextColor(row, selected)
end
function page.action:show()
self.output.win:clear()
UI.SlideOut.show(self)
self.output:draw()
self.output.win.redraw()
--self.output:draw()
--self.output.win.redraw()
end
function page:run(operation, name)
@@ -116,6 +116,7 @@ function page:run(operation, name)
print(cmd .. '\n')
term.setTextColor(colors.white)
local s, m = Util.run(_ENV, '/sys/apps/package.lua', operation, name)
if not s and m then
_G.printError(m)
end

View File

@@ -24,7 +24,7 @@ local page = UI.Page {
wizard = UI.Wizard {
ey = -2,
pages = {
splash = UI.Window {
splash = UI.WizardPage {
index = 1,
intro = UI.TextArea {
textColor = colors.yellow,
@@ -33,7 +33,7 @@ local page = UI.Page {
value = string.format(splashIntro, Ansi.white),
},
},
label = UI.Window {
label = UI.WizardPage {
index = 2,
labelText = UI.Text {
x = 3, y = 2,
@@ -51,7 +51,7 @@ local page = UI.Page {
value = string.format(labelIntro, Ansi.white),
},
},
password = UI.Window {
password = UI.WizardPage {
index = 3,
labelText = UI.Text {
x = 3, y = 2,
@@ -73,7 +73,7 @@ local page = UI.Page {
value = string.format(passwordIntro, Ansi.white),
},
},
packages = UI.Window {
packages = UI.WizardPage {
index = 4,
button = UI.Button {
x = 3, y = -3,

View File

@@ -361,16 +361,21 @@ local Config = require('config')
local Entry = require('entry')
local History = require('history')
local Input = require('input')
local Terminal = require('terminal')
local colors = _G.colors
local os = _G.os
local term = _G.term
local textutils = _G.textutils
local oldTerm
local terminal = term.current()
--Terminal.scrollable(terminal, 100)
terminal.noAutoScroll = true
if not terminal.scrollUp then
local Terminal = require('terminal')
terminal = Terminal.window(term.current())
terminal.setMaxScroll(200)
oldTerm = term.redirect(terminal)
end
local config = {
standard = {
@@ -555,6 +560,9 @@ local function shellRead(history)
term.setCursorBlink(true)
local function redraw()
if terminal.scrollBottom then
terminal.scrollBottom()
end
local _,cy = term.getCursorPos()
term.setCursorPos(3, cy)
local filler = #entry.value < lastLen
@@ -571,11 +579,11 @@ local function shellRead(history)
local ie = Input:translate(event, p1, p2, p3)
if ie then
if ie.code == 'scroll_up' then
--terminal.scrollUp()
if ie.code == 'scroll_up' and terminal.scrollUp then
terminal.scrollUp()
elseif ie.code == 'scroll_down' then
--terminal.scrollDown()
elseif ie.code == 'scroll_down' and terminal.scrollDown then
terminal.scrollDown()
elseif ie.code == 'terminate' then
bExit = true
@@ -652,3 +660,7 @@ while not bExit do
end
end
end
if oldTerm then
term.redirect(oldTerm)
end