Date: Tue, 20 Feb 2018 03:58:45 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329621 - head/stand/lua Message-ID: <201802200358.w1K3wjTD048958@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Tue Feb 20 03:58:45 2018 New Revision: 329621 URL: https://svnweb.freebsd.org/changeset/base/329621 Log: stand/lua: Add and use drawer.menu_name_handlers Pull out specialized naming behavior into drawer.menu_name_handlers. This is currently only needed for the carousel entry, where naming is based on the current choice and the menu item purposefully does not store this state. The setup was designed so that every type can have a special name handler, and the default action is to simply use the result of entry.name(). Modified: head/stand/lua/drawer.lua Modified: head/stand/lua/drawer.lua ============================================================================== --- head/stand/lua/drawer.lua Tue Feb 20 03:51:09 2018 (r329620) +++ head/stand/lua/drawer.lua Tue Feb 20 03:58:45 2018 (r329621) @@ -159,6 +159,33 @@ function drawer.drawscreen(menu_opts) return drawer.drawmenu(menu_opts); end +drawer.menu_name_handlers = { + -- Menu name handlers should take the menu being drawn and entry being + -- drawn as parameters, and return the name of the item. + -- This is designed so that everything, including menu separators, may + -- have their names derived differently. The default action for entry + -- types not specified here is to call and use entry.name(). + [core.MENU_CAROUSEL_ENTRY] = function(drawing_menu, entry) + local carid = entry.carousel_id; + local caridx = menu.getCarouselIndex(carid); + local choices = entry.items(); + + if (#choices < caridx) then + caridx = 1; + end + return entry.name(caridx, choices[caridx], choices); + end, +}; + +function menu_entry_name(drawing_menu, entry) + local name_handler = drawer.menu_name_handlers[entry.entry_type]; + + if (name_handler ~= nil) then + return name_handler(drawing_menu, entry); + end + return entry.name(); +end + function drawer.drawmenu(m) x = drawer.menu_position.x; y = drawer.menu_position.y; @@ -179,22 +206,9 @@ function drawer.drawmenu(m) if (e.entry_type ~= core.MENU_SEPARATOR) then entry_num = entry_num + 1; screen.setcursor(x, y + line_num); - local name = ""; - if (e.entry_type == core.MENU_CAROUSEL_ENTRY) then - local carid = e.carousel_id; - local caridx = menu.getCarouselIndex(carid); - local choices = e.items(); + print(entry_num .. ". " .. menu_entry_name(m, e)); - if (#choices < caridx) then - caridx = 1; - end - name = e.name(caridx, choices[caridx], choices); - else - name = e.name(); - end - print(entry_num .. ". " .. name); - -- fill the alias table alias_table[tostring(entry_num)] = e; if (e.alias ~= nil) then @@ -204,7 +218,7 @@ function drawer.drawmenu(m) end else screen.setcursor(x, y + line_num); - print(e.name()); + print(menu_entry_name(m, e)); end ::continue:: end
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802200358.w1K3wjTD048958>