File tree Expand file tree Collapse file tree 5 files changed +43
-11
lines changed Expand file tree Collapse file tree 5 files changed +43
-11
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,14 @@ git clone <repository-url>
2424cp -r bash-ui-lib/lib /path/to/your/project/
2525```
2626
27+ ## Requirements
28+
29+ - ** Interactive Terminal** : The library requires a TTY (interactive terminal) to function properly
30+ - ** Bash 4.0+** : Uses associative arrays and other modern bash features
31+ - ** Standard utilities** : ` tput ` , ` grep ` , ` sed ` (usually pre-installed)
32+
33+ ** Note** : The library will detect non-interactive terminals and exit gracefully with appropriate warnings.
34+
2735## Quick Start
2836
2937Here's a minimal example:
Original file line number Diff line number Diff line change @@ -137,13 +137,8 @@ _setup_default_dts_menu() {
137137# show_footer
138138# Show footer with actions using UI library
139139show_footer () {
140- # Check if footer is set up
141- if [[ " ${# UI_FOOTER_ACTIONS_KEYS[@]} " -eq 0 ]]; then
142- _setup_default_dts_footer
143- fi
144-
145- # Render footer using UI library
146- ui_render_footer
140+ # Render DTS-style footer directly (don't call ui_render_footer to avoid recursion)
141+ _setup_default_dts_footer
147142}
148143
149144# _setup_default_dts_footer
@@ -155,7 +150,13 @@ _setup_default_dts_footer() {
155150 echo -ne " ${RED}${POWEROFF_OPT_UP:- P}${NORMAL} to poweroff ${NORMAL} "
156151 echo -e " ${RED}${SHELL_OPT_UP:- S}${NORMAL} to enter shell ${NORMAL} "
157152
158- if systemctl is-active sshd.service > /dev/null 2>&1 ; then
153+ # Safely check SSH status - avoid segfault from systemctl issues
154+ local ssh_status=" inactive"
155+ if command -v systemctl & > /dev/null; then
156+ ssh_status=$( systemctl is-active sshd.service 2> /dev/null || echo " inactive" )
157+ fi
158+
159+ if [[ " $ssh_status " == " active" ]]; then
159160 echo -ne " ${RED}${SSH_OPT_UP:- K}${NORMAL} to stop SSH server ${NORMAL} "
160161 else
161162 echo -ne " ${RED}${SSH_OPT_UP:- K}${NORMAL} to launch SSH server ${NORMAL} "
Original file line number Diff line number Diff line change @@ -88,11 +88,18 @@ ui_set_post_render_callback() {
8888ui_read_input () {
8989 UI_INPUT=" "
9090
91+ # Check if terminal is interactive
92+ if ! [[ -t 0 ]]; then
93+ # Not interactive, exit the loop
94+ ui_exit 1
95+ return 1
96+ fi
97+
9198 if [[ " $UI_INPUT_MODE " == " single" ]]; then
92- read -r -n 1 UI_INPUT
99+ read -r -n 1 UI_INPUT || { ui_exit 1 ; return 1 ; }
93100 echo
94101 else
95- read -r UI_INPUT
102+ read -r UI_INPUT || { ui_exit 1 ; return 1 ; }
96103 fi
97104}
98105
Original file line number Diff line number Diff line change @@ -296,6 +296,11 @@ ui_render_screen() {
296296ui_handle_menu_selection () {
297297 local key=" $1 "
298298
299+ # Return early if key is empty or invalid
300+ if [[ -z " $key " ]]; then
301+ return 1
302+ fi
303+
299304 # Check if key exists in menu items
300305 if [[ -n " ${UI_MENU_ITEMS_HANDLER[$key]+isset} " ]]; then
301306 local condition=" ${UI_MENU_ITEMS_CONDITION[$key]} "
@@ -327,6 +332,11 @@ ui_handle_menu_selection() {
327332ui_handle_footer_selection () {
328333 local key=" $1 "
329334
335+ # Return early if key is empty or invalid
336+ if [[ -z " $key " ]]; then
337+ return 1
338+ fi
339+
330340 # Check if key exists in footer actions
331341 if [[ -n " ${UI_FOOTER_ACTIONS_HANDLER[$key]+isset} " ]]; then
332342 local condition=" ${UI_FOOTER_ACTIONS_CONDITION[$key]} "
Original file line number Diff line number Diff line change @@ -141,7 +141,13 @@ ui_confirm() {
141141# Pause and wait for user to press Enter
142142ui_pause () {
143143 local message=" ${1:- Press Enter to continue.} "
144- read -r -p " $message "
144+ # Check if stdin is available and terminal is interactive
145+ if [[ -t 0 ]]; then
146+ read -r -p " $message " || true
147+ else
148+ # Non-interactive, just print message and return
149+ echo " $message "
150+ fi
145151}
146152
147153# ui_wait_seconds <seconds> [message]
You can’t perform that action at this time.
0 commit comments