Try printing modules in two columns

This commit is contained in:
2024-08-04 00:53:50 -04:00
parent 7e3c9909ef
commit 5c1ea83ef0

View File

@@ -411,15 +411,38 @@ interactive_header() {
# echo ""
echo "Available Submodules:"
# Determine if we need two columns
if [ ${#ALL_SUBMODULES[@]} -gt 8 ]; then
# Calculate the number of elements in each column
num_columns=$(( (${#ALL_SUBMODULES[@]} + 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_SUBMODULES[i]}" ]]; then
item_length=${#ALL_SUBMODULES[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
printf "%d. %s" $((i+1)) "${ALL_SUBMODULES[i]}"
if [ $((i + num_columns)) -lt ${#ALL_SUBMODULES[@]} ]; then
printf "\t\t\t%d. %s\n" $((i + num_columns + 1)) "${ALL_SUBMODULES[i + num_columns]}"
# Print the first column
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
printf "\t%d. %s\n" $((i + num_columns + 1)) "${ALL_SUBMODULES[i + num_columns]}"
else
# Print a newline if no second column item
echo
fi
done
@@ -430,6 +453,25 @@ 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 ""