### Bash List Selection Prompt Renders a text-based list of options for single selection. Users navigate with arrow keys and confirm with Enter. The 'list' function takes a prompt message and an array of options, returning the 0-based index of the selected item. ```bash options=("one" "two" "three" "four") option=$(list "Select one item" "${options[@]}") echo "Your choice: ${options[$option]}" ``` -------------------------------- ### Bash Editor Prompt Opens the default text editor (or 'vi' as a fallback) for multi-line text input. The 'editor' function captures the content written by the user and returns it as a string. ```bash # Open default editor text=$(editor "Please enter something in the editor") echo -e "You wrote:\n${text}" ``` -------------------------------- ### Log Message with Level and Color (Bash) Logs a message to standard output with a specified numeric log level and ANSI color codes. It respects the global `LOG_LEVEL` variable, defaulting to 'INFO' if not set. Messages are only displayed if their level meets or exceeds the current `LOG_LEVEL`. ```bash # Log a message on info level log "$LOG_INFO" "this is a info message" log "LOG_DEBUG" "i am only visible when $LOG_LEVEL is debug" ``` -------------------------------- ### Bash Checkbox Prompt Allows users to select multiple options from a text-based list. Similar to 'list', but supports multi-selection using arrow keys and Enter. The 'checkbox' function returns a string representing the selected indices. ```bash options=("one" "two" "three" "four") checked=$(checkbox "Select one or more items" "${options[@]}") echo "Your choices: ${checked}" ``` -------------------------------- ### Bash Text Input Prompt Prompts the user for text input. Can be used with or without validation. The 'input' function displays a prompt and captures user-entered text. The 'with_validate' function can be combined with a validation function like 'validate_present' to ensure input is not empty. ```bash # Raw input without validation text=$(input "Please enter something and confirm with enter") # Input with validation text=$(with_validate 'input "Please enter at least one character and confirm with enter"' validate_present) ``` -------------------------------- ### Bash Confirmation Prompt Displays a yes/no confirmation dialog. The 'confirm' function prompts the user with a given message. It returns '0' for 'no' and '1' for 'yes' on standard output, allowing for conditional logic in scripts. ```bash confirmed=$(confirm "Should it be?") if [ "$confirmed" = "0" ]; then echo "No?"; else echo "Yes!"; fi ``` -------------------------------- ### Bash Range Selection Prompt Presents a numerical range selection interface. Users can increment or decrement the value using arrow keys. The 'range' function takes a prompt, minimum, default, and maximum values, returning the selected number. ```bash # Range with negative min value value=$(range "Pick a number" -5 0 5) ``` -------------------------------- ### Bash Input Validation Prompt Evaluates a prompt command repeatedly until a validation function returns successfully (exit code 0). The 'with_validate' function is versatile, allowing integration with built-in validators like 'validate_present' or custom validation logic. ```bash # Using builtin is present validator text=$(with_validate 'input "Please enter something and confirm with enter"' validate_present) # Using custom validator e.g. for password validate_password() { if [ ${#1} -lt 10 ];then echo "Password needs to be at least 10 characters"; exit 1; fi } pass=$(with_validate 'password "Enter random password"' validate_password) ``` -------------------------------- ### Display Success Message in Bash The show_success function displays a given success message to standard error. It is prefixed with a specific emoji to visually indicate success. This function is ideal for confirming the completion of a task. ```bash show_success "There it is! World peace." ``` -------------------------------- ### Bash Password Input Prompt Provides a secure password input field that masks characters with asterisks. Supports optional validation using the 'with_validate' function. The 'password' function captures the entered password. ```bash # Password prompt with custom validation validate_password() { if [ ${#1} -lt 10 ];then echo "Password needs to be at least 10 characters"; exit 1; fi } pass=$(with_validate 'password "Enter random password"' validate_password) # Password ith no validation pass=$(password "Enter password to use") ``` -------------------------------- ### Parse Log Level from Text (Bash) Parses a text representation of a log level (e.g., 'info', 'ERROR') into its corresponding numeric value. This function is essential for setting and managing the script's logging verbosity. It handles both lowercase and uppercase input. ```bash # Parse lower case log level parse_log_level "info" # Parse upper case log level parse_log_level "ERROR" ``` -------------------------------- ### Bash Presence Validation Function A built-in validation function that checks if a prompt returned any input. 'validate_present' returns an exit code of 0 if the input string has at least one character, and 1 otherwise. It's commonly used with 'with_validate' for required fields. ```bash # text input with validation text=$(with_validate 'input "Please enter something and confirm with enter"' validate_present) ``` -------------------------------- ### Display Error Message in Bash The show_error function displays a given error message to standard error. It is prefixed with a specific emoji to visually indicate an error. This function is useful for providing immediate feedback on failed operations. ```bash show_error "Oh snap, that went horribly wrong" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.