1
0
Fork 0
mirror of https://github.com/Reuh/daccord.git synced 2025-10-27 12:49:30 +00:00

Performance improvement and cleaning

This commit is contained in:
Étienne Fildadut 2018-08-30 22:04:39 +02:00
parent 96e0dc2c83
commit d21e9b67a0
2 changed files with 320 additions and 209 deletions

View file

@ -73,9 +73,9 @@ let config = {
port = 6600, port = 6600,
password = "", -- leave empty if you don't use a password password = "", -- leave empty if you don't use a password
-- Default behaviour -- Default behaviour
filenameSearch = false, -- instant search search also search in filenames (not only when using the file= syntax), slower filenameSearch = true, -- instant search search also search in filenames for untitled tracks (not only when using the file= syntax), slightly slower when handling large searches
-- Interface -- Interface
songDisplay = { "Track", { "Title", "file" }, "Artist", "Album" } -- list of tags or list of alternative tags (first one to exist will be used) to display for each song songDisplay = { "Track", { "Title", "Name", "file" }, "Artist", "Album" } -- list of tags or list of alternative tags (first one to exist will be used) to display for each song
} }
(loadfile("config.lua", "t", config) or () end)() -- GATHER UP EVERYONE! I WANT YOU TO MEET... THE AMAZING CONFIG FILE LOADER! (loadfile("config.lua", "t", config) or () end)() -- GATHER UP EVERYONE! I WANT YOU TO MEET... THE AMAZING CONFIG FILE LOADER!
@ -152,13 +152,14 @@ gui {
else else
start, sel, val, stop = @sub(1, @cursorPosition):match("()([A-Za-z_]+)=\"([^\"]*)()$") start, sel, val, stop = @sub(1, @cursorPosition):match("()([A-Za-z_]+)=\"([^\"]*)()$")
end end
-- TODO: candran "str":thing
-- music tags -- music tags
for _, tag in ipairs(tags) do for _, tag in ipairs(tags) do
if tag:lower() == sel:lower() then if tag:lower() == sel:lower() then
results = {}
let r, songs = mpc:list(tag) let r, songs = mpc:list(tag)
if r then if r then
results = {}
for _, s in ipairs(songs) do for _, s in ipairs(songs) do
if s[tag]:lower():match(val:lower()) then -- filter val if s[tag]:lower():match(val:lower()) then -- filter val
table.insert(results, s) table.insert(results, s)
@ -177,14 +178,17 @@ gui {
-- file search -- file search
if sel:lower() == "file" then if sel:lower() == "file" then
let r, songs = mpc:search(("(file == %q)"):format(val), "window", "0:"..tostring(list.h)) results = {}
if r then
results = {} list:setPump(10, :(start, stop)
for _, s in ipairs(songs) do let r, songs = mpc:search("(file == %q)":format(val), "window", "%s:%s":format(start-1, stop))
table.insert(results, s) if r then
list:insert{tostring(s.file)} for _, s in ipairs(songs) do
table.insert(results, s)
list:insert{tostring(s.file)}
end
end end
end end)
tagCompleting.tag = "file" tagCompleting.tag = "file"
tagCompleting.start = start tagCompleting.start = start
@ -192,59 +196,85 @@ gui {
end end
-- Song search -- Song search
else else
results = {
_filenameSearchOffset = 0, -- where the filename search begin in the result list
_filenameSearchStart = 0 -- where the search window should start in the filename search
}
-- Build query -- Build query
let query = {} let query = {}
-- Any selectors -- Any selectors
let withoutSel = @content:gsub("[A-Za-z_]+=[^\" ]+", ""):gsub("[A-Za-z_]+=\"[^\"]*\"", "") let withoutSel = @content:gsub("[A-Za-z_]+=[^\" ]+", ""):gsub("[A-Za-z_]+=\"[^\"]*\"", "")
for word in withoutSel:gmatch("[^%s]+") do for word in withoutSel:gmatch("[^%s]+") do
table.insert(query, ("(any == %q)"):format(word)) table.insert(query, "(any == %q)":format(word))
end end
-- Tag selectors -- Tag selectors
for tag, val in @content:gmatch("([A-Za-z_]+)=([^\" ]+)") do for tag, val in @content:gmatch("([A-Za-z_]+)=([^\" ]+)") do
table.insert(query, ("(%s == %q)"):format(tag, val)) table.insert(query, "(%s == %q)":format(tag, val))
end end
for tag, val in @content:gmatch("([A-Za-z_]+)=\"([^\"]*)\"") do for tag, val in @content:gmatch("([A-Za-z_]+)=\"([^\"]*)\"") do
table.insert(query, ("(%s == %q)"):format(tag, val)) table.insert(query, "(%s == %q)":format(tag, val))
end end
-- Limit -- Limit
table.insert(query, "window") table.insert(query, "window")
table.insert(query, "0:"..tostring(list.h)) table.insert(query, "0:0")
-- Search -- And they pumped...
let r, songs = mpc:search(unpack(query)) list:setPump(10, :(start, stop)
if r then results = songs end let filenameSearchStop -- where the filename search window should end
-- Filename search -- only search if didn't reache filename search
if config.filenameSearch then if results._filenameSearchStart == 0 then
for i=1, #query, 1 do -- Update limit
query[i] = query[i]:gsub("^%(any", "(file") query[#query] = "%s:%s":format(start-1, stop)
end
let r, songs = mpc:search(unpack(query)) -- Search
if r then let r, songs = mpc:search(unpack(query))
-- Merge if r then
for _, newSong in ipairs(songs) do -- TODO more efficient (using a sorted thing) -- Update widget
let found = false for _, s in ipairs(songs) do
for _, existingSong in ipairs(results) do table.insert(results, songs)
if newSong.file == existingSong.file then @insert(songTable(s))
found = true
break
end
end end
if not found then
table.insert(results, newSong) -- Fill what's left with filename search
if config.filenameSearch and #results < stop then
results._filenameSearchOffset = #results
filenameSearchStop = stop-results._filenameSearchOffset+results._filenameSearchStart
end end
end end
else
filenameSearchStop = stop-results._filenameSearchOffset+results._filenameSearchStart
end end
end
-- Update widget -- Filename search
for _, s in ipairs(results) do if filenameSearchStop then
list:insert(songTable(s)) for i=1, #query-2, 1 do
end query[i] = query[i]:gsub("^%(any", "(file")
end
-- Loop to fill as much as possible (since we skip tracks with a title)
repeat
query[#query] = "%s:%s":format(results._filenameSearchStart, filenameSearchStop)
results._filenameSearchStart = filenameSearchStop
let r, songs = mpc:search(unpack(query))
if r then
for _, newSong in ipairs(songs) do
if not newSong.Title then
table.insert(results, newSong)
@insert(songTable(newSong))
end
end
end
filenameSearchStop = stop-results._filenameSearchOffset+results._filenameSearchStart
until filenameSearchStop == results._filenameSearchStart or #songs == 0
end
end)
end end
end end
}, },
@ -303,26 +333,33 @@ gui {
updateInterval = 5, updateInterval = 5,
onUpdate = :() pump = :(start, stop)
let r, songs = mpc:playlistinfo() let r, songs = mpc:playlistinfo("%s:%s":format(start-1, stop))
if r then playlist = songs end if r then
for i=1, stop-start+1, 1 do
for i, s in ipairs(playlist) do if songs[i] then
let item = songTable(s) playlist[start+i-1] = songs[i]
if @content[i] then let item = songTable(songs[i])
@replace(i, item) if @content[start+i-1] then
else @replace(start+i-1, item)
@insert(i, item) else
@insert(start+i-1, item)
end
else
playlist[start+i-1] = 0
@remove(start+i-1)
start -= 1
end
end end
end end
end,
while #@content > #playlist do
@remove() onUpdate = :()
end @repump()
end, end,
onSelect = :(l) onSelect = :(l)
if #playlist > 0 then if playlist[l[1]] then
mpc:playid(playlist[l[1]].Id) mpc:playid(playlist[l[1]].Id)
end end
end, end,

382
gui.can
View file

@ -26,21 +26,17 @@ os.setlocale("")
let everyWidget = {} let everyWidget = {}
let widget = class { let widget = class {
_exit = false, id = nil, -- (optional) widget id
type = nil, -- widget type
_redraw = true, width = nil, -- height
x = 0, height = nil, -- width
y = 0,
w = 0,
h = 0,
parent = {}, focused = false, -- true if take inputs
focused = false,
updateInterval = -1, updateInterval = -1, -- time in seconds between updates
_nextUpdate = os.time(), -- -1 = no update
new = :(data) new = :(data) -- create a new widget
table.insert(everyWidget, self) table.insert(everyWidget, self)
-- Copy properties -- Copy properties
@ -49,60 +45,74 @@ let widget = class {
end end
-- Dimensions -- Dimensions
if not @parent._firstX then @parent._firstX, @parent._firstY = 0, 0 end if not @_parent._firstX then @_parent._firstX, @_parent._firstY = 0, 0 end
@x, @y = @parent._firstX, @parent._firstY @_x, @_y = @_parent._firstX, @_parent._firstY
if @width == "extend" @w = @parent.w - @x if @width == "extend" @_w = @_parent._w - @_x
elseif @width:match("%d+em$") @w = tonumber(@width:match("%d+")) elseif @width:match("%d+em$") @_w = tonumber(@width:match("%d+"))
if @height == "extend" then if @height == "extend" then
@h = @parent.h - @y @_h = @_parent._h - @_y
@parent._lastVerticalExtend = self -- will be resized if vertical space is needed @_parent._lastVerticalExtend = self -- will be resized if vertical space is needed
@parent._afterLastVerticalExtend = {} @_parent._afterLastVerticalExtend = {}
elseif @height:match("%d+em$") @h = tonumber(@height:match("%d+")) elseif @height:match("%d+em$") @_h = tonumber(@height:match("%d+"))
if @y >= @parent.h then -- resize if @_y >= @_parent._h then -- resize
@parent._lastVerticalExtend:_resize(@parent._lastVerticalExtend.w, @parent._lastVerticalExtend.h - @h) @_parent._lastVerticalExtend:_resize(@_parent._lastVerticalExtend._w, @_parent._lastVerticalExtend._h - @_h)
@parent._firstY -= @h @_parent._firstY -= @_h
@y -= @h @_y -= @_h
for _, el in ipairs(@parent._afterLastVerticalExtend) do -- move widgets for _, el in ipairs(@_parent._afterLastVerticalExtend) do -- move widgets
el.y -= @h el._y -= @_h
end end
end end
@parent._firstX += @w @_parent._firstX += @_w
if @parent._firstX >= @parent.w then @parent._firstX = 0 end -- newline if @_parent._firstX >= @_parent._w then @_parent._firstX = 0 end -- newline
@parent._firstY += @h @_parent._firstY += @_h
if @parent._lastVerticalExtend ~= self and @parent._afterLastVerticalExtend then table.insert(@parent._afterLastVerticalExtend, self) end if @_parent._lastVerticalExtend ~= self and @_parent._afterLastVerticalExtend then table.insert(@_parent._afterLastVerticalExtend, self) end
-- Setup -- Setup
if @_setup then @_setup() end if @_setup then @_setup() end
screen:move(@parent.y + @y + @h, @parent.x + @x + @w) screen:move(@_parent._y + @_y + @_h, @_parent._x + @_x + @_w)
end, end,
exit = :() exit = :() -- exit the application
@_exit = true @_exit = true
end, end,
byId = :(id) byId = :(id) -- return a widget by its id
for _, el in ipairs(everyWidget) do for _, el in ipairs(everyWidget) do
if el.id == id return el if el.id == id return el
end end
error("no element with id "..tostring(id)) error("no element with id "..tostring(id))
end, end,
updateAfter = :(time) updateAfter = :(time) -- reschedule the next widget update
@_nextUpdate = os.time() + time @_nextUpdate = os.time() + time
end end,
_parent = {},
_exit = false,
_redraw = true,
_x = 0,
_y = 0,
_w = 0,
_h = 0,
_nextUpdate = os.time(), -- -1 = no update
} }
let widgets = setmetatable({ let widgets = setmetatable({
fill = widget { fill = widget {
fill = nil, -- filling type
_draw = :() _draw = :()
if type(@fill) == "string" then @fill = curses[@fill] end if type(@fill) == "string" then @fill = curses[@fill] end
for y = @parent.y + @y, @parent.y + @y + @h - 1 do for y = @_parent._y + @_y, @_parent._y + @_y + @_h - 1 do
screen:move(y, @parent.x + @x) screen:move(y, @_parent._x + @_x)
for x = @parent.x + @x, @parent.x + @x + @w - 1 do for x = @_parent._x + @_x, @_parent._x + @_x + @_w - 1 do
screen:addch(@fill or 32) screen:addch(@fill or 32)
end end
end end
@ -110,10 +120,27 @@ let widgets = setmetatable({
}, },
input = widget { input = widget {
content = "", content = "", -- text content
cursorPosition = 1, cursorPosition = 1, -- cursor position, first character is 1
sub = :(start, stop=utf8.len(@content)) -- get the substring
if stop < 1 or start >= utf8.len(@content) then
return ""
else
return @content:sub(utf8.offset(@content, start), (utf8.offset(@content, stop+1) or (#@content+1))-1)
end
end,
replace = :(start, stop, newText) -- replace a substring
if @cursorPosition >= stop then
@cursorPosition += utf8.len(newText) - (stop - start)
end
@content = @sub(1, start-1) .. newText .. @sub(stop+1)
@onTextInput()
@_redraw = true
end,
onTextInput = :() end, -- called when the text change
_input = :(charbuffer, control) _input = :(charbuffer, control)
let y, x = @parent.y + @y, @parent.x + @x + @cursorPosition-1 let y, x = @_parent._y + @_y, @_parent._x + @_x + @cursorPosition-1
if control == "backspace" then if control == "backspace" then
screen:mvdelch(y, x-1) screen:mvdelch(y, x-1)
if @cursorPosition > 1 then if @cursorPosition > 1 then
@ -159,41 +186,108 @@ let widgets = setmetatable({
end end
end, end,
_draw = :() _draw = :()
for y = @parent.y + @y, @parent.y + @y + @h - 1 do for y = @_parent._y + @_y, @_parent._y + @_y + @_h - 1 do
screen:move(y, @parent.x + @x) screen:move(y, @_parent._x + @_x)
for x = @parent.x + @x, @parent.x + @x + @w - 1 do for x = @_parent._x + @_x, @_parent._x + @_x + @_w - 1 do
screen:addch(32) screen:addch(32)
end end
end end
screen:mvaddstr(@parent.y + @y, @parent.x + @x, @content) screen:mvaddstr(@_parent._y + @_y, @_parent._x + @_x, @content)
end, end,
_placeCursor = :() _placeCursor = :()
screen:move(@parent.y + @y, @parent.x + @x + @cursorPosition-1) screen:move(@_parent._y + @_y, @_parent._x + @_x + @cursorPosition-1)
return true return true
end, end
sub = :(start, stop=utf8.len(@content))
if stop < 1 or start >= utf8.len(@content) then
return ""
else
return @content:sub(utf8.offset(@content, start), (utf8.offset(@content, stop+1) or (#@content+1))-1)
end
end,
replace = :(start, stop, newText)
if @cursorPosition >= stop then
@cursorPosition += utf8.len(newText) - (stop - start)
end
@content = @sub(1, start-1) .. newText .. @sub(stop+1)
@onTextInput()
@_redraw = true
end,
onTextInput = :() end
}, },
list = widget { list = widget {
content = {}, content = {}, -- list content (list of tables)
columnWidth = {}, selected = 1, -- last selected line
selected = 1, pump = nil, -- function used to pump. See :setPump().
scroll = 0, insert = :(pos, item) -- insert a line, shifting elements after it
if item then
table.insert(@content, pos, item)
if @selected > pos and @selected < #@content then
@selected += 1
end
else
item = pos
table.insert(@content, item)
end
if #@content == 1 then -- column count is determined by 1st item (other items can do what they want, this isn't a dictatorship)
@_columnWidth = [for _=1,#item do 0 end]
end
if #item >= #@_columnWidth then -- if the column fits into our dictatorship, update column width
for c=1, #@_columnWidth do
let l = utf8.len(item[c]) -- if it isn't valid UTF8, ignore (can happen for files in Windows-made zipfiles). Should probably raise a warning or something... TODO.
if l and l > @_columnWidth[c] then
@_columnWidth[c] = utf8.len(item[c]) + 1
end
end
end
@_redraw = true
end,
remove = :(pos=#@content) -- remove a line, shifting elements after it
table.remove(@content, pos)
if @selected > pos and @selected > 1 then
@selected -= 1
end
@selected = math.min(@selected, #@content)
@_redraw = true
end,
replace = :(pos, item) -- replace a line
@content[pos] = item
if #@content == 1 then -- column count is determined by 1st item (other items can do what they want, this isn't a dictatorship)
@_columnWidth = [for _=1,#item do 0 end]
end
if #item >= #@_columnWidth then -- if the column fits into our dictatorship, update column width
for c=1, #@_columnWidth do
let l = utf8.len(item[c]) -- if it isn't valid UTF8, ignore (can happen for files in Windows-made zipfiles). Should probably raise a warning or something... TODO.
if l and l > @_columnWidth[c] then
@_columnWidth[c] = utf8.len(item[c]) + 1
end
end
end
@_redraw = true
end,
-- Give a pump function (startPosition, stopPosition) -> {tables...} which load the lines between startPosition and stopPosition.
-- The pump may returns the lines instead of inserting them itself.
-- step is the preferance of number of line to be loaded at one.
setPump = :(step, newPump)
@pump = newPump
@_pumpStep = step
if #@content == 0 then
let pumped = @pump(1, math.max(@_h, @_pumpStep))
if pumped then
for _, l in ipairs(pumped) do
@insert(l)
end
end
end
end,
repump = :() -- force already pumped elements to be repumped. The rest of the list state will be kept.
@content = {}
@_columnWidth = {}
let pumped = @pump(1, math.max(@_scroll+@_h, @_scroll+@_pumpStep)) -- TODO: change everything so we only need to pump what is currently displayed
if pumped then
for i, l in ipairs(pumped) do
@replace(@_scroll+i-1, l)
end
end
end,
clear = :() -- reset list: content, current selection, current pump
@content = {}
@_columnWidth = {}
@_redraw = true
@selected = 1
@_scroll = 0
@pump = nil
end,
onSelect = :() end, -- called when selecting a line
_columnWidth = {},
_scroll = 0,
_pumpStep = 5,
_redraw = true, _redraw = true,
_input = :(charbuffer, control) _input = :(charbuffer, control)
if control == "up" then if control == "up" then
@ -209,13 +303,23 @@ let widgets = setmetatable({
@selected += 10 @selected += 10
@_redraw = true @_redraw = true
end end
if @pump and @selected > #@content then -- pump data if needed
let pumped = @pump(#@content+1, #@content+@_pumpStep+1)
if pumped then
for _, l in ipairs(pumped) do
@insert(l)
end
end
end
@selected = math.min(math.max(@selected, 1), math.max(#@content, 1)) @selected = math.min(math.max(@selected, 1), math.max(#@content, 1))
while @selected <= @scroll do while @selected <= @_scroll do
@scroll -= 1 @_scroll -= 1
end end
while @selected >= @scroll + @h + 1 do while @selected >= @_scroll + @_h + 1 do
@scroll += 1 @_scroll += 1
end end
if control == "enter" then if control == "enter" then
@ -227,79 +331,37 @@ let widgets = setmetatable({
end, end,
_draw = :() _draw = :()
let oY, oX = screen:getyx() let oY, oX = screen:getyx()
for y = @parent.y + @y, @parent.y + @y + @h -1 do -- clear for y = @_parent._y + @_y, @_parent._y + @_y + @_h -1 do -- clear
screen:mvaddstr(y, @parent.x + @x, (" "):rep(@w)) screen:mvaddstr(y, @_parent._x + @_x, (" "):rep(@_w))
end end
screen:move(@parent.y + @y, @parent.x + @x) screen:move(@_parent._y + @_y, @_parent._x + @_x)
for i=@scroll+1, @scroll + @h do -- draw for i=@_scroll+1, @_scroll + @_h do -- draw
if i == @selected then if i == @selected then
screen:standout() screen:standout()
end end
let colx = @parent.x+@x let colx = @_parent._x+@_x
for c=1, #@columnWidth do for c=1, #@_columnWidth do
screen:mvaddstr(@parent.y+@y+i-1-@scroll, colx, @content[i] and @content[i][c] or "") -- TODO: make sure it doesn't go too far right or something screen:mvaddstr(@_parent._y+@_y+i-1-@_scroll, colx, @content[i] and @content[i][c] or "") -- TODO: make sure it doesn't go too far right or something
colx += @columnWidth[c] colx += @_columnWidth[c]
end end
if i == @selected then if i == @selected then
screen:standend() screen:standend()
end end
end end
screen:move(oY, oX) screen:move(oY, oX)
end, end
insert = :(pos, item)
if item then
table.insert(@content, pos, item)
if @selected > pos and @selected < #@content then
@selected += 1
end
else
item = pos
table.insert(@content, item)
end
if #@content == 1 then -- column count is determined by 1st item (other items can do what they want, this isn't a dictatorship)
@columnWidth = [for _=1,#item do 0 end]
end
if #item >= #@columnWidth then -- if the column fits into our dictatorship, update column width
for c=1, #@columnWidth do
let l = utf8.len(item[c]) -- if it isn't valid UTF8, ignore (can happen for files in Windows-made zipfiles). Should probably raise a warning or something... TODO.
if l and l > @columnWidth[c] then
@columnWidth[c] = utf8.len(item[c]) + 1
end
end
end
@_redraw = true
end,
remove = :(pos=#@content)
table.remove(@content, pos)
if @selected > pos and @selected > 1 then
@selected -= 1
end
@selected = math.min(@selected, #@content)
@_redraw = true
end,
replace = :(pos, item)
@content[pos] = item
@_redraw = true
end,
clear = :()
@content = {}
@columnWidth = {}
@_redraw = true
@selected = 1
@scroll = 0
end,
onSelect = :() end
}, },
tabs = widget { tabs = widget {
selected = 1, selected = 1, -- selected tab
children = {}, children = {}, -- children elements
_children = {}, _children = {},
_setup = :() _setup = :()
for i, tab in ipairs(@) do for i, tab in ipairs(@) do
@children[i] = { x = @x, y = @y, w = @w, h = @h } @children[i] = { _x = @_x, _y = @_y, _w = @_w, _h = @_h }
for _, el in ipairs(tab) do for _, el in ipairs(tab) do
el.parent = @children[i] el._parent = @children[i]
table.insert(@children[i], widgets[el.type]:new(el)) table.insert(@children[i], widgets[el.type]:new(el))
end end
end end
@ -316,53 +378,55 @@ let widgets = setmetatable({
end end
end, end,
_resize = :(w, h) _resize = :(w, h)
@w, @h = w, h @_w, @_h = w, h
for i, tab in ipairs(@) do for i, tab in ipairs(@) do
for _, el in ipairs(@children[i]) do for _, el in ipairs(@children[i]) do
if el.x + el.w > w then el.w = w - el.x end if el._x + el._w > w then el._w = w - el._x end
if el.y + el.h > h then el.h = h - el.y end if el._y + el._h > h then el._h = h - el._y end
end end
end end
end end
}, },
label = widget { label = widget {
content = "Label", content = "Label", -- text
_draw = :() set = :(str) -- set text
screen:mvaddstr(@parent.y + @y, @parent.x + @x, @content .. (" "):rep(@w - #@content))
end,
set = :(str)
@content = str @content = str
@_redraw = true @_redraw = true
end,
_draw = :()
screen:mvaddstr(@_parent._y + @_y, @_parent._x + @_x, @content .. (" "):rep(@_w - #@content))
end end
}, },
slider = widget { slider = widget {
min = 0, min = 0, -- min value
max = 1, max = 1, -- max value
current = 0, value = 0, -- current value
head = "⏸", head = "⏸", -- associated symbol
_draw = :() set = :(value) -- change value
let len = math.ceil((@current - @min) / (@max - @min) * @w) @value = value
screen:mvaddstr(@parent.y + @y, @parent.x + @x, ("="):rep(len-1))
screen:addstr(@head .. (" "):rep(@w - len))
end,
set = :(current)
@current = current
@_redraw = true @_redraw = true
end, end,
setMax = :(max) setMax = :(max) -- change maximum
@max = max @max = max
@_redraw = true @_redraw = true
end, end,
setMin = :(min) setMin = :(min) -- change minimum
@min = min @min = min
@_redraw = true @_redraw = true
end, end,
setHead = :(head) setHead = :(head) -- change symbol
@head = head @head = head
@_redraw = true @_redraw = true
end end,
_draw = :()
let len = math.ceil((@value - @min) / (@max - @min) * @_w)
screen:mvaddstr(@_parent._y + @_y, @_parent._x + @_x, ("="):rep(len-1))
screen:addstr(@head .. (" "):rep(@_w - len))
end,
} }
}, { }, {
__index = (t, k) __index = (t, k)
@ -396,11 +460,11 @@ return (ui)
screen:clear() screen:clear()
let h, w = screen:getmaxyx() let h, w = screen:getmaxyx()
let parent = { let parent = {
x = 0, y = 0, _x = 0, _y = 0,
w = w, h = h _w = w, _h = h
} }
for _, el in ipairs(ui) do for _, el in ipairs(ui) do
el.parent = parent el._parent = parent
el._widget = widgets[el.type]:new(el) el._widget = widgets[el.type]:new(el)
end end
@ -444,9 +508,19 @@ return (ui)
elseif k == "[B" then elseif k == "[B" then
control = "down" control = "down"
elseif k == "[5" then elseif k == "[5" then
control = "pgup" k ..= string.char(screen:getch())
if k == "[5~" then
control = "pgup"
else
error("unknown control "..tostring(k))
end
elseif k == "[6" then elseif k == "[6" then
control = "pgdown" k ..= string.char(screen:getch())
if k == "[6~" then
control = "pgdown"
else
error("unknown control "..tostring(k))
end
elseif k == "[3" then elseif k == "[3" then
k ..= string.char(screen:getch()) k ..= string.char(screen:getch())
if k == "[3~" then if k == "[3~" then