-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterminal_test.sh
executable file
·191 lines (165 loc) · 6.69 KB
/
terminal_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
#
# libsay
# terminal_test.sh - Version: 1.2-202209.26.180000
# See what your terminal can do.
# This will show what your terminal is able to do with Escape Characters
# for text effects and colours.
#
# Author: Megaf - https://github.com/Megaf - mmegaf [at] gmail [dot] com
# Date: 21/09/2022
# GitHub: https://github.com/Megaf/libsay
# License: GPL V3
# TODO: Add md5 to check if test succeeded.
# Prints the ASCII table.
start_timer()
{
start=""
start="$(date +%s.%3N)"
}
end_timer()
{
end="$(date +%s.%3N)"
total_time="$(echo "scale=3; $end - $start" | bc)"
echo "It took $total_time seconds to run the tests."
}
ascii_test()
{
echo "Printing the ASCII table."
print_ascii()
{
command=$(printf %x "$i")
printf "%sASCII code $i: "; printf "'"; echo -n -e "\x$command"; printf "'\n"
}
for i in {32..126}; do
print_ascii "$i"
done
unset -v character command i
for i in {128..254}; do
print_ascii "$i"
done
unset -v character command i
unset -f print_ascii
}
# Test terminals capabilities for text effects via Escape Characters.
terminal_test()
{
local run_amount run_number
echo "Testing terminal's capabilities."
print_test()
{
printf "\e[0m\n"; echo -n -e "\e[""$run_number""m"
printf "Text example."; printf "\e[0m\n"
printf "\n"
}
run_amount="128" # Total number of "effects" to try.
run_number="0"
printf "Testing text effects.\n"
while [ "$run_number" -le "29" ]; do
printf '%s' "Effect number: $run_number"
print_test
run_number="$((++run_number))"
done
printf "Testing normal foreground colours.\n"
while [ "$run_number" -le "39" ]; do
printf '%s' "Colour number: $run_number"
print_test
run_number="$((++run_number))"
done
printf "Testing normal background colours.\n"
while [ "$run_number" -le "49" ]; do
printf '%s' "Colour number: $run_number"
print_test
run_number="$((++run_number))"
done
printf "Testing aditional text effects.\n"
while [ "$run_number" -le "89" ]; do
printf '%s' "Effect number: $run_number"
print_test
run_number="$((++run_number))"
done
printf "Testing light foreground colours.\n"
while [ "$run_number" -le "99" ]; do
printf '%s' "Colour number: $run_number"
print_test
run_number="$((++run_number))"
done
printf "Testing light background colours.\n"
while [ "$run_number" -le "109" ]; do
printf '%s' "Colour number: $run_number"
print_test
run_number="$((++run_number))"
done
printf "Testing aditional extra effects.\n"
while [ "$run_number" -le "$run_amount" ]; do
printf '%s' "Effect number: $run_number"
print_test
run_number="$((++run_number))"
done
unset -v run_amount run_number
unset -f print_test f
}
libsay_test()
{
local test_message debug
# shellcheck source=/dev/null
source libsay
say "TITLE: The following test uses libsays's functions."
draw do_godown
debug="false";
say "NOTICE: 'debug=$debug'"
read -r -d '' test_message << EOM
TITLE: Multiline Message.
A normal unformatted text.
NOTICE: Please notice this!
WARNING: I'm warning you...
ERROR: Nothing wrong happened.
INFO: The line below this one is a DEBUG one.
DEBUG: Last line, DEBUG message.
EOM
rst; say "$test_message"; rst
draw do_godown
debug="true";
say "NOTICE: 'debug=$debug'"
rst; say "$test_message"; rst
unset -v test_message debug
draw do_godown
say "TITLE: Testing text formating using libsay's '_on' functions."
rst; printf '%s' " underline - "; underline_on; echo -e "This is a testing text.\n"; rst
rst; printf '%s' " squiggly underline - "; wavy_underline_on; echo -e "This is a testing text.\n"; rst
rst; printf '%s' " double underline - "; double_underline_on; echo -e "This is a testing text.\n"; rst
rst; printf '%s' " overline - "; overline_on; echo -e "This is a testing text.\n"; rst
rst; printf '%s' " underline and overline - "; overunder_on; echo -e "This is a testing text.\n"; rst
rst; printf '%s' "underline and squiggly overline - "; overuwavynder_on; echo -e "This is a testing text.\n"; rst
rst; printf '%s' " bold - "; bold_on; echo -e "This is a testing text.\n"; rst
rst; printf '%s' " inverted - "; invert_on; echo -e "This is a testing text.\n"; rst
rst; printf '%s' " blinking - "; blink_on; echo -e "This is a testing text.\n"; rst
rst; printf '%s' " italics - "; italics_on; echo -e "This is a testing text.\n"; rst
rst; printf '%s' " strike-through - "; crossout_on; echo -e "This is a testing text.\n"; rst
rst; printf '%s' " faded - "; fade_on; echo -e "This is a testing text.\n"; rst
}
__all_tests() { terminal_test && ascii_test && libsay_test; }
help_menu()
{
echo "┌──────────────────────────────────────────────────────┐"
echo "| Please run './terminal_test test_name'. |"
echo "| Where 'test name' is one of the following: |"
echo "├─────────────────┬────────────────────────────────────┤"
echo "| Test Name | Description |"
echo "├─────────────────┼────────────────────────────────────┤"
echo "| 'terminal_test' | Tests your termina's capabilities. |"
echo "| 'ascii_test' | Prints the ASCII Table. |"
echo "| 'libsay_test' | Tests the libsay library. |"
echo "| 'all' | Runs all of the above. |"
echo "└─────────────────┴────────────────────────────────────┘"
}
case "$*" in
terminal_test) start_timer; terminal_test; end_timer ;;
ascii_test) start_timer; ascii_test; end_timer ;;
libsay_test) start_timer; libsay_test; end_timer ;;
all) start_timer; __all_tests; end_timer ;;
*) help_menu ;;
esac
unset -v start end total_time
unset -f terminal_test ascii_test libsay_test help_menu start_timer end_timer
exit 0