Menu Library

SolidGroundUX DocumentationSolidGroundUX
NL

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

Internal functions
FunctionPurposeArgumentsOutput
_sgnd_flag_is_onDetermine whether a menu or framework flag represents an enabled state.- $1 — Value to evaluate.—
_sgnd_console_togglewordFormat 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_statuswordRender one status-bar fragment using its configured state and style.- $1 — LABEL - Status label.Writes a styled LABEL: VALUE fragment to stdout.
_sgnd_console_onoffFormat 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_clearonrenderBuild the status-bar label for the clear-on-render setting.—Writes the current Clear screen toggle label to stdout.
_sgnd_console_label_dryrunBuild the status-bar label for dry-run mode.—Writes the current Dry-run/Commit toggle label to stdout.
_sgnd_console_label_debugBuild the status-bar label for debug mode.—Writes the current Debug toggle label to stdout.
_sgnd_console_label_verboseBuild the status-bar label for verbose output.—Writes the current Verbose toggle label to stdout.
_sgnd_console_label_logfileBuild the status-bar label for logfile state.—Writes the current Logfile toggle label to stdout.
_sgnd_console_toggle_clearonrenderSwitch SGND_CLEAR_ONRENDER between enabled and disabled for the current session.——
_sgnd_console_toggle_debugToggle FLAG_DEBUG and refresh the framework run mode.——
_sgnd_console_toggle_verboseSwitch FLAG_VERBOSE for the current console session.——
_sgnd_console_theme_nameDerive a human-readable theme name from SGND_UI_STYLE.—Writes the normalized theme name to stdout.
_sgnd_console_set_lines_per_pagePrompt for and apply the number of menu lines available per page.——
_sgnd_console_redrawSignal that the current console menu should be rendered again.——
_sgnd_console_quitSignal that the console menu should terminate.——
_sgnd_console_nextpageAdvance the menu to the next visible page when available.——
_sgnd_console_prevpageMove the menu to the previous visible page when available.——
_sgnd_console_refresh_model_cacheConvert registered group/item rows into direct-index arrays used by layout and rendering.——
_sgnd_console_collect_group_render_indexesBuild the cached group order used by the renderer for the currently active module source.——
_sgnd_console_collect_visible_item_indexesCache menu rows that may be rendered or selected on the active module page.——
_sgnd_console_visible_item_countCount the currently visible menu items.—Writes the number of currently visible/renderable menu items to stdout.
_sgnd_console_get_visible_row_indexTranslate 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_chapterGroup 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_numberConvert 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_rowFind 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_posDetermine whether the current group has additional items later in the visible list.- $1 — GROUP_KEY - Group to test.—
_sgnd_console_body_heightDetermine how many rendered lines may be allocated to one menu page.—Writes the effective body height to stdout.
_sgnd_console_measure_item_linesMeasure 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_linesMeasure the terminal line count of a rendered menu-group header.—Writes the fixed two-line group-header height to stdout.
_sgnd_console_display_key_widthKeep 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_widthFind the widest visible item prefix so labels and descriptions align consistently.—Writes the calculated label width to stdout.
_sgnd_console_build_pagesPartition visible menu rows into pages that fit the current terminal and configured line limit.——
_sgnd_console_render_menuRender the title, page indicator, paged module rows, builtin groups, and toggle bar.——
_sgnd_console_render_menu_titleRender the console title/version, hostname, description, and surrounding borders.——
_sgnd_console_render_page_headerShow page navigation state as a centered section header when the menu spans——
_sgnd_console_render_menu_body_pagedSelect the current page's cached rows/groups and pass them to the row renderer.——
_sgnd_console_render_page_rowsRender one page using the supplied group keys and model row indexes.- $1 — PAGE_GROUPS - Name of an array containing group keys.—
_sgnd_console_render_groupRender 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_togglebarShow the current mode, access level, log levels, theme, and direct-key legend beneath the menu.——
_sgnd_menu_status_textRender 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_csvEmit a comma-separated list containing visible numeric selections and active—Writes the comma-separated choice list to stdout.
_sgnd_menu_execute_itemExecute a registered menu item while allowing a host application to wrap- $1 — ITEM_KEY - Registered menu item key.—
_sgnd_console_dispatchResolve 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