From 82526665364389d92e0f2c33eba04678275863bb Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 27 Jan 2026 01:12:16 -0800 Subject: on-demand calculation and update of option info Using metatables to calculate info strings on render, we can avoid precomputing it for all options when generating the menu, making certain menus open much faster. This also allows us to update dynamic info, e.g. the currently programme, while the menu is open. --- osd.lua | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'osd.lua') diff --git a/osd.lua b/osd.lua index 58c6903..7075a73 100644 --- a/osd.lua +++ b/osd.lua @@ -235,8 +235,9 @@ function mt:option_text(opt, info) str = col .. '[' .. str .. ']' end - if opt.info and #opt.info > 0 then - str = str .. colour.info .. ' (' .. asscape(opt.info) .. ')' + local opt_info = opt.info + if opt_info and #opt_info > 0 then + str = str .. colour.info .. ' (' .. asscape(opt_info) .. ')' end return str @@ -542,6 +543,8 @@ function mt:render() end function mt:redraw(state) + self.redraw_time = os.time() + local out_titles = {} local out_options = {} @@ -574,15 +577,10 @@ function mt:redraw(state) #menu.options) do local opt = menu.options[i] - -- use real-time count for favourites - if opt.id == 'favourites' then - opt.info = tostring(#state.favourites) - end - local selected = i == menu.cursor and not menu.search_active local info = { selected = selected, - empty = (opt.type == 'group' and not opt.lazy and + empty = (opt.type == 'group' and opt.children and #opt.children == 0), playing = not not ( opt.id and opt.id == state.playing_id), -- cgit v1.2.3-70-g09d2