Add interactive menu regression

This commit is contained in:
2026-04-17 11:09:25 +08:00
parent b5ae4a5668
commit 7b854c7a96
8 changed files with 114 additions and 18 deletions

View File

@@ -216,7 +216,8 @@ cmd_add() {
local proto_choice ipver_choice proto ipver lport tip tport desc
print_section '添加新的转发规则'
proto_choice=$(prompt_select '请选择协议' 'TCP' 'UDP' 'TCP + UDP')
prompt_select_capture '请选择协议' 'TCP' 'UDP' 'TCP + UDP'
proto_choice=${PROMPT_SELECT_RESULT}
case ${proto_choice} in
0) proto=tcp ;;
1) proto=udp ;;
@@ -225,12 +226,14 @@ cmd_add() {
esac
while true; do
lport=$(prompt_input '请输入本地监听端口' '')
prompt_input_capture '请输入本地监听端口' ''
lport=${PROMPT_INPUT_RESULT}
validate_port "${lport}" && break
log_warn '端口无效,请重新输入。'
done
ipver_choice=$(prompt_select '请选择 IP 版本' '仅 IPv4' '仅 IPv6' '同时 IPv4 + IPv6')
prompt_select_capture '请选择 IP 版本' '仅 IPv4' '仅 IPv6' '同时 IPv4 + IPv6'
ipver_choice=${PROMPT_SELECT_RESULT}
case ${ipver_choice} in
0) ipver=4 ;;
1) ipver=6 ;;
@@ -239,18 +242,21 @@ cmd_add() {
esac
while true; do
tip=$(prompt_input "$(rule_target_hint "${ipver}")" '')
prompt_input_capture "$(rule_target_hint "${ipver}")" ''
tip=${PROMPT_INPUT_RESULT}
rule_validate_target "${tip}" "${ipver}" && break
log_warn '目标地址无效,请重新输入。'
done
while true; do
tport=$(prompt_input '请输入目标端口' '')
prompt_input_capture '请输入目标端口' ''
tport=${PROMPT_INPUT_RESULT}
validate_port "${tport}" && break
log_warn '目标端口无效,请重新输入。'
done
desc=$(prompt_input '请输入描述(可留空)' '')
prompt_input_capture '请输入描述(可留空)' ''
desc=${PROMPT_INPUT_RESULT}
desc=$(rule_sanitize_desc "${desc}")
printf '协议: %s\n' "$(rule_proto_label "${proto}")"
@@ -319,7 +325,8 @@ cmd_delete() {
cmd_list 0
while true; do
answer=$(prompt_input '请输入要删除的规则编号' '')
prompt_input_capture '请输入要删除的规则编号' ''
answer=${PROMPT_INPUT_RESULT}
if [[ ${answer} =~ ^[0-9]+$ ]] && (( answer >= 1 && answer <= ${#RULES_CACHE[@]} )); then
index=$((answer - 1))
break