diff --git a/scripts/menu.sh b/scripts/menu.sh index 138da872..d3db9dce 100644 --- a/scripts/menu.sh +++ b/scripts/menu.sh @@ -19,6 +19,7 @@ CFG_PATH="$CRASHDIR"/configs/ShellCrash.cfg . "$CRASHDIR"/libs/i18n.sh . "$CRASHDIR"/menus/1_start.sh . "$CRASHDIR"/menus/running_status.sh +# . "$CRASHDIR"/menus/tui_layout.sh # 加载语言 load_lang common diff --git a/scripts/menus/tui_layout.sh b/scripts/menus/tui_layout.sh new file mode 100644 index 00000000..aa0d39b4 --- /dev/null +++ b/scripts/menus/tui_layout.sh @@ -0,0 +1,50 @@ +# tui/layout.sh +# Terminal UI layout helpers +# Provides menu/table formatting utilities + + +# set the total width of the menu +# (adjusting this number will automatically change the entire menu, including the separator lines) +# note: The number represents the number of columns that appear when the "||" appears on the right +TABLE_WIDTH=60 + +# define two extra-long template strings in advance +# (the length should be greater than the expected TABLE_WIDTH) +FULL_EQ="====================================================================================================" +FULL_DASH="- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " + +# function to print content lines +# (using cursor jump) +content_line() { + echo -e " ${1}\033[${TABLE_WIDTH}G||" +} + +# function to print sub content lines +# for printing accompanying instructions +sub_content_line() { + echo -e " ${1}\033[${TABLE_WIDTH}G||" + content_line +} + +# increase the spacing between the front +# and back forms to improve readability +double_line_break() { + printf "\n\n" +} + +# function to print separators +# (using string slicing) +# parameter $1: pass in "=" or "-" +separator_line() { + local separator_type="$1" + local output_line="" + local len=$((TABLE_WIDTH - 1)) + + if [ "$separator_type" == "=" ]; then + output_line="${FULL_EQ:0:$len}" + else + output_line="${FULL_DASH:0:$len}" + fi + + echo "${output_line}||" +}