1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-21 18:57:41 +00:00

ui improvements

This commit is contained in:
kepler155c@gmail.com
2017-10-03 00:50:54 -04:00
parent c0baa00668
commit 8e381d3ebf
10 changed files with 393 additions and 228 deletions

View File

@@ -143,7 +143,7 @@ function Browser.grid:eventHandler(event)
if event.type == 'copy' then -- let copy be handled by parent
return false
end
return UI.Grid.eventHandler(self, event)
return UI.ScrollingGrid.eventHandler(self, event)
end
function Browser.statusBar:draw()

View File

@@ -8,6 +8,7 @@ local Util = require('util')
local sandboxEnv = setmetatable(Util.shallowCopy(getfenv(1)), { __index = _G })
sandboxEnv.exit = function() Event.exitPullEvents() end
sandboxEnv._echo = function( ... ) return ... end
requireInjector(sandboxEnv)
multishell.setTitle(multishell.getCurrent(), 'Lua')
@@ -16,15 +17,15 @@ UI:configure('Lua', ...)
local command = ''
local history = History.load('usr/.lua_history', 25)
local page = UI.Page({
menuBar = UI.MenuBar({
local page = UI.Page {
menuBar = UI.MenuBar {
buttons = {
{ text = 'Local', event = 'local' },
{ text = 'Global', event = 'global' },
{ text = 'Device', event = 'device', name = 'Device' },
},
}),
prompt = UI.TextEntry({
},
prompt = UI.TextEntry {
y = 2,
shadowText = 'enter command',
limit = 256,
@@ -35,8 +36,8 @@ local page = UI.Page({
mouse_rightclick = 'clear_prompt',
-- [ 'control-space' ] = 'autocomplete',
},
}),
grid = UI.ScrollingGrid({
},
grid = UI.ScrollingGrid {
y = 3,
columns = {
{ heading = 'Key', key = 'name' },
@@ -44,9 +45,9 @@ local page = UI.Page({
},
sortColumn = 'name',
autospace = true,
}),
},
notification = UI.Notification(),
})
}
function page:setPrompt(value, focus)
self.prompt:setValue(value)
@@ -138,23 +139,24 @@ function page:eventHandler(event)
self:executeStatement('device')
elseif event.type == 'history_back' then
local value = history.back()
local value = history:back()
if value then
self:setPrompt(value)
end
elseif event.type == 'history_forward' then
self:setPrompt(history.forward() or '')
self:setPrompt(history:forward() or '')
elseif event.type == 'clear_prompt' then
self:setPrompt('')
history.setPosition(#history.entries + 1)
history:reset()
elseif event.type == 'command_enter' then
local s = tostring(self.prompt.value)
if #s > 0 then
history.add(s)
history:add(s)
history:back()
self:executeStatement(s)
else
local t = { }
@@ -166,7 +168,7 @@ function page:eventHandler(event)
pos = k,
})
end
history.setPosition(#history.entries + 1)
history:reset()
command = nil
self.grid:setValues(t)
self.grid:setIndex(1)
@@ -228,7 +230,7 @@ function page.grid:eventHandler(event)
local function commandAppend()
if entry.isHistory then
history.setPosition(entry.pos)
--history.setPosition(entry.pos)
return entry.value
end
if type(entry.rawValue) == 'function' then
@@ -262,15 +264,14 @@ function page.grid:eventHandler(event)
clipboard.setData(entry.rawValue)
end
else
return UI.Grid.eventHandler(self, event)
return UI.ScrollingGrid.eventHandler(self, event)
end
return true
end
function page:rawExecute(s)
local fn, m = loadstring('return (' .. s .. ')', 'lua')
local fn, m = load('return _echo(' ..s.. ');', 'lua', nil, sandboxEnv)
if fn then
setfenv(fn, sandboxEnv)
m = { pcall(fn) }
fn = table.remove(m, 1)
if #m == 1 then
@@ -279,9 +280,8 @@ function page:rawExecute(s)
return fn, m
end
fn, m = loadstring(s, 'lua')
fn, m = load(s, 'lua', nil, sandboxEnv)
if fn then
setfenv(fn, sandboxEnv)
fn, m = pcall(fn)
end

View File

@@ -270,11 +270,23 @@ function page.container:setCategory(categoryName)
local col, row = gutter, 2
local count = #self.children
local r = math.random(1, 4)
-- reposition all children
for k,child in ipairs(self.children) do
child.x = self.width
child.y = math.floor(self.height)
child.tween = Tween.new(6, child, { x = col, y = row }, 'outSine')
if r == 1 then
child.x = math.random(1, self.width)
child.y = math.random(1, self.height)
elseif r == 2 then
child.x = self.width
child.y = self.height
elseif r == 3 then
child.x = math.floor(self.width / 2)
child.y = math.floor(self.height / 2)
elseif r == 4 then
child.x = self.width - col
child.y = row
end
child.tween = Tween.new(6, child, { x = col, y = row }, 'linear')
if k < count then
col = col + child.width
@@ -286,25 +298,25 @@ function page.container:setCategory(categoryName)
end
self:initChildren()
self.animate = true
local transition = { i = 1, parent = self, children = self.children }
function transition:update(device)
self.parent:clear()
for _,child in ipairs(self.children) do
child.tween:update(1)
child.x = math.floor(child.x)
child.y = math.floor(child.y)
child:draw()
end
self.canvas:blit(device, self, self)
self.i = self.i + 1
return self.i < 7
end
self:addTransition(transition)
end
function page.container:draw()
if self.animate then
self.animate = false
for i = 1, 6 do
for _,child in ipairs(self.children) do
child.tween:update(1)
child.x = math.floor(child.x)
child.y = math.floor(child.y)
end
UI.ViewportWindow.draw(self)
self:sync()
os.sleep()
end
else
UI.ViewportWindow.draw(self)
end
UI.ViewportWindow.draw(self)
end
function page:refresh()
@@ -442,10 +454,7 @@ local editor = UI.Dialog {
text = 'Icon', event = 'loadIcon', help = 'Select icon'
},
image = UI.NftImage {
y = 6,
x = 2,
height = 3,
width = 8,
y = 6, x = 2, height = 3, width = 8,
},
},
statusBar = UI.StatusBar(),
@@ -462,7 +471,7 @@ function editor:enable(app)
end
self.form.image:setImage(icon)
end
UI.Page.enable(self)
UI.Dialog.enable(self)
self:focusFirst()
end
@@ -531,7 +540,7 @@ function editor:eventHandler(event)
page:refresh()
page:draw()
else
return UI.Page.eventHandler(self, event)
return UI.Dialog.eventHandler(self, event)
end
return true
end

View File

@@ -489,17 +489,18 @@ local function autocomplete(line, suggestions)
end
end
local function shellRead(_tHistory )
local function shellRead(history)
term.setCursorBlink( true )
local sLine = ""
local nHistoryPos
local nPos = 0
local lastPattern
local w = term.getSize()
local sx = term.getCursorPos()
history:reset()
local function redraw( sReplace )
local nScroll = 0
if sx + nPos >= w then
@@ -563,32 +564,19 @@ local function shellRead(_tHistory )
redraw()
end
elseif param == keys.up or param == keys.down then
if _tHistory then
redraw(" ")
if param == keys.up then
if nHistoryPos == nil then
if #_tHistory > 0 then
nHistoryPos = #_tHistory
end
elseif nHistoryPos > 1 then
nHistoryPos = nHistoryPos - 1
end
else
if nHistoryPos == #_tHistory then
nHistoryPos = nil
elseif nHistoryPos ~= nil then
nHistoryPos = nHistoryPos + 1
end
end
if nHistoryPos then
sLine = _tHistory[nHistoryPos]
nPos = string.len( sLine )
else
sLine = ""
nPos = 0
end
redraw()
redraw(" ")
if param == keys.up then
sLine = history:back()
else
sLine = history:forward()
end
if sLine then
nPos = string.len(sLine)
else
sLine = ""
nPos = 0
end
redraw()
elseif param == keys.backspace then
if nPos > 0 then
redraw(" ")
@@ -637,13 +625,13 @@ while not bExit do
write("$ " )
term.setTextColour(_colors.commandTextColor)
term.setBackgroundColor(colors.black)
local sLine = shellRead(history.entries)
local sLine = shellRead(history)
if bExit then -- terminated
break
end
sLine = Util.trim(sLine)
if #sLine > 0 and sLine ~= 'exit' then
history.add(sLine)
history:add(sLine)
end
term.setTextColour(_colors.textColor)
if #sLine > 0 then