Add interactive menu regression
This commit is contained in:
@@ -150,17 +150,16 @@ print_section() {
|
||||
}
|
||||
|
||||
read_test_input() {
|
||||
local reply=''
|
||||
READ_TEST_INPUT_RESULT=''
|
||||
if [[ -n ${IPF_TEST_INPUTS-} ]]; then
|
||||
if [[ ${IPF_TEST_INPUTS} == *$'\n'* ]]; then
|
||||
reply=${IPF_TEST_INPUTS%%$'\n'*}
|
||||
READ_TEST_INPUT_RESULT=${IPF_TEST_INPUTS%%$'\n'*}
|
||||
IPF_TEST_INPUTS=${IPF_TEST_INPUTS#*$'\n'}
|
||||
else
|
||||
reply=${IPF_TEST_INPUTS}
|
||||
READ_TEST_INPUT_RESULT=${IPF_TEST_INPUTS}
|
||||
IPF_TEST_INPUTS=''
|
||||
fi
|
||||
fi
|
||||
printf '%s' "${reply}"
|
||||
}
|
||||
|
||||
prompt_input() {
|
||||
@@ -169,10 +168,12 @@ prompt_input() {
|
||||
local reply=''
|
||||
|
||||
if [[ -n ${IPF_TEST_INPUTS-} ]]; then
|
||||
reply=$(read_test_input)
|
||||
read_test_input
|
||||
reply=${READ_TEST_INPUT_RESULT}
|
||||
if [[ -z ${reply} && -n ${default_value} ]]; then
|
||||
reply=${default_value}
|
||||
fi
|
||||
PROMPT_INPUT_RESULT=${reply}
|
||||
printf '%s\n' "${reply}" >&2
|
||||
printf '%s\n' "${reply}"
|
||||
return 0
|
||||
@@ -184,9 +185,14 @@ prompt_input() {
|
||||
else
|
||||
read -r -p "${prompt}: " reply
|
||||
fi
|
||||
PROMPT_INPUT_RESULT=${reply}
|
||||
printf '%s\n' "${reply}"
|
||||
}
|
||||
|
||||
prompt_input_capture() {
|
||||
prompt_input "$@" >/dev/null
|
||||
}
|
||||
|
||||
prompt_confirm() {
|
||||
local prompt=$1
|
||||
local default_choice=${2:-n}
|
||||
@@ -198,7 +204,8 @@ prompt_confirm() {
|
||||
suffix='[y/N]'
|
||||
fi
|
||||
|
||||
answer=$(prompt_input "${prompt} ${suffix}" "")
|
||||
prompt_input_capture "${prompt} ${suffix}" ""
|
||||
answer=${PROMPT_INPUT_RESULT}
|
||||
if [[ -z ${answer} ]]; then
|
||||
answer=${default_choice}
|
||||
fi
|
||||
@@ -218,15 +225,21 @@ prompt_select() {
|
||||
done
|
||||
|
||||
while true; do
|
||||
answer=$(prompt_input "${prompt}" "")
|
||||
prompt_input_capture "${prompt}" ""
|
||||
answer=${PROMPT_INPUT_RESULT}
|
||||
if [[ ${answer} =~ ^[0-9]+$ ]] && (( answer >= 1 && answer <= count )); then
|
||||
printf '%s\n' "$((answer - 1))"
|
||||
PROMPT_SELECT_RESULT=$((answer - 1))
|
||||
printf '%s\n' "${PROMPT_SELECT_RESULT}"
|
||||
return 0
|
||||
fi
|
||||
log_warn "请输入 1-${count} 之间的编号。"
|
||||
done
|
||||
}
|
||||
|
||||
prompt_select_capture() {
|
||||
prompt_select "$@" >/dev/null
|
||||
}
|
||||
|
||||
pause_return() {
|
||||
if [[ -n ${IPF_TEST_INPUTS-} ]]; then
|
||||
return 0
|
||||
@@ -272,7 +285,7 @@ _validate_ipv6_part_count() {
|
||||
continue
|
||||
fi
|
||||
[[ ${field} =~ ^[0-9A-Fa-f]{1,4}$ ]] || return 1
|
||||
((count++))
|
||||
((count += 1))
|
||||
done
|
||||
|
||||
printf '%s\n' "${count}"
|
||||
|
||||
Reference in New Issue
Block a user