Fix: Simplify input prompts in setup script

Reverts input functions to a simpler model by separating the
`echo` of the prompt from the `read` command itself.
This avoids using `read -p` with complex, colorized prompt strings,
which can sometimes cause issues in specific terminal emulators or
compatibility layers like those found in MobaXterm.

This change aims to improve robustness of input handling by:
1. Using `echo -e -n` for displaying the prompt with colors.
2. Using a plain `read` or `read -s` for capturing user input.

This is a further attempt to resolve issues where users might be
unable to type or paste into prompts within the MobaXterm environment.
This commit is contained in:
google-labs-jules[bot]
2025-06-20 09:42:11 +00:00
parent 3d433ba1d7
commit 9ab6fd5a44

View File

@@ -77,36 +77,17 @@ _prompt_user() {
local prompt_message="$1"
local var_name="$2"
local default_value="${3:-}"
local current_value="${!var_name:-$default_value}" # Not used currently, but good for reference
local input
local read_target_set_internally=false
# Check if stdin (fd 0) is a terminal
if ! [ -t 0 ]; then
# If stdin is not a terminal, check if /dev/tty is available
if [ -c /dev/tty ]; then
read_target_set_internally=true
else
_print_msg error "Cannot read user input: No TTY available. stdin is not a terminal and /dev/tty is not accessible."
# Exiting because user input is critical for this script.
# Alternatively, could return an error code: return 1
exit 1
fi
# Echo the prompt using color codes
if [ -n "$default_value" ]; then
echo -e -n "${YELLOW}${prompt_message}${NC} [Default: $default_value]: "
else
echo -e -n "${YELLOW}${prompt_message}${NC}: "
fi
if [ -n "$default_value" ]; then
if $read_target_set_internally; then
read -p "$(echo -e "${YELLOW}$prompt_message${NC} [Default: $default_value]: ")" input < /dev/tty
else
read -p "$(echo -e "${YELLOW}$prompt_message${NC} [Default: $default_value]: ")" input
fi
else
if $read_target_set_internally; then
read -p "$(echo -e "${YELLOW}$prompt_message${NC}: ")" input < /dev/tty
else
read -p "$(echo -e "${YELLOW}$prompt_message${NC}: ")" input
fi
fi
# Read the input
read input
if [ -z "$input" ] && [ -n "$default_value" ]; then
eval "$var_name=\"$default_value\""
@@ -120,26 +101,13 @@ _prompt_user_sensitive() {
local var_name="$2"
local input
local read_target_set_internally=false
# Check if stdin (fd 0) is a terminal
if ! [ -t 0 ]; then
# If stdin is not a terminal, check if /dev/tty is available
if [ -c /dev/tty ]; then
read_target_set_internally=true
else
_print_msg error "Cannot read sensitive user input: No TTY available. stdin is not a terminal and /dev/tty is not accessible."
# Exiting because user input is critical for this script.
# Alternatively, could return an error code: return 1
exit 1
fi
fi
# Echo the prompt using color codes
echo -e -n "${YELLOW}${prompt_message}${NC}: "
if $read_target_set_internally; then
read -sp "$(echo -e "${YELLOW}$prompt_message${NC}: ")" input < /dev/tty
else
read -sp "$(echo -e "${YELLOW}$prompt_message${NC}: ")" input
fi
# Read the input silently
read -s input
echo # Newline after sensitive input
eval "$var_name=\"$input\""
}