Skip to content

Commit cde489d

Browse files
Refactor style function to be more flexible to support more styles
1 parent 92769d1 commit cde489d

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

β€Žgenerator.sh

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,36 @@ SH_ECHO
127127
else
128128
code=9
129129
fi
130-
# bold or not
131-
for bold in "" "Bold"; do
132-
if [ "${bold}" = "" ]; then
133-
bCode=
134-
else
135-
bCode='1;'
136-
fi
137-
# underline or not
138-
for underLine in "" "UL"; do
139-
{
140-
echo ""
141-
printf "%secho%s%s%s%s%s%s" "${fn}" "${dot}" "${light}" "${bold}" "${underLine}" "${color}" "${brackets}"
142-
if [ "${underLine}" = "" ]; then
143-
ulCode=
144-
else
145-
ulCode='4;'
146-
fi
147-
# write the code down
148-
echo "${startSym}"
149-
echo " ${echo}"' "\\033['"${ulCode}${bCode}${code}""$(grep "${color}" "${table}" | awk '{print $2}')"'m$'"${para}"'\\033[m"'
150-
echo "${endSym}"
151-
} >> "${newDist}"
130+
# style like bold, underline
131+
for style in "" "Bold" "UL"; do
132+
case "${style}" in
133+
"Bold") styleCode='1;' ;;
134+
"UL") styleCode='4;' ;;
135+
""|*) styleCode= ;;
136+
esac
137+
for style2 in "" "Bold" "UL"; do
138+
if [ "${style}" != "${style2}" ]; then
139+
case "${style2}" in
140+
"Bold") finalStyleCode="${styleCode}1;" ;;
141+
"UL") finalStyleCode="${styleCode}4;" ;;
142+
""|*) finalStyleCode="${styleCode}" ;;
143+
esac
144+
else
145+
style2=
146+
finalStyleCode="${styleCode}"
147+
fi
148+
echoFunction="$(printf "%secho%s%s%s%s%s" "${fn}" "${dot}" "${light}" "${style}" "${style2}" "${color}")"
149+
echoFunctionShuffle="$(printf "%secho%s%s%s%s%s" "${fn}" "${dot}" "${light}" "${style2}" "${style}" "${color}")"
150+
if ! ( grep -q "${echoFunction}" "${newDist}" || grep -q "${echoFunctionShuffle}" "${newDist}") ; then
151+
{
152+
echo ""
153+
printf "%s%s" "${echoFunction}" "${brackets}"
154+
# write the code down
155+
echo "${startSym}"
156+
echo " ${echo}"' "\\033['"${finalStyleCode}${code}""$(grep "${color}" "${table}" | awk '{print $2}')"'m$'"${para}"'\\033[m"'
157+
echo "${endSym}"
158+
} >> "${newDist}"
159+
fi
152160
done
153161
done
154162
done

0 commit comments

Comments
Β (0)