Provide reusable menu definition, rendering, navigation, and dispatch
Source: target-root/usr/local/lib/solidgroundux/common/sgnd-menu.sh
Provide reusable menu definition, rendering, navigation, and dispatch
Public functions
- Initialize a reusable menu model
- Register a menu group
- Register one menu item
- Set menu item status decoration
- Render the current menu
- Compatibility alias for sgnd_menu_register_group
- Compatibility alias for sgnd_menu_register_item
- Read one menu choice or navigation key
- Dispatch a normalized menu choice
Internal functions
| Function | Purpose | Arguments | Output |
|---|---|---|---|
_sgnd_lib_guard | Ensure direct execution is rejected and record that the library has been sourced. | — | — |
_sgnd_flag_is_on | Determine whether a menu or framework flag represents an enabled state. | - $1 — Value to evaluate. | — |
_sgnd_console_toggleword | Format one toggle label using the enabled/disabled color and underline its hotkey. | - $1 — WORD - Toggle text. | Writes the styled toggle word to stdout. |
_sgnd_console_statusword | Render one status-bar fragment using its configured state and style. | - $1 — LABEL - Status label. | Writes a styled LABEL: VALUE fragment to stdout. |
_sgnd_console_onoff | Format an enabled or disabled state as a colored On/Off value. | - $1 — VALUE - Boolean/numeric state. | Writes styled On or Off text to stdout. |
_sgnd_console_label_clearonrender | Build the status-bar label for the clear-on-render setting. | — | Writes the current Clear screen toggle label to stdout. |
_sgnd_console_label_dryrun | Build the status-bar label for dry-run mode. | — | Writes the current Dry-run/Commit toggle label to stdout. |
_sgnd_console_label_debug | Build the status-bar label for debug mode. | — | Writes the current Debug toggle label to stdout. |
_sgnd_console_label_verbose | Build the status-bar label for verbose output. | — | Writes the current Verbose toggle label to stdout. |
_sgnd_console_label_logfile | Build the status-bar label for logfile state. | — | Writes the current Logfile toggle label to stdout. |
_sgnd_console_toggle_clearonrender | Switch SGND_CLEAR_ONRENDER between enabled and disabled for the current session. | — | — |
_sgnd_console_toggle_debug | Toggle FLAG_DEBUG and refresh the framework run mode. | — | — |
_sgnd_console_toggle_verbose | Switch FLAG_VERBOSE for the current console session. | — | — |
_sgnd_console_theme_name | Derive a human-readable theme name from SGND_UI_STYLE. | — | Writes the normalized theme name to stdout. |
_sgnd_console_set_lines_per_page | Prompt for and apply the number of menu lines available per page. | — | — |
_sgnd_console_redraw | Signal that the current console menu should be rendered again. | — | — |
_sgnd_console_quit | Signal that the console menu should terminate. | — | — |
_sgnd_console_nextpage | Advance the menu to the next visible page when available. | — | — |
_sgnd_console_prevpage | Move the menu to the previous visible page when available. | — | — |
_sgnd_console_refresh_model_cache | Convert registered group/item rows into direct-index arrays used by layout and rendering. | — | — |
_sgnd_console_collect_group_render_indexes | Build the cached group order used by the renderer for the currently active module source. | — | — |
_sgnd_console_collect_visible_item_indexes | Cache menu rows that may be rendered or selected on the active module page. | — | — |
_sgnd_console_visible_item_count | Count the currently visible menu items. | — | Writes the number of currently visible/renderable menu items to stdout. |
_sgnd_console_get_visible_row_index | Translate a visible menu-item position into the corresponding model row. | - $1 — VISIBLE_INDEX - Zero-based position in SGND_VISIBLE_ITEM_INDEXES. | Writes the corresponding SGND_ITEM_ROWS index to stdout. |
_sgnd_menu_module_chapter | Group ordered console modules by their tens prefix: 10/15, 20/25, 30/35, etc. | - $1 — SOURCE - Module source/id beginning with an optional numeric prefix. | Numeric chapter identifier. Sources without a numeric prefix use chapter 0. |
_sgnd_console_get_visible_display_number | Convert a model row index into the numeric key shown to the user, resetting numbering when the module chapter changes. | - $1 — ROW_INDEX - Index in SGND_ITEM_ROWS. | Writes the one-based display number to stdout. |
_sgnd_console_find_visible_pos_for_row | Find the visible position corresponding to a model row. | - $1 — ROW_INDEX - Index in SGND_ITEM_ROWS. | Writes the zero-based visible position to stdout. |
_sgnd_console_group_continues_after_visible_pos | Determine whether the current group has additional items later in the visible list. | - $1 — GROUP_KEY - Group to test. | — |
_sgnd_console_body_height | Determine how many rendered lines may be allocated to one menu page. | — | Writes the effective body height to stdout. |
_sgnd_console_measure_item_lines | Measure how many terminal lines one rendered menu item occupies. | - $1 — ROW_INDEX - Item row to measure. | Writes the number of terminal lines required by the item and wrapped description. |
_sgnd_console_measure_group_header_lines | Measure the terminal line count of a rendered menu-group header. | — | Writes the fixed two-line group-header height to stdout. |
_sgnd_console_display_key_width | Keep item labels aligned when a menu contains multi-digit selections. | — | Writes the number of character columns required by the widest visible numeric key. |
_sgnd_console_calc_label_width | Find the widest visible item prefix so labels and descriptions align consistently. | — | Writes the calculated label width to stdout. |
_sgnd_console_build_pages | Partition visible menu rows into pages that fit the current terminal and configured line limit. | — | — |
_sgnd_console_render_menu | Render the title, page indicator, paged module rows, builtin groups, and toggle bar. | — | — |
_sgnd_console_render_menu_title | Render the console title/version, hostname, description, and surrounding borders. | — | — |
_sgnd_console_render_page_header | Show page navigation state as a centered section header when the menu spans | — | — |
_sgnd_console_render_menu_body_paged | Select the current page's cached rows/groups and pass them to the row renderer. | — | — |
_sgnd_console_render_page_rows | Render one page using the supplied group keys and model row indexes. | - $1 — PAGE_GROUPS - Name of an array containing group keys. | — |
_sgnd_console_render_group | Render a group and all of its currently renderable items, primarily for builtin groups outside normal paging. | - $1 — GROUP_KEY - Registered group key. | — |
_sgnd_console_render_togglebar | Show the current mode, access level, log levels, theme, and direct-key legend beneath the menu. | — | — |
_sgnd_menu_status_text | Render the icon and colors associated with a named menu-item status. | - $1 — STATUS - never, success, warning, failed, or empty. | Writes the styled icon plus trailing space, or nothing for an empty/unknown status. |
_sgnd_console_valid_choices_csv | Emit a comma-separated list containing visible numeric selections and active | — | Writes the comma-separated choice list to stdout. |
_sgnd_menu_execute_item | Execute a registered menu item while allowing a host application to wrap | - $1 — ITEM_KEY - Registered menu item key. | — |
_sgnd_console_dispatch | Resolve navigation, lines-per-page, numeric, or direct-key choices against the | - $1 — CHOICE - Normalized choice returned by sgnd_menu_read_choice. | — |
Description
Provides the reusable menu system used by the management console and other SolidGroundUX applications.
The library:
- Defines menu structures and item registration mechanisms
- Supports grouping, ordering, and labeling of menu items
- Integrates with rendering helpers to display menus consistently
- Handles user selection and dispatch to registered actions
- Enables modular extension by allowing external modules to register items
Design principles
- Modular menu composition through registration rather than hardcoding
- Clear separation between menu definition, rendering, and execution
- Predictable navigation and selection behavior
- Minimal coupling to specific applications or modules
Role in framework
- Reusable SolidGroundUX UI component
- Bridges UI rendering, input handling, and executable scripts
- Enables pluggable console applications through module-based menus
Non-goals
- Full TUI frameworks or complex screen management
- Persistent menu state beyond runtime session
- Business logic execution beyond dispatching actions
