summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2023-12-27 18:56:28 +0000
committerdavidovski <david@davidovski.xyz>2023-12-27 18:56:28 +0000
commit739ff05c19c67d27c5790e365b3315da03c58e34 (patch)
tree4d25af6891cad3ecb2c5faeecb2ef6a7fc7ed4c1
parent8788e6bd8023dc4b8fe24f22e0bfd85e325658c5 (diff)
line wrapping on words
-rwxr-xr-xtypr.sh31
1 files changed, 18 insertions, 13 deletions
diff --git a/typr.sh b/typr.sh
index 800b7f1..9ceafad 100755
--- a/typr.sh
+++ b/typr.sh
@@ -42,7 +42,9 @@ typr_draw_text () {
i=0
t="$text"
e="$entered_text"
+ lt=""
while [ "$t" ] ; do
+ lt=$ct
ct=${t%${t#?}}
ce=${e%${e#?}}
t="${t#?}"
@@ -55,6 +57,12 @@ typr_draw_text () {
[ ! "$ce" ] && newcolor="" \
+ [ "$i" -gt "$startcol" ] && [ "$lt" = " " ] && {
+ line=$((line+1))
+ draw="${draw}[${line};${startcol}H"
+ i=0
+ }
+
[ "$color" != "$newcolor" ] && {
color="$newcolor"
draw="${draw}$newcolor"
@@ -62,12 +70,6 @@ typr_draw_text () {
}
- [ "$i" -gt "$startcol" ] && {
- line=$((line+1))
- draw="${draw}[${line};${startcol}H"
- i=0
- }
-
[ "$ct" = " " ] && [ "$color" = "" ] \
&& draw="${draw}_" \
|| draw="$draw$ct"
@@ -85,12 +87,12 @@ typr_get_time () {
time_ms=$(((time_ns/1000000)%1000))
time_seconds=$(((time_ns/1000000000)%60))
time_minutes=$((time_ns/60000000000))
-
+
printf "%02d:%02d.%03d" "$time_minutes" "$time_seconds" "$time_ms"
}
typr_draw_time () {
- printf "[$((areay-1));${areax}H%s" "$(typr_get_time)"
+ [ ! -z "$start" ] && printf "[$((areay-1));${areax}H%s" "$(typr_get_time)"
}
typr_show_results () {
@@ -115,7 +117,7 @@ typr_show_results () {
typr_generate_text () {
wordcount=100
- text="$(printf "%s\n" $words | shuf -r -n $wordcount | xargs printf "%s ")"
+ text="$(printf "%s " $(printf "%s\n" $words | shuf -r -n $wordcount))"
text="${text% }"
}
@@ -126,12 +128,14 @@ typr_draw_loop () {
done
}
-
-typr_main () {
+typr_start_timer () {
start="$(date +%s%N)"
-
typr_draw_loop &
draw_pid="$!"
+ export start draw_pid
+}
+
+typr_main () {
while true; do
typr_draw_text
@@ -142,7 +146,8 @@ typr_main () {
entered_text="${entered_text%?}"
;;
*)
- echo "$c" >> LOG
+ [ -z "$start" ] && typr_start_timer
+
entered_text="$entered_text$c"
;;
esac