mirror of
https://github.com/juewuy/ShellCrash.git
synced 2026-03-10 23:41:22 +00:00
Merge pull request #1139 from sofia-riese/patch-5
feat(tui): add layout utilities for terminal UI formatting
This commit is contained in:
@@ -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
|
||||
|
||||
50
scripts/menus/tui_layout.sh
Normal file
50
scripts/menus/tui_layout.sh
Normal file
@@ -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}||"
|
||||
}
|
||||
Reference in New Issue
Block a user