From owner-svn-src-head@freebsd.org Tue Feb 20 03:58:46 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 38317F23519; Tue, 20 Feb 2018 03:58:46 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D64BA7F10E; Tue, 20 Feb 2018 03:58:45 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CE60A2412B; Tue, 20 Feb 2018 03:58:45 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1K3wj5q048959; Tue, 20 Feb 2018 03:58:45 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1K3wjTD048958; Tue, 20 Feb 2018 03:58:45 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201802200358.w1K3wjTD048958@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 20 Feb 2018 03:58:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329621 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 329621 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Feb 2018 03:58:46 -0000 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