Use two columns for three header entries
This commit is contained in:
@@ -387,11 +387,37 @@ interactive_header() {
|
||||
echo ""
|
||||
|
||||
echo "Available Modules:"
|
||||
if [ ${#ALL_MODULES[@]} -gt 8 ]; then
|
||||
# Determine if we need two columns
|
||||
if [[ ${#ALL_MODULES[@]} -gt 8 ]]; then
|
||||
# Calculate the number of elements in each column
|
||||
num_columns=$(( (${#ALL_MODULES[@]} + 1) / 2 ))
|
||||
|
||||
# Determine the maximum width of the first column
|
||||
max_width=0
|
||||
for ((i=0; i<num_columns; i++)); do
|
||||
# Check if the item exists
|
||||
if [[ -n "${ALL_MODULES[i]}" ]]; then
|
||||
item_length=${#ALL_MODULES[i]}
|
||||
if [[ $item_length -gt $max_width ]]; then
|
||||
max_width=$item_length
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Print in two columns
|
||||
for ((i=0; i<${#ALL_MODULES[@]}; i++)); do
|
||||
printf "%d. %s\t" $((i+1)) "${ALL_MODULES[i]}"
|
||||
if [ $((i % 2)) -eq 1 ]; then
|
||||
for ((i=0; i<num_columns; i++)); do
|
||||
# Print the first column
|
||||
if [[ -n "${ALL_MODULES[i]}" ]]; then
|
||||
printf "%d. %-${max_width}s" $((i+1)) "${ALL_MODULES[i]}"
|
||||
else
|
||||
printf "%${max_width}s" ""
|
||||
fi
|
||||
|
||||
# Print the second column if it exists
|
||||
if [[ $((i + num_columns)) -lt ${#ALL_MODULES[@]} ]]; then
|
||||
printf "\t%d. %s\n" $((i + num_columns + 1)) "${ALL_MODULES[i + num_columns]}"
|
||||
else
|
||||
# Print a newline if no second column item
|
||||
echo
|
||||
fi
|
||||
done
|
||||
@@ -403,17 +429,9 @@ interactive_header() {
|
||||
fi
|
||||
echo ""
|
||||
|
||||
|
||||
# # Print the array with item numbers in two columns
|
||||
# for ((i=0; i<${#ALL_MODULES[@]}; i++)); do
|
||||
# printf "%d\t%s\n" $((i+1)) "${ALL_MODULES[i]}"
|
||||
# done | column -t -s $'\t'
|
||||
# echo ""
|
||||
|
||||
echo "Available Submodules:"
|
||||
|
||||
# Determine if we need two columns
|
||||
if [ ${#ALL_SUBMODULES[@]} -gt 8 ]; then
|
||||
if [[ ${#ALL_SUBMODULES[@]} -gt 8 ]]; then
|
||||
# Calculate the number of elements in each column
|
||||
num_columns=$(( (${#ALL_SUBMODULES[@]} + 1) / 2 ))
|
||||
|
||||
@@ -432,14 +450,14 @@ interactive_header() {
|
||||
# Print in two columns
|
||||
for ((i=0; i<num_columns; i++)); do
|
||||
# Print the first column
|
||||
if [ -n "${ALL_SUBMODULES[i]}" ]; then
|
||||
if [[ -n "${ALL_SUBMODULES[i]}" ]]; then
|
||||
printf "%d. %-${max_width}s" $((i+1)) "${ALL_SUBMODULES[i]}"
|
||||
else
|
||||
printf "%${max_width}s" ""
|
||||
fi
|
||||
|
||||
# Print the second column if it exists
|
||||
if [ $((i + num_columns)) -lt ${#ALL_SUBMODULES[@]} ]; then
|
||||
if [[ $((i + num_columns)) -lt ${#ALL_SUBMODULES[@]} ]]; then
|
||||
printf "\t%d. %s\n" $((i + num_columns + 1)) "${ALL_SUBMODULES[i + num_columns]}"
|
||||
else
|
||||
# Print a newline if no second column item
|
||||
@@ -453,58 +471,8 @@ interactive_header() {
|
||||
done
|
||||
fi
|
||||
echo ""
|
||||
# if [ ${#ALL_SUBMODULES[@]} -gt 8 ]; then
|
||||
# # Calculate the number of elements in each column
|
||||
# num_columns=$(( (${#ALL_SUBMODULES[@]} + 1) / 2 ))
|
||||
# # Print in two columns
|
||||
# for ((i=0; i<num_columns; i++)); do
|
||||
# printf "%d. %s" $((i+1)) "${ALL_SUBMODULES[i]}"
|
||||
# if [ $((i + num_columns)) -lt ${#ALL_SUBMODULES[@]} ]; then
|
||||
# printf "\t\t%d. %s\n" $((i + num_columns + 1)) "${ALL_SUBMODULES[i + num_columns]}"
|
||||
# else
|
||||
# echo
|
||||
# fi
|
||||
# done
|
||||
# else
|
||||
# # Print in a single column
|
||||
# for ((i=0; i<${#ALL_SUBMODULES[@]}; i++)); do
|
||||
# printf "%d. %s\n" $((i+1)) "${ALL_SUBMODULES[i]}"
|
||||
# done
|
||||
# fi
|
||||
# echo ""
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# if [ ${#ALL_SUBMODULES[@]} -gt 8 ]; then
|
||||
# # Print in two columns
|
||||
# for ((i=0; i<${#ALL_SUBMODULES[@]}; i++)); do
|
||||
# printf "%d. %s\t" $((i+1)) "${ALL_SUBMODULES[i]}"
|
||||
# if [ $((i % 2)) -eq 1 ]; then
|
||||
# echo
|
||||
# fi
|
||||
# done
|
||||
# else
|
||||
# # Print in a single column
|
||||
# for ((i=0; i<${#ALL_SUBMODULES[@]}; i++)); do
|
||||
# printf "%d. %s\n" $((i+1)) "${ALL_SUBMODULES[i]}"
|
||||
# done
|
||||
# fi
|
||||
echo ""
|
||||
# for i in "${!ALL_SUBMODULES[@]}"; do
|
||||
# printf "%d. %s\n" "$((i+1))" "${ALL_SUBMODULES[i]}"
|
||||
# done
|
||||
# echo ""
|
||||
|
||||
# Gather and list projects from SCANS_DIR
|
||||
shopt -s nullglob
|
||||
projects=("$SCANS_DIR"/*/)
|
||||
@@ -517,12 +485,48 @@ interactive_header() {
|
||||
echo "Available Projects:"
|
||||
projects=("${projects[@]%/}") # strip comma first!
|
||||
projects=("${projects[@]##*/}")
|
||||
for i in "${!projects[@]}"; do
|
||||
printf "%d. %s\n" "$((i+1))" "${projects[i]}"
|
||||
|
||||
# Determine if we need two columns
|
||||
if [[ ${#projects[@]} -gt 8 ]]; then
|
||||
# Calculate the number of elements in each column
|
||||
num_columns=$(( (${#projects[@]} + 1) / 2 ))
|
||||
|
||||
# Determine the maximum width of the first column
|
||||
max_width=0
|
||||
for ((i=0; i<num_columns; i++)); do
|
||||
# Check if the item exists
|
||||
if [[ -n "${projects[i]}" ]]; then
|
||||
item_length=${#projects[i]}
|
||||
if [[ $item_length -gt $max_width ]]; then
|
||||
max_width=$item_length
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Print in two columns
|
||||
for ((i=0; i<num_columns; i++)); do
|
||||
# Print the first column
|
||||
if [[ -n "${projects[i]}" ]]; then
|
||||
printf "%d. %-${max_width}s" $((i+1)) "${projects[i]}"
|
||||
else
|
||||
printf "%${max_width}s" ""
|
||||
fi
|
||||
|
||||
# Print the second column if it exists
|
||||
if [[ $((i + num_columns)) -lt ${#projects[@]} ]]; then
|
||||
printf "\t%d. %s\n" $((i + num_columns + 1)) "${projects[i + num_columns]}"
|
||||
else
|
||||
# Print a newline if no second column item
|
||||
echo
|
||||
fi
|
||||
done
|
||||
else
|
||||
# Print in a single column
|
||||
for ((i=0; i<${#projects[@]}; i++)); do
|
||||
printf "%d. %s\n" $((i+1)) "${projects[i]}"
|
||||
done
|
||||
fi
|
||||
echo ""
|
||||
|
||||
fi
|
||||
# Let user choose or add project(s)
|
||||
if [[ -z ${PROJECTS[*]} ]]; then
|
||||
num=$((${#projects[@]}))
|
||||
|
||||
Reference in New Issue
Block a user