更新dispHelp文件

从固定宽度显示改变为按单词分割显示
This commit is contained in:
张壹 2018-09-29 22:28:38 +08:00
parent b1b52bbb81
commit 2cb99ae1aa

View File

@ -1,92 +1,196 @@
#!/bin/bash #!/bin/bash
# 一些输出帮助文档的函数 # 一些输出帮助文档的函数
# 显示命令简介 两个参数 命令名称 命令简介 # 显示命令简介 两个参数 命令名称 命令简介
#function dispTitle(){
# winWidth=`tput cols`
#
# cutLength=`expr ${winWidth} - 19`
# segment=${2:0:${cutLength}}
# printf "%s\n%-10s%s\n" "${1}" " " "${segment}"
#
# times=1
# while (( ${#segment} == ${cutLength} ))
# do
# st=`expr ${cutLength} \* ${times}`
# segment=${2:${st}:${cutLength}}
# printf "%-10s%s\n" " " "${segment}"
# times=`expr ${times} + 1`
# done
# printf "\n"
#}
function dispTitle(){ function dispTitle(){
winWidth=`tput cols` winWidth=`tput cols`
message=${2}
cutLength=`expr ${winWidth} - 19` printf "%s\n%-9s" "${1}"
segment=${2:0:${cutLength}}
printf "%s\n%-10s%s\n" "${1}" " " "${segment}"
times=1 head_length=19
while (( ${#segment} == ${cutLength} )) print_length=${head_length}
do for segment in ${message[@]}; do
st=`expr ${cutLength} \* ${times}` print_length=`expr ${print_length} + ${#segment} + 1`
segment=${2:${st}:${cutLength}} if [[ ${print_length} -le ${winWidth} ]]; then
printf "%-10s%s\n" " " "${segment}" printf " %s" "${segment}"
times=`expr ${times} + 1` else
print_length=`expr ${head_length} + ${#segment} + 1`
printf "\n%-10s%s" " " "${segment}"
fi
done done
printf "\n" printf "\n\n"
} }
# 显示作者信息 一个参数 作者信息 # 显示作者信息 一个参数 作者信息
#function dispAuthorInfo(){
# winWidth=`tput cols`
#
# cutLength=`expr ${winWidth} - 19`
# segment=${1:0:${cutLength}}
#
# printf "%-10s%s\n" "Author:" "${segment}"
#
# times=1
# while (( ${#segment} == ${cutLength} ))
# do
# st=`expr ${cutLength} \* ${times}`
# segment=${1:${st}:${cutLength}}
# printf "%-10s%s\n" " " "${segment}"
# times=`expr ${times} + 1`
# done
# printf "\n"
#}
function dispAuthorInfo(){ function dispAuthorInfo(){
winWidth=`tput cols` winWidth=`tput cols`
message=${1}
cutLength=`expr ${winWidth} - 19` printf "%-9s" "Author:"
segment=${1:0:${cutLength}}
printf "%-10s%s\n" "Author:" "${segment}" head_length=19
print_length=${head_length}
for segment in ${message[@]}; do
print_length=`expr ${print_length} + ${#segment} + 1`
if [[ ${print_length} -le ${winWidth} ]]; then
printf " %s" "${segment}"
else
print_length=`expr ${head_length} + ${#segment} + 1`
printf "\n%-10s%s" " " "${segment}"
fi
done
printf "\n\n"
}
times=1 # 显示用法 一个参数 做法信息
while (( ${#segment} == ${cutLength} )) #function dispUsage(){
do # winWidth=`tput cols`
st=`expr ${cutLength} \* ${times}` #
segment=${1:${st}:${cutLength}} # cutLength=`expr ${winWidth} - 19`
printf "%-10s%s\n" " " "${segment}" # segment=${1:0:${cutLength}}
times=`expr ${times} + 1` #
# printf "%-10s%s\n" "Usage:" "${segment}"
#
# times=1
# while (( ${#segment} == ${cutLength} ))
# do
# st=`expr ${cutLength} \* ${times}`
# segment=${1:${st}:${cutLength}}
# printf "%-10s%s\n" " " "${segment}"
# times=`expr ${times} + 1`
# done
# printf "\nOptions:\n"
#}
function dispUsage(){
winWidth=`tput cols`
message=${1}
printf "%-9s" "Usage:"
head_length=19
print_length=${head_length}
for segment in ${message[@]}; do
print_length=`expr ${print_length} + ${#segment} + 1`
if [[ ${print_length} -le ${winWidth} ]]; then
printf " %s" "${segment}"
else
print_length=`expr ${head_length} + ${#segment} + 1`
printf "\n%-10s%s" " " "${segment}"
fi
done
printf "\n\n"
}
# 短命令说明 两个参数 命令符号 命令说明
#function dispOptionShort(){
# winWidth=`tput cols`
#
# cutLength=`expr ${winWidth} - 19`
# segment=${2:0:${cutLength}}
# printf "%-4s%-6s%s\n" " " "${1}" "${segment}"
#
# times=1
# while (( ${#segment} == ${cutLength} ))
# do
# st=`expr ${cutLength} \* ${times}`
# segment=${2:${st}:${cutLength}}
# printf "%-10s%s\n" " " "${segment}"
# times=`expr ${times} + 1`
# done
#}
function dispOptionShort(){
winWidth=`tput cols`
message=${2}
printf "%-4s%-5s" " " "${1}"
head_length=19
print_length=${head_length}
for segment in ${message[@]}; do
print_length=`expr ${print_length} + ${#segment} + 1`
if [[ ${print_length} -le ${winWidth} ]]; then
printf " %s" "${segment}"
else
print_length=`expr ${head_length} + ${#segment} + 1`
printf "\n%-10s%s" " " "${segment}"
fi
done done
printf "\n" printf "\n"
} }
# 显示用法 一个参数 做法信息
function dispUsage(){
winWidth=`tput cols`
cutLength=`expr ${winWidth} - 19`
segment=${1:0:${cutLength}}
printf "%-10s%s\n" "Usage:" "${segment}"
times=1
while (( ${#segment} == ${cutLength} ))
do
st=`expr ${cutLength} \* ${times}`
segment=${1:${st}:${cutLength}}
printf "%-10s%s\n" " " "${segment}"
times=`expr ${times} + 1`
done
printf "\nOptions:\n"
}
# 短命令说明 两个参数 命令符号 命令说明
function dispOptionShort(){
winWidth=`tput cols`
cutLength=`expr ${winWidth} - 19`
segment=${2:0:${cutLength}}
printf "%-4s%-6s%s\n" " " "${1}" "${segment}"
times=1
while (( ${#segment} == ${cutLength} ))
do
st=`expr ${cutLength} \* ${times}`
segment=${2:${st}:${cutLength}}
printf "%-10s%s\n" " " "${segment}"
times=`expr ${times} + 1`
done
}
# 长命令说明 三个参数 短命令符号 长命令符号 命令说明 # 长命令说明 三个参数 短命令符号 长命令符号 命令说明
#function dispOptionLong(){
# winWidth=`tput cols`
#
# cutLength=`expr ${winWidth} - 32`
# segment=${3:0:${cutLength}}
# printf "%-4s%-6s%-12s%s\n" " " "${1}" "${2}" "${segment}"
#
# times=1
# while (( ${#segment} == ${cutLength} ))
# do
# st=`expr ${cutLength} \* ${times}`
# segment=${3:${st}:${cutLength}}
# printf "%-22s%s\n" " " "${segment}"
# times=`expr ${times} + 1`
# done
#}
function dispOptionLong(){ function dispOptionLong(){
winWidth=`tput cols` winWidth=`tput cols`
message=${3}
cutLength=`expr ${winWidth} - 32` printf "%-4s%-6s%-11s" " " "${1}" "${2}"
segment=${3:0:${cutLength}}
printf "%-4s%-6s%-12s%s\n" " " "${1}" "${2}" "${segment}"
times=1 head_length=32
while (( ${#segment} == ${cutLength} )) print_length=${head_length}
do for segment in ${message[@]}; do
st=`expr ${cutLength} \* ${times}` print_length=`expr ${print_length} + ${#segment} + 1`
segment=${3:${st}:${cutLength}} if [[ ${print_length} -le ${winWidth} ]]; then
printf "%-22s%s\n" " " "${segment}" printf " %s" "${segment}"
times=`expr ${times} + 1` else
print_length=`expr ${head_length} + ${#segment} + 1`
printf "\n%-22s%s" " " "${segment}"
fi
done done
printf "\n"
} }