Simplify helpers under line cap

This commit is contained in:
2026-04-17 11:33:45 +08:00
parent 4c431584eb
commit af871a67a3
5 changed files with 87 additions and 168 deletions

View File

@@ -46,6 +46,15 @@ usage() {
USAGE
}
MENU_LINES=(
'[1] 查看所有转发规则'
'[2] 添加新的转发规则'
'[3] 删除现有转发规则'
'[4] 查看系统环境状态'
'[5] 立即保存到磁盘'
'[0] 退出'
)
bootstrap() {
if [[ ${IPF_SKIP_ENV_CHECK} != 1 ]]; then
env_check_all
@@ -54,7 +63,7 @@ bootstrap() {
}
render_main_menu() {
local status persist count width
local status persist count width line
status=$(env_status_summary)
count=$(storage_count)
if persist_available; then
@@ -64,31 +73,20 @@ render_main_menu() {
fi
if use_box_ui; then
width=$(term_width)
if (( width > 78 )); then
width=78
fi
width=$(box_width)
box_top "${width}"
box_line "${width}" "${IPF_APP_NAME}"
box_separator "${width}"
box_line "${width}" "状态: ${status} 规则数: ${count} 持久化: ${persist}"
box_separator "${width}"
box_line "${width}" '[1] 查看所有转发规则'
box_line "${width}" '[2] 添加新的转发规则'
box_line "${width}" '[3] 删除现有转发规则'
box_line "${width}" '[4] 查看系统环境状态'
box_line "${width}" '[5] 立即保存到磁盘'
box_line "${width}" '[0] 退出'
for line in "${MENU_LINES[@]}"; do
box_line "${width}" "${line}"
done
box_bottom "${width}"
else
printf '%s\n' "${IPF_APP_NAME}"
printf '状态: %s | 规则数: %s | 持久化: %s\n' "${status}" "${count}" "${persist}"
printf '[1] 查看所有转发规则\n'
printf '[2] 添加新的转发规则\n'
printf '[3] 删除现有转发规则\n'
printf '[4] 查看系统环境状态\n'
printf '[5] 立即保存到磁盘\n'
printf '[0] 退出\n'
printf '%s\n' "${MENU_LINES[@]}"
fi
}