1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-20 18:27:40 +00:00

UI improvements

This commit is contained in:
kepler155c@gmail.com
2017-10-07 23:03:18 -04:00
parent af981dd1f8
commit 98ec840db1
8 changed files with 240 additions and 166 deletions

View File

@@ -5,6 +5,8 @@ local Event = require('event')
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
multishell.setTitle(multishell.getCurrent(), 'Files')
UI:configure('Files', ...)
@@ -20,7 +22,7 @@ local marked = { }
local directories = { }
local cutMode = false
function formatSize(size)
local function formatSize(size)
if size >= 1000000 then
return string.format('%dM', math.floor(size/1000000, 2))
elseif size >= 1000 then
@@ -58,16 +60,16 @@ local Browser = UI.Page {
},
},
grid = UI.ScrollingGrid {
columns = {
columns = {
{ heading = 'Name', key = 'name' },
{ key = 'flags', width = 2 },
{ heading = 'Size', key = 'fsize', width = 6 },
{ heading = 'Size', key = 'fsize', width = 5 },
},
sortColumn = 'name',
y = 2, ey = -2,
},
statusBar = UI.StatusBar {
columns = {
columns = {
{ key = 'status' },
{ key = 'totalSize', width = 6 },
},
@@ -84,6 +86,7 @@ local Browser = UI.Page {
d = 'delete',
delete = 'delete',
[ 'control-h' ] = 'toggle_hidden',
[ 'control-s' ] = 'toggle_dirSize',
[ 'control-x' ] = 'cut',
[ 'control-c' ] = 'copy',
paste = 'paste',
@@ -117,7 +120,7 @@ function Browser.grid:sortCompare(a, b)
return a.isDir
end
function Browser.grid:getRowTextColor(file, selected)
function Browser.grid:getRowTextColor(file)
if file.marked then
return colors.green
end
@@ -130,13 +133,6 @@ function Browser.grid:getRowTextColor(file, selected)
return colors.white
end
function Browser.grid:getRowBackgroundColorX(file, selected)
if selected then
return colors.gray
end
return self.backgroundColor
end
function Browser.grid:eventHandler(event)
if event.type == 'copy' then -- let copy be handled by parent
return false
@@ -169,7 +165,6 @@ function Browser:unmarkAll()
end
function Browser:getDirectory(directory)
local s, dir = pcall(function()
local dir = directories[directory]
@@ -350,7 +345,7 @@ function Browser:eventHandler(event)
self.statusBar:sync()
local _, ch = os.pullEvent('char')
if ch == 'y' or ch == 'Y' then
for k,m in pairs(marked) do
for _,m in pairs(marked) do
pcall(function()
fs.delete(m.fullName)
end)
@@ -377,7 +372,7 @@ function Browser:eventHandler(event)
end
elseif event.type == 'paste' then
for k,m in pairs(copied) do
for _,m in pairs(copied) do
local s, m = pcall(function()
if cutMode then
fs.move(m.fullName, fs.combine(self.dir.name, m.name))

View File

@@ -1,14 +1,19 @@
requireInjector(getfenv(1))
local Event = require('event')
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local help = _G.help
multishell.setTitle(multishell.getCurrent(), 'Help')
UI:configure('Help', ...)
local files = { }
for _,f in pairs(help.topics()) do
table.insert(files, { name = f })
local topics = { }
for _,topic in pairs(help.topics()) do
if help.lookup(topic) then
table.insert(topics, { name = topic })
end
end
local page = UI.Page {
@@ -22,9 +27,9 @@ local page = UI.Page {
},
grid = UI.ScrollingGrid {
y = 4,
values = files,
values = topics,
columns = {
{ heading = 'Name', key = 'name' },
{ heading = 'Topic', key = 'name' },
},
sortColumn = 'name',
},
@@ -34,36 +39,56 @@ local page = UI.Page {
},
}
local function showHelp(name)
UI.term:reset()
shell.run('help ' .. name)
print('Press enter to return')
repeat
os.pullEvent('key')
local _, k = os.pullEvent('key_up')
until k == keys.enter
local topicPage = UI.Page {
backgroundColor = colors.black,
titleBar = UI.TitleBar {
title = 'text',
previousPage = true,
},
helpText = UI.TextArea {
backgroundColor = colors.black,
x = 2, ex = -1, y = 3, ey = -2,
},
accelerators = {
q = 'back',
backspace = 'back',
},
}
function topicPage.helpText:focus()
-- let the help text get focused so we consume key strokes
end
function topicPage:eventHandler(event)
if event.type == 'back' then
UI:setPreviousPage()
end
return UI.Page.eventHandler(self, event)
end
function page:eventHandler(event)
if event.type == 'quit' then
Event.exitPullEvents()
UI:exitPullEvents()
elseif event.type == 'grid_select' then
if self.grid:getSelected() then
showHelp(self.grid:getSelected().name)
self:setFocus(self.filter)
self:draw()
local name = self.grid:getSelected().name
local f = help.lookup(name)
topicPage.titleBar.title = name
topicPage.helpText:setText(Util.readFile(f))
UI:setPage(topicPage)
end
elseif event.type == 'text_change' then
local text = event.text
if #text == 0 then
self.grid.values = files
if #event.text == 0 then
self.grid.values = topics
else
self.grid.values = { }
for _,f in pairs(files) do
if string.find(f.name, text) then
for _,f in pairs(topics) do
if string.find(f.name, event.text) then
table.insert(self.grid.values, f)
end
end
@@ -72,7 +97,7 @@ function page:eventHandler(event)
self.grid:setIndex(1)
self.grid:draw()
else
UI.Page.eventHandler(self, event)
return UI.Page.eventHandler(self, event)
end
end

View File

@@ -148,7 +148,7 @@ local page = UI.Page {
tabBar = UI.VerticalTabBar {
buttons = buttons,
},
container = UI.ViewportWindow {
container = UI.Viewport {
x = cx,
y = cy,
},
@@ -324,7 +324,7 @@ function page.container:setCategory(categoryName)
end
function page.container:draw()
UI.ViewportWindow.draw(self)
UI.Viewport.draw(self)
end
function page:refresh()