Simplify helpers under line cap
This commit is contained in:
@@ -83,19 +83,20 @@ repeat_char() {
|
||||
}
|
||||
|
||||
term_width() {
|
||||
if [[ -n ${COLUMNS:-} ]]; then
|
||||
printf '%s\n' "${COLUMNS}"
|
||||
return
|
||||
fi
|
||||
if command_is_available tput; then
|
||||
tput cols 2>/dev/null && return
|
||||
fi
|
||||
[[ -n ${COLUMNS:-} ]] && { printf '%s\n' "${COLUMNS}"; return; }
|
||||
command_is_available tput && tput cols 2>/dev/null && return
|
||||
printf '80\n'
|
||||
}
|
||||
|
||||
use_box_ui() {
|
||||
[[ ${IPF_FORCE_PLAIN_UI} != 1 ]] || return 1
|
||||
[[ $(term_width) -ge 60 ]]
|
||||
[[ ${IPF_FORCE_PLAIN_UI} != 1 && $(term_width) -ge 60 ]]
|
||||
}
|
||||
|
||||
box_width() {
|
||||
local width
|
||||
width=$(term_width)
|
||||
(( width > 78 )) && width=78
|
||||
printf '%s\n' "${width}"
|
||||
}
|
||||
|
||||
pad_right() {
|
||||
@@ -111,20 +112,14 @@ pad_right() {
|
||||
printf '%s%*s' "${text}" "${padding}" ''
|
||||
}
|
||||
|
||||
box_top() {
|
||||
local width=${1:-60}
|
||||
printf '╔%s╗\n' "$(repeat_char '═' "$((width - 2))")"
|
||||
box_border() {
|
||||
local left=$1 right=$2 width=${3:-60}
|
||||
printf '%s%s%s\n' "${left}" "$(repeat_char '═' "$((width - 2))")" "${right}"
|
||||
}
|
||||
|
||||
box_bottom() {
|
||||
local width=${1:-60}
|
||||
printf '╚%s╝\n' "$(repeat_char '═' "$((width - 2))")"
|
||||
}
|
||||
|
||||
box_separator() {
|
||||
local width=${1:-60}
|
||||
printf '╠%s╣\n' "$(repeat_char '═' "$((width - 2))")"
|
||||
}
|
||||
box_top() { box_border '╔' '╗' "${1:-60}"; }
|
||||
box_bottom() { box_border '╚' '╝' "${1:-60}"; }
|
||||
box_separator() { box_border '╠' '╣' "${1:-60}"; }
|
||||
|
||||
box_line() {
|
||||
local width=${1:-60}
|
||||
@@ -134,19 +129,15 @@ box_line() {
|
||||
}
|
||||
|
||||
print_section() {
|
||||
local title=${1-}
|
||||
local title=${1-} width
|
||||
if use_box_ui; then
|
||||
local width
|
||||
width=$(term_width)
|
||||
if (( width > 78 )); then
|
||||
width=78
|
||||
fi
|
||||
width=$(box_width)
|
||||
box_top "${width}"
|
||||
box_line "${width}" "${title}"
|
||||
box_bottom "${width}"
|
||||
else
|
||||
printf '== %s ==\n' "${title}"
|
||||
return
|
||||
fi
|
||||
printf '== %s ==\n' "${title}"
|
||||
}
|
||||
|
||||
read_test_input() {
|
||||
@@ -181,7 +172,7 @@ prompt_input() {
|
||||
|
||||
if [[ -n ${default_value} ]]; then
|
||||
read -r -p "${prompt} [${default_value}]: " reply
|
||||
reply=${reply:-${default_value}}
|
||||
[[ -n ${reply} ]] || reply=${default_value}
|
||||
else
|
||||
read -r -p "${prompt}: " reply
|
||||
fi
|
||||
@@ -338,17 +329,11 @@ validate_port() {
|
||||
}
|
||||
|
||||
validate_proto() {
|
||||
case ${1-} in
|
||||
tcp|udp|both) return 0 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
[[ ${1-} =~ ^(tcp|udp|both)$ ]]
|
||||
}
|
||||
|
||||
validate_ipver() {
|
||||
case ${1-} in
|
||||
4|6|both) return 0 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
[[ ${1-} =~ ^(4|6|both)$ ]]
|
||||
}
|
||||
|
||||
require_root() {
|
||||
|
||||
Reference in New Issue
Block a user