-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathj_type
More file actions
executable file
·969 lines (964 loc) · 38.4 KB
/
j_type
File metadata and controls
executable file
·969 lines (964 loc) · 38.4 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
#! /usr/bin/env bash
##region########################################### GET PATH, DIR, & NAME ###########################################
readonly MY_PATH=$(realpath "$0")
MY_DIR=''
MY_NAME=''
if [[ "$MY_PATH" =~ ^(.*)/([^/]+)$ ]]; then
readonly MY_DIR="${BASH_REMATCH[1]}" MY_NAME="${BASH_REMATCH[2]}"
else
readonly MY_DIR="$HOME" MY_NAME="$0"
echo "$MY_NAME: Failed to get dir" 1>&2
exit 1
fi
##endregion######################################## GET PATH, DIR, & NAME ###########################################
##region########################################### SHOW HELP & VERSION ###########################################
show_help() {
cat << __EOF__
A typing test.
Usage: $0 [-gp] [-w WIDTH] [-l LINES] [VALID_CHARACTERS]
or: $0 --help
or: $0 --version
Options:
-h, --help: Shows this help text.
-v, --version: Shows version info.
__EOF__
}
show_version() {
cat << __EOF__
$0 1.1.0
Copyright (C) 2025 Justin Morris
__EOF__
}
##endregion######################################## SHOW HELP & VERSION ###########################################
# readonly LOG_FILE="$MY_DIR/$MY_NAME.log.txt"
readonly WORDS_FILE="$MY_DIR/words.txt"
# cspell:disable-next-line
readonly DEFAULT_CHARACTER_LIST='asdfjkl;ghqwertyuiopxczvbnm,.'
declare -A CTR_SEQ=; declare -A TPUT_COLOR=; declare -i MAX_READ_INT=; declare RESET_COLOR_BACKGROUND=; declare RESET_COLOR_FOREGROUND=
eval "$(misc_util CTR_SEQ TPUT_COLOR MAX_READ_INT RESET_COLOR_BACKGROUND RESET_COLOR_FOREGROUND)"
##region########################################### PARAMETERS ###########################################
# # The time in milliseconds after which an update will be forced.
# # TODO: Implement
# declare -ir FORCE_REFRESH_INTERVAL=5000
# The time in milliseconds after which an update will be attempted.
declare -ir REFRESH_INTERVAL=500
# The maximum # of words to use for test generation.
declare -i maxDictSize=100000
declare -i maxWordLength=7
declare -i rows=3
declare -i columns=$(tput cols)
declare characters=''
declare -a words=()
# Dynamically generate nonsense words?
declare fGenWords='true'
declare fProperPunctuation='true'
# declare fReplay='false'
while [[ -n "${1+x}" ]]; do
case "$1" in
(-h | --help) show_help; exit;;
(-v | --version) show_version; exit;;
(-l | --lines) shift; declare -ir rows="$1";;
(-w | --width) shift; declare -ir columns="$1";;
(-g | --genWords) fGenWords='true';;
(\+g | -!g | \+\+genWords | --!genWords) fGenWords='false';;
(-p | --properPunctuation) fProperPunctuation='true';;
(\+p | -!p | \+\+properPunctuation | --!properPunctuation) fProperPunctuation='false';;
# (-r | --replay)
# ;;
(*) characters+="$1";;
esac
shift
done
if [ -z "$characters" ]; then characters="$DEFAULT_CHARACTER_LIST"; fi
declare -r punctuationCharacters="$(echo -nE "$characters" | sed -E 's/[^[:punct:]]//g')"
# declare -r alnumCharacters="$(echo -nE "$characters" | sed -E 's/[^[:alnum:]]//g')"
if ! eval "$fGenWords"; then
# match only the words that are short enough & only have valid characters
mapfile -t words < <(grep --max-count=$maxDictSize -E --text -e "^[$characters]{1,$maxWordLength}$" "$WORDS_FILE")
fi
if ! [[ "$characters" =~ ' ' ]]; then characters+=' '; fi
declare -r characters
declare -r ORIG_IFS="$IFS"
##region########################################### Get Random Word ###########################################
# # 1: max length
# # 2: valid chars
# # 3...: invalid indices
# getRandomWord() {
# local -a validWords
# if [ -n "${words[*]}" ]; then
# IFS=$'\n'
# mapfile -t validWords < <(echo -n "${words[*]}" | grep --max-count=$maxDictSize -E --text -e "^[${2:-$characters}]{1,${1:-$maxWordLength}}$")
# IFS="$ORIG_IFS"
# else
# mapfile -t validWords < <(grep --max-count=$maxDictSize -E --text -e "^[${2:-$characters}]{1,${1:-$maxWordLength}}$" "$WORDS_FILE")
# fi
# local -i t_ind=$RANDOM%${#validWords[@]} safety=0
# # if shift 2 && [ -n "$*" ]; then
# if shift 2; then
# while ((safety++ < 100)) && array_includes $t_ind "$@"; do
# t_ind=$RANDOM%${#validWords[@]}
# done
# fi
# echo -n "${validWords[$t_ind]}"
# return $safety
# }
##endregion######################################## Get Random Word ###########################################
##endregion######################################## PARAMETERS ###########################################
# shellcheck disable=SC2317
function storeStatisticsScreen() { true; }
# TODO: Redirect for error message
function doExit() {
tput clear
stty echo
if ((${1:-0} == 0)); then
storeStatisticsScreen
tput rmcup
else
tput rmcup
echo "$2" 1>&2
fi
exit "${1:-0}"
}
tput smcup; tput clear; trap 'doExit' INT
declare -a testLines=()
##region########################################### GENERATE TEST SEQUENCE ###########################################
declare -a newTestLines=()
# Dependent on:
# * newTestLines
function genTestSequence() {
RANDOM=$$
declare -g newTestLines=()
local l_current_word=''
local -r punctAndSpace="$punctuationCharacters "
local -i j=0; local -i i=0
local -i count=0
# l_current_word shouldn't be emptied before calling if punctuation is desired.
_validateAndAddChar() {
if [ "$1" = ' ' ]; then
# If it doesn't end in space & isn't empty...
if [ "${newTestLines[$j]: -1}" != ' ' ] && (("${#l_current_word}" > 0)); then
l_current_word=''
newTestLines[j]+="$1"
# ...forcing a space...
elif [ -n "$2" ]; then
l_current_word=''
newTestLines[j]+=' '
else # Try again
((i--))
fi
elif eval "$fProperPunctuation"; then
if [[ "$1" =~ [\;\,\.\:\!] ]]; then
# If there's space for the char + a space, it's preceded by a letter/number, & the word isn't empty
if ((${#newTestLines[$j]} + 2 < columns)) &&
[[ "${newTestLines[$j]: -1}" =~ [[:alnum:]] ]] &&
(("${#l_current_word}" > 0)); then
l_current_word=''
newTestLines[j]+="$1 "
((i++))
# ...forcing a space...
elif [ -n "$2" ]; then
l_current_word=''
newTestLines[j]+=' '
else # Try again
((i--))
fi
else
l_current_word+="$1"
newTestLines[j]+="$1"
fi
else
l_current_word+="$1"
newTestLines[j]+="$1"
fi
}
_addPunctOrSpace() {
if eval "$fProperPunctuation"; then
_validateAndAddChar "${punctAndSpace:$((${#punctuationCharacters} > 0 ? RANDOM % (${#punctuationCharacters} + 1) : 0)):1}" 'force'
else
newTestLines[j]+="${punctAndSpace:$((${#punctuationCharacters} > 0 ? RANDOM % (${#punctuationCharacters} + 1) : 0)):1}"
fi
}
for ((j = 0; j < rows; j++)); do
for ((i = 0; i < columns; i++)); do
echo -n $'\r'"$((count++))"
if ((${#l_current_word} >= maxWordLength)); then
if eval "$fProperPunctuation" && ((${#punctuationCharacters} > 0)); then
_validateAndAddChar "${punctAndSpace:$((RANDOM % (${#punctuationCharacters} + 1))):1}" 'force'
else
newTestLines[j]+=' '
fi
l_current_word=
continue
fi
if ((${#words[@]} > 0)); then
local -a badIndices=()
local -i c2=0
local -i loop=0
echo -n ' '
while true; do
echo -n "$(tput cub 3)$((c2++))"
# echo -n $'\n'"$((c2++))$(tput cuu1)"
((t_ind = RANDOM % ${#words[@]}))
for ((t_ind = RANDOM % ${#words[@]}; loop < 100; loop++, t_ind = RANDOM % ${#words[@]})); do
if ! array_includes "$t_ind" "${badIndices[@]}"; then break; fi
done
l_current_word="${words[$t_ind]}"
local -i newLength=0
((newLength = ${#newTestLines[j]} + ${#l_current_word}))
# If it overflows the line...
if ((newLength > columns)); then
# ...and there's another line...
if ((j + 1 < rows)); then
((newLength %= columns - 1, l_wordSlice=${#l_current_word} - newLength))
newTestLines[j]+="${l_current_word:0:$l_wordSlice}-"
((j++))
newTestLines[j]+="${l_current_word: -$newLength}"
((i = ${#newTestLines[j]}))
# ...and there's not another line...
else
# ...and we've tried too many options...
if ((loop >= 100)); then
# TODO: Graceful early exit
echo -n 'too many'
break 2
else # ...try another word
badIndices+=("$t_ind")
continue
fi
fi
# If it perfectly fills the line...
elif ((newLength == columns)); then
newTestLines[j]+="$l_current_word"
# ...and there's another line...
if ((j + 1 < rows)); then
# ...start it w/ a space/punctuation
((j++))
((i = 0))
else # We're done
break 3
fi
else # It fits, but doesn't fill, the line (disregarding the trailing space/punctuation)
newTestLines[j]+="$l_current_word"
((i = ${#newTestLines[j]}))
fi
# If it got here, it was successful and is waiting for a space/punctuation
# Increase chance for spaces
if ((RANDOM % 2 == 0)); then
_addPunctOrSpace
else
newTestLines[j]+=' '
fi
l_current_word=
break
done
continue
fi
_validateAndAddChar "${characters:$((RANDOM % ${#characters})):1}"
done
done
}
# function _testGenerator() {
# function _test_punctuation() {
# genTestSequence
# }
# }
genTestSequence
tput clear
##endregion######################################## GENERATE TEST SEQUENCE ###########################################
# unset words
for item in "${newTestLines[@]}"; do testLines+=("$item"); done
echo -nE "$(array_join $'\n\n' "${testLines[@]}")"
tput cup 1 0
shopt -s globasciiranges extglob
##region########################################### SETUP INPUT STREAM ###########################################
declare -ri INPUT_FD=3
declare streamFile="$(mktemp --dry-run "$HOME/Desktop/j_type_inputStream_XXXX")"
if ! [[ "$streamFile" =~ ^$HOME/Desktop/j_type_inputStream_ ]]; then doExit 1 "Cannot safely rm -f $streamFile"; fi
mkfifo "$streamFile"
exec 3<>"$streamFile"
rm -f "$streamFile"
unset streamFile
# shellcheck disable=SC2064
trap "exec $INPUT_FD>&- $INPUT_FD<&-" EXIT
exec 3<&0
##endregion######################################## SETUP INPUT STREAM ###########################################
stty -echo
declare -a inputs=('')
declare -a inputColors=('')
declare -A inputColorsBg=()
declare -i currRow=0
##region########################################### ARRAY GETTERS/SETTERS ###########################################
__restrictToBounds() {
local -i lRow=$1; local -i lCol=$2
if ((lCol >= columns)) || ((lCol < 0)); then
((lRow += lCol / columns, lRow -= lCol >= 0 ? 0 : 1, lCol %= columns, lCol += lCol >= 0 ? 0 : columns))
fi
if ((lRow < 0)); then
((lRow = 0, lCol = 0))
elif ((lRow >= rows)); then
((lRow = rows - 1, lCol = columns - 1))
fi
echo $lRow $lCol
if ((lCol < 0 || lCol >= columns)); then
doExit 127 "Bad Bounding"
fi
# if ((lCol < 0)); then
# ((lCol = 0))
# elif ((lCol >= columns)); then
# ((lCol = columns - 1))
# fi
}
# Needs to end in a new line for easy usage w/ read
getXY() {
local fBounded='true'
if [ "$1" = '--unbounded' ]; then
fBounded='false'
shift
fi; local -r fBounded
local -i lRow=
local -i lCol=
if [[ "$1" =~ ^([[:digit:]])+\:([[:digit:]])+$ ]]; then
lRow="${BASH_REMATCH[1]}"
lCol="${BASH_REMATCH[2]}"
else
if [ -n "$1" ]; then
lRow="$1"
else
lRow="$currRow"
fi
if [ -n "$2" ]; then
lCol="$2"
else
lCol="${#inputs[$lRow]}"
fi
fi
if eval "$fBounded"; then
__restrictToBounds $lRow $lCol
else
echo $lRow $lCol
fi
}
# getXYUnbounded() { getXY --unbounded "$@"; }
# isInBounds() {
# local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXY "$@"); local -ir lRow lCol
# ((lRow >= 0 && lCol >= 0 && lRow < rows && lCol < columns))
# }
getXYNext() {
local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXY "$@")
# if ((lCol >= columns && lRow < rows)); then
((lCol++))
if ((lCol >= columns)); then ((lRow += lCol / columns, lCol %= columns)); fi
echo $lRow $lCol
}
getXYAfterNext() { read -sr lRow lCol < <(getXYNext "$@"); getXYNext "$lRow" "$lCol"; }
getXYPrior() {
local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXY "$@")
((lCol--))
if ((lCol < 0)); then
((lRow += lCol / columns, lRow -= lCol >= 0 ? 0 : 1, lCol %= columns, lCol += lCol >= 0 ? 0 : columns))
fi
echo $lRow $lCol
}
getXYBeforePrior() { read -sr lRow lCol < <(getXYPrior "$@"); getXYPrior "$lRow" "$lCol"; }
# isInBounds() {
# local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXY "$@"); local -ir lRow lCol
# ((lRow >= 0 && lCol >= 0 && lRow < rows && lCol < columns))
# }
# restrictToBounds() {
# local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXY --unbounded "$@")
# if ((lCol >= columns)) || ((lCol < 0)); then
# ((lRow += lCol / columns, lRow -= lCol >= 0 ? 0 : 1, lCol %= columns, lCol += lCol >= 0 ? 0 : columns))
# fi
# }
getCoord() {
local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXY "$@"); local -ir lRow lCol
echo -n "$lRow:$lCol"
# echo -n "$currRow:${#inputs[$currRow]}"
}
getForPrior() {
local lCommand="$1"; shift
if ! [ "${lCommand:0:3}" = 'get' ]; then lCommand="get${lCommand@u}"; fi
local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXYPrior "$@"); shift 2
$lCommand $lRow $lCol
}
setForPrior() {
local lCommand="$1"; shift
local lValue="$1"; shift
if ! [ "${lCommand:0:3}" = 'set' ]; then lCommand="set${lCommand@u}"; fi
local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXYPrior "$@"); shift 2
$lCommand "$lValue" $lRow $lCol
}
getForBeforePrior() {
local lCommand="$1"; shift
local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXYPrior "$@"); shift 2
getForPrior "$lCommand" $lRow $lCol
}
# setForBeforePrior() {
# local lCommand="$1"; shift; local lValue="$1"; shift
# local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXYPrior "$@"); shift 2
# setForPrior "$lCommand" "$lValue" $lRow $lCol
# }
getForNext() {
local lCommand="$1"; shift
if ! [ "${lCommand:0:3}" = 'get' ]; then lCommand="get${lCommand@u}"; fi
local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXYNext "$@"); shift 2
$lCommand $lRow $lCol
}
# setForNext() {
# local lCommand="$1"; shift
# local lValue="$1"; shift
# if ! [ "${lCommand:0:3}" = 'set' ]; then lCommand="set${lCommand@u}"; fi
# local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXYNext "$@"); shift 2
# $lCommand "$lValue" $lRow $lCol
# }
getForAfterNext() {
local lCommand="$1"; shift
local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXYNext "$@"); shift 2
getForNext "$lCommand" $lRow $lCol
}
# setForAfterNext() {
# local lCommand="$1"; shift; local lValue="$1"; shift
# local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXYNext "$@"); shift 2
# setForNext "$lCommand" "$lValue" $lRow $lCol
# }
getTestChar() {
local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXY "$@"); local -ir lRow lCol
local t="${testLines[$lRow]}"; echo -n "${t: $lCol:1}"
}
# shellcheck disable=SC2120
getInput() {
local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXY "$@"); local -ir lRow lCol
local t="${inputs[$lRow]}"; echo -n "${t: $lCol:1}"
}
# shellcheck disable=SC2120
getInputColor() {
local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXY "$@"); local -ir lRow lCol
local t="${inputColors[$lRow]}"; echo -n "${t: $lCol:1}"
}
# shellcheck disable=SC2120
getInputColorBg() {
local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXY "$@"); local -ir lRow lCol
local t="$(getCoord $lRow $lCol)"; echo -n "${inputColorsBg[$t]}"
}
# setInput() {
# local val="$1"; shift
# local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXY "$@"); local -ir lRow lCol; shift 2
# inputs[lRow]="${inputs[$lRow]:0:$lCol}${val}${inputs[$lRow]:$((lCol + 1))}"
# }
setInputColor() {
local val="$1"; shift
local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXY "$@"); local -ir lRow lCol; shift 2
inputColors[lRow]="${inputColors[$lRow]:0:$lCol}${val}${inputColors[$lRow]:$((lCol + 1))}"
}
# setInputColorBg() {
# local val="$1"; shift
# local -i lRow=; local -i lCol=; read -sr lRow lCol < <(getXY "$@"); local -ir lRow lCol; shift 2
# local t="$(getCoord $lRow $lCol)"; inputColorsBg[$t]="$val"
# }
##endregion######################################## ARRAY GETTERS/SETTERS ###########################################
getCurrInputColNum() { echo -n ${#inputs[$currRow]}; }
getInputColNum() { if [ -z "$1" ]; then getCurrInputColNum; else echo -n ${#inputs[$1]}; fi; }
getCurrInputRowNum() { echo -n $currRow; }
addToInput() {
local -i linesAdded=0; local -i myCurrRow=$currRow; local -i myCurrCol=$(getCurrInputColNum)
for ((i = 0; i < "${#1}"; i++, myCurrCol++)); do
inputs[myCurrRow]+="${1:$i:1}"
if ((myCurrCol + 1 == columns)); then
((linesAdded++, myCurrRow++, myCurrCol = -1))
elif ((myCurrCol + 1 > columns)); then
doExit 1 "$myCurrCol > columns ($columns)"
fi
done
return $linesAdded
}
removeFromInput() {
local -i linesRemoved=0; local -i myCurrRow=$currRow; local -i myCurrCol=$(getInputColNum $myCurrRow)
for ((i = 0; i < "$1"; i++, myCurrCol--)); do
if ((myCurrCol == 0 && myCurrRow > 0)); then
((linesRemoved++, myCurrRow--, myCurrCol = $(getInputColNum $myCurrRow)))
elif ((myCurrCol < 0)); then
doExit 1 "$myCurrCol < 0"
fi
inputs[myCurrRow]="${inputs[$myCurrRow]:0:$((myCurrCol - 1))}${inputs[$myCurrRow]:$myCurrCol}"
done
return $linesRemoved
}
##region########################################### Line/Word Boundaries ###########################################
# If character at cursor position is alpha-numeric but the prior one wasn't
# shellcheck disable=SC2120
isAtWordStart() { [[ $(getTestChar "$@") =~ ^[[:alnum:]]+$ ]] && ! [[ $(getForPrior TestChar "$@") =~ ^[[:alnum:]]+$ ]]; }
# If character at cursor position isn't alpha-numeric but the next one is
# shellcheck disable=SC2120
isBeforeWordStart() { ! [[ $(getTestChar "$@") =~ ^[[:alnum:]]+$ ]] && [[ $(getForNext TestChar "$@") =~ ^[[:alnum:]]+$ ]]; }
# If character at cursor position isn't alpha-numeric but the prior one was
isAtWordEnd() { ! [[ $(getTestChar "$@") =~ ^[[:alnum:]]+$ ]] && [[ $(getForPrior TestChar "$@") =~ ^[[:alnum:]]+$ ]]; }
# If character at cursor position is alpha-numeric but the next one isn't
# shellcheck disable=SC2120
isBeforeWordEnd() { [[ $(getTestChar "$@") =~ ^[[:alnum:]]+$ ]] && ! [[ $(getForNext TestChar "$@") =~ ^[[:alnum:]]+$ ]]; }
isAboutToEndLine() { (($(getCurrInputColNum) == ${#testLines[$(getCurrInputRowNum)]} - 1)); }
isAtStartOfLine() { (($(getCurrInputColNum) == 0)); }
# hasJustEndedLine() { isAtStartOfLine && (($(getCurrInputRowNum) > 0)); }
# isAtWordOrLineStart() { isAtStartOfLine || isAtWordStart; }
# isAtStartPosition() { (($(getCurrInputRowNum) == 0 && $(getCurrInputColNum) == 0)); }
# isAtEndPosition() { (($(getCurrInputRowNum) + 1 == rows && $(getCurrInputColNum) + 1 == columns)); }
##endregion######################################## Line/Word Boundaries ###########################################
##region########################################### General Test ###########################################
# generalTest() {
# local -r cumulative="$(array_join '' "${testLines[@]}")"
# local -i i=0
# local errored='false'
# for ((i = 2; i + 2 < ${#cumulative}; i++)); do
# if ! [ "$(getForBeforePrior testChar 0 $i)" = "${cumulative:$((i - 2)):1}" ]; then
# echo "getForBeforePrior testChar 0 $i failed ($(getForBeforePrior testChar 0 $i) != ${cumulative:$((i - 2)):1})"
# getXYBeforePrior 0 $i
# getXYPrior 0 $i
# getXY 0 $i
# getXYNext 0 $i
# getXYAfterNext 0 $i
# errored='true'
# fi
# if ! [ "$(getForPrior testChar 0 $i)" = "${cumulative:$((i - 1)):1}" ]; then
# echo "getForPrior testChar 0 $i failed ($(getForPrior testChar 0 $i) != ${cumulative:$((i - 1)):1})"
# getXYBeforePrior 0 $i
# getXYPrior 0 $i
# getXY 0 $i
# getXYNext 0 $i
# getXYAfterNext 0 $i
# errored='true'
# fi
# if ! [ "$(getTestChar 0 $i)" = "${cumulative:$((i - 0)):1}" ]; then
# echo "getTestChar 0 $i failed ($(getTestChar 0 $i) != ${cumulative:$((i - 0)):1})"
# getXYBeforePrior 0 $i
# getXYPrior 0 $i
# getXY 0 $i
# getXYNext 0 $i
# getXYAfterNext 0 $i
# errored='true'
# fi
# if ! [ "$(getForNext testChar 0 $i)" = "${cumulative:$((i + 1)):1}" ]; then
# echo "getForNext testChar 0 $i failed ($(getForNext testChar 0 $i) != ${cumulative:$((i + 1)):1})"
# getXYBeforePrior 0 $i
# getXYPrior 0 $i
# getXY 0 $i
# getXYNext 0 $i
# getXYAfterNext 0 $i
# errored='true'
# fi
# if ! [ "$(getForAfterNext testChar 0 $i)" = "${cumulative:$((i + 2)):1}" ]; then
# echo "getForAfterNext testChar 0 $i failed ($(getForAfterNext testChar 0 $i) != ${cumulative:$((i + 2)):1})"
# getXYBeforePrior 0 $i
# getXYPrior 0 $i
# getXY 0 $i
# getXYNext 0 $i
# getXYAfterNext 0 $i
# errored='true'
# fi
# done
# # if eval "$errored"; then doExit; fi
# if ! eval "$errored"; then echo -n "$(tput setab 2) $(tput cub1)$RESET_COLOR_BACKGROUND"; fi
# }
# generalTest
##endregion######################################## General Test ###########################################
declare startTime=''
# The last time the status was updated, in milliseconds since `startTime`.
declare -i lastStatusUpdateTime=0
# The elapsed time since `startTime` in milliseconds.
declare -i lastUpdateTime=0
# The elapsed time since `lastUpdateTime` in milliseconds.
declare -i currDeltaTime=''
# The elapsed time since `startTime` in milliseconds.
declare currUpdateTime=''
declare -r startDate="$(date --iso-8601='seconds')"
declare -a wordStartTimes=("0")
declare -a wordEndTimes=()
declare -a wordStartPositions=('0:0')
function calcWordTime() {
local -i wordIndex=0
if (($# >= 2 || $# <= 0)); then
local -ir wordIndex=$(indexOf "$(getCoord "$@")" "${wordStartPositions[@]}")
if ((wordIndex == -1)); then
doExit 111 "input $* wordStartPositions ${wordStartPositions[*]}"
fi
else
local -ir wordIndex="$1"
fi
if ((${#wordEndTimes[@]} > wordIndex)); then
getDeltaTime -m --from "${wordStartTimes[$wordIndex]}" --to "${wordEndTimes[$wordIndex]}"
else
getDeltaTime -m --from "${wordStartTimes[$wordIndex]}" --to "$currUpdateTime"
fi
}
function getWordCompletionData() {
local -i r=; local -i c=; read -sr r c < <(getXY "$@")
local -ir startR=r; local -ir startC=c
local word=
local -i endR=r; local -i endC=c
while ! isAtWordEnd $r $c; do
word+="$(getTestChar $r $c)"
((endR=r, endC=c))
read -sr r c < <(getXYNext $r $c)
done
local -ir wordIndex=$(indexOf "$startR:$startC" "${wordStartPositions[@]}")
local -r wordTime=$(calcWordTime "$wordIndex")
echo "$startR" "$startC" "$endR" "$endC" "$word" "$wordIndex" "$wordTime"
}
declare -i recognizedKeystrokes=0
declare -a badInputs=()
declare -i allMistakesCount=0
declare -i uniqueMistakesCount=0
# Maps the `$row:$column:$incorrectCharacter` to the # of times that combination was typed; used to allow for contextual error reporting (i.e. provides info to determine if a certain sequence of keystrokes causes errors instead of just the expected & entered character).
declare -A mistakeContext=()
declare -A mistakeFreq=()
# Can be used to replicate this run (think Doom replays).
# TODO: Add to whenever recognizedKeystrokes is incremented
declare inputSequence=
declare -r STATS_FILE="$MY_DIR/jTypeStats.txt"
function storeStatisticsScreen() {
# ${lastUpdateTime@A}
output=$(cat <<-_EOF_
$startDate
${testLines[@]@A}
${inputs[@]@A}
${inputColors[@]@A}
${inputColorsBg[@]@A}
${currRow@A}
${wordStartTimes[@]@A}
${wordEndTimes[@]@A}
${badInputs[@]@A}
${allMistakesCount@A}
${uniqueMistakesCount@A}
${mistakeContext[@]@A}
${mistakeFreq[@]@A}
${inputSequence@A}
${rows@A}
${columns@A}
_EOF_
)
read -rN 1 -p $'STATISTICS:\n'"$output"$'\n'"$(tput smso)Store statistics to '$STATS_FILE'? (y/n)$(tput rmso) "
if [ "$REPLY" = 'n' ] || [ "$REPLY" = 'N' ]; then return; fi
echo -E "$output" >>"$STATS_FILE"
}
_update() {
# Putting this before _update makes it very slow for whatever reason.
# shellcheck disable=SC2120
function printStatus() {
local -a flags=()
if (($# == 0)); then
local -ar flags=(
'--deltaWord'
'--wordTimesLength'
'--linePositWordFlags'
'--positAlnum'
'--testChar'
'--input'
'--xy'
# '--wordStartPositions'
'--wordStartTimes'
'--wordEndTimes'
# '--badInputs'
# '--mistakesCount'
# '--mistakeFreq'
# '--calcWordTimes'
# '--lastDictWord'
# '--inputColor'
# '--inputColorBg'
# '--coord'
# '--getCurrInputColNum'
# '--inputs'
'--currDeltaTime'
'--currUpdateTime'
'--lastUpdateTime'
'--wordData'
)
else
local -ar flags=("$@")
fi
local preStatusLine="$(tput cud $((rows * 2 - currRow * 2)))"
local statusLine=$'\rStatus Line:'
_show() { array_includes "$1" "${flags[@]}"; }
__addLine() { statusLine+="$*$(tput el)"$' \b\n'; }
IFS=' '
_show '--inputs' && __addLine "inputs: $(array_join $'\n' "${inputs[@]}")"
_show '--getCurrInputColNum' && __addLine "getCurrInputColNum: $(getCurrInputColNum)"
# shellcheck disable=SC2119
_show '--xy' && __addLine "getXY: BeforePrior=$(getXYBeforePrior); Prior=$(getXYPrior); curr=$(getXY); Next=$(getXYNext); AfterNext=$(getXYAfterNext)"
_show '--coord' && __addLine "getCoord: beforePrior=$(getForBeforePrior Coord); prior=$(getForPrior Coord); curr=$(getCoord); Next=$(getForNext Coord); AfterNext=$(getForAfterNext Coord)"
# shellcheck disable=SC2119
_show '--inputColor' && __addLine "getInputColor: beforePrior=$(getForBeforePrior getInputColor); prior=$(getForPrior getInputColor); curr=$(getInputColor); Next=$(getForNext getInputColor); AfterNext=$(getForAfterNext getInputColor)"
# shellcheck disable=SC2119
_show '--inputColorBg' && __addLine "getInputColorBg: beforePrior=$(getForBeforePrior getInputColorBg); prior=$(getForPrior getInputColorBg); curr=$(getInputColorBg); Next=$(getForNext getInputColorBg); AfterNext=$(getForAfterNext getInputColorBg)"
# shellcheck disable=SC2119
_show '--input' && __addLine "getInput: beforePrior=$(getForBeforePrior getInput); prior=$(getForPrior getInput); curr=$(getInput); Next=$(getForNext getInput); AfterNext=$(getForAfterNext getInput)"
_show '--testChar' && __addLine "TestChar: beforePrior=$(getForBeforePrior TestChar); prior=$(getForPrior TestChar); curr=$(getTestChar); Next=$(getForNext TestChar); AfterNext=$(getForAfterNext TestChar)"
if _show '--positAlnum'; then
statusLine+="is alnum: "
if [[ $(getForPrior TestChar) =~ ^[[:alnum:]]+$ ]]; then statusLine+="$(tput setaf "${TPUT_COLOR[GREEN]}")"; else statusLine+="$(tput setaf "${TPUT_COLOR[RED]}")"; fi; statusLine+="prior "
if [[ $(getTestChar) =~ ^[[:alnum:]]+$ ]]; then statusLine+="$(tput setaf "${TPUT_COLOR[GREEN]}")"; else statusLine+="$(tput setaf "${TPUT_COLOR[RED]}")"; fi; statusLine+="curr "
if [[ $(getForNext TestChar) =~ ^[[:alnum:]]+$ ]]; then statusLine+="$(tput setaf "${TPUT_COLOR[GREEN]}")"; else statusLine+="$(tput setaf "${TPUT_COLOR[RED]}")"; fi; statusLine+="next"
__addLine "$RESET_COLOR_FOREGROUND"
fi
if _show '--linePositWordFlags'; then
# shellcheck disable=SC2119
if isAtWordStart; then statusLine+="$(tput setaf "${TPUT_COLOR[GREEN]}")"; else statusLine+="$(tput setaf "${TPUT_COLOR[RED]}")"; fi; statusLine+=" isAtWordStart"
# shellcheck disable=SC2119
if isBeforeWordStart; then statusLine+="$(tput setaf "${TPUT_COLOR[GREEN]}")"; else statusLine+="$(tput setaf "${TPUT_COLOR[RED]}")"; fi; statusLine+=" isBeforeWordStart"
# shellcheck disable=SC2119
if isAtWordEnd; then statusLine+="$(tput setaf "${TPUT_COLOR[GREEN]}")"; else statusLine+="$(tput setaf "${TPUT_COLOR[RED]}")"; fi; statusLine+=" isAtWordEnd"
# shellcheck disable=SC2119
if isBeforeWordEnd; then statusLine+="$(tput setaf "${TPUT_COLOR[GREEN]}")"; else statusLine+="$(tput setaf "${TPUT_COLOR[RED]}")"; fi; statusLine+=" isBeforeWordEnd"
if isAtStartOfLine; then statusLine+="$(tput setaf "${TPUT_COLOR[GREEN]}")"; else statusLine+="$(tput setaf "${TPUT_COLOR[RED]}")"; fi; statusLine+=" isAtStartOfLine"
if isAboutToEndLine; then statusLine+="$(tput setaf "${TPUT_COLOR[GREEN]}")"; else statusLine+="$(tput setaf "${TPUT_COLOR[RED]}")"; fi; statusLine+=" isAboutToEndLine"
__addLine "$RESET_COLOR_FOREGROUND"
fi
_show '--currDeltaTime' && __addLine "currDeltaTime: $currDeltaTime"
_show '--currUpdateTime' && __addLine "currUpdateTime: $currUpdateTime"
_show '--lastUpdateTime' && __addLine "lastUpdateTime: $lastUpdateTime"
_show '--deltaWord' && __addLine "deltaWord: $((currUpdateTime - wordStartTimes[-1]))"
_show '--wordTimesLength' && __addLine "Length: wordStartTimes=${#wordStartTimes[@]}); wordEndTimes=${#wordEndTimes[@]})"
_show '--wordStartPositions' && __addLine "wordStartPositions (L=${#wordStartPositions[@]}): ${wordStartPositions[*]@Q}"
_show '--wordStartTimes' && __addLine "wordStartTimes (L=${#wordStartTimes[@]}): ${wordStartTimes[*]@Q}"
_show '--wordEndTimes' && __addLine "wordEndTimes (L=${#wordEndTimes[@]}): ${wordEndTimes[*]@Q}"
_show '--badInputs' && __addLine "badInputs (L=${#badInputs[@]}): ${badInputs[*]@Q}"
_show '--mistakesCount' && __addLine "All mistakes: $allMistakesCount; Unique mistakes: $uniqueMistakesCount"
_show '--mistakeFreq' && __addLine "Mistake Frequency: $(array_join ';' "${mistakeFreq[@]@K}")"
_show '--calcWordTimes' && { for ((i = 0; i < ${#wordEndTimes[@]}; i++)); do statusLine+="$i: $((wordEndTimes[i] - wordStartTimes[i])) ms; "; done; __addLine " "; }
_show '--wordData' && { for item in "${wordStartPositions[@]}"; do statusLine+="$(getWordCompletionData "$item"); "; done; __addLine " "; }
_show '--lastDictWord' && ((${#words[@]} > 0)) && __addLine "last word: ${words[-1]}"
IFS="$ORIG_IFS"
local postStatusLine="$(tput vpa $((currRow * 2 + 1)))"
if (($(getCurrInputColNum) > 0)); then postStatusLine+="$(tput cuf "$(getCurrInputColNum)")"; fi
echo -n "$preStatusLine$statusLine$postStatusLine"
unset statusLine preStatusLine postStatusLine __addLine
}
local cache=
while ((${#cache} > 0)) || read -rsN 1 -u $INPUT_FD -t .5 inputChar; do
if ((${#cache} > 0)); then inputChar="${cache:0:1}"; cache="${cache:1}"; fi
##region########################################### Update Time ###########################################
declare -g +i currUpdateTime="$(date -u +'%-s%0N')"; currUpdateTime="${currUpdateTime:0:-6}"
if [ -z "$startTime" ]; then
declare -gr startTime="$currUpdateTime"
declare -g lastUpdateTime='0'
declare -g currUpdateTime='0'
fi
declare -gi currDeltaTime="$(getDeltaTime -m --from "$lastUpdateTime" --to "$currUpdateTime")"
##endregion######################################## Update Time ###########################################
local preDisplay=
local postDisplay="$RESET_COLOR_FOREGROUND"
# Assumes
# * Color handled in `preDisplay` & `postDisplay`
# * `inputChar` holds what to add to `inputs[currRow]`
# * `inputChar` holds 1 character
_addToOutput() {
echo -n "$preDisplay$inputChar$postDisplay"
# shellcheck disable=SC2119
if isBeforeWordEnd; then
if ((${#wordStartTimes[@]} == ${#wordEndTimes[@]})); then
doExit 11 "ending word but start and end times are same length (${#wordEndTimes[*]}) S: ${wordStartTimes[*]} E: ${wordEndTimes[*]}"
fi
wordEndTimes+=("$currUpdateTime")
fi
# shellcheck disable=SC2119
if isBeforeWordStart; then
if ((${#wordStartTimes[@]} != ${#wordEndTimes[@]})); then
doExit 12 "Starting word but start and end times are different lengths (${#wordEndTimes[*]}) S(${#wordStartTimes[*]}): ${wordStartTimes[*]} E(${#wordEndTimes[*]}): ${wordEndTimes[*]}"
fi
wordStartTimes+=("$currUpdateTime")
wordStartPositions+=("$(getForNext coord)")
fi
local -i linesAdded=0 i=0
addToInput "$inputChar"
linesAdded=$?
for ((i = 0; i < linesAdded; i++)); do
tput cud 2
echo -n $'\r'
((currRow++))
done
}
# Adds the input to the display w/o changing the cursor position or the background variables.
# Assumes
# * Color handled in `preDisplay` & `postDisplay`
# * `inputChar` holds what to add to `inputs[currRow]`
# * `inputChar` holds 1 character
# shellcheck disable=SC2120
visualAddToOutput() { echo -n "$preDisplay${1:-$inputChar}$postDisplay$(tput cub1)"; }
# shellcheck disable=SC2119
if [ -n "$(getInputColorBg)" ]; then
preDisplay+="$(tput setab "$(getInputColorBg)")"
postDisplay+="$RESET_COLOR_BACKGROUND"
fi
visualScrollLeft() {
local l_coord="$(getForPrior getCoord)"
if [ "$(getForPrior getInputColor)" = 1 ]; then
setForPrior set
inputColorsBg[$l_coord]=3
fi
if [ -n "${inputColorsBg[$l_coord]}" ]; then
echo -n "$(tput setab "${inputColorsBg[$l_coord]}")"
fi
unset l_coord
if [ -n "$(getForPrior getInputColor)" ]; then
echo -n "$(tput setaf "$(getForPrior getInputColor)")"
fi
setForPrior setInputColor ''
if (($(getCurrInputColNum) == 0 && currRow > 0)); then
tput cuu 2
tput hpa $((columns - 1))
echo -n "${1:-$(getForPrior getInput)}"$'\b'"$RESET_COLOR_BACKGROUND$RESET_COLOR_FOREGROUND"
else
echo -n $'\b'"${1:-$(getForPrior getInput)}"$'\b'"$RESET_COLOR_BACKGROUND$RESET_COLOR_FOREGROUND"
fi
}
# TODO: Finish
logicalScrollLeft() {
if (($(getCurrInputColNum) == 0 && currRow <= 0)); then return; fi
visualScrollLeft
# local -i linesRemoved=0
# removeFromInput 1
# linesRemoved=$?
# ((currRow-=linesRemoved))
}
doBackspace() {
if (($(getCurrInputColNum) == 0 && currRow <= 0)); then return; fi
if isAtWordEnd; then
if ((${#wordStartTimes[@]} != ${#wordEndTimes[@]})); then
doExit 13 "Undoing word end but start and end times are different lengths (${#wordEndTimes[*]}) S(${#wordStartTimes[*]}): ${wordStartTimes[*]} E(${#wordEndTimes[*]}): ${wordEndTimes[*]}"
fi
unset 'wordEndTimes[-1]'
fi
# shellcheck disable=SC2119
if isAtWordStart; then
if ((${#wordStartTimes[@]} == ${#wordEndTimes[@]})); then
doExit 14 "Undoing word start but start and end times are same length (${#wordEndTimes[*]}) S: ${wordStartTimes[*]} E: ${wordEndTimes[*]}"
fi
unset 'wordStartTimes[-1]'
unset 'wordStartPositions[-1]'
fi
visualScrollLeft "$1"
local -i linesRemoved=0
removeFromInput 1
linesRemoved=$?
((currRow-=linesRemoved))
}
invalidCharacter() {
preDisplay+="$(tput setaf "${TPUT_COLOR[RED]}")"
setInputColor 1
preDisplay+="$(tput smso)"
postDisplay="$(tput rmso)$postDisplay"
if [ "$inputChar" = $'\e' ]; then inputChar="^["; fi
badInputs+=("$inputChar$1")
inputChar="?"
}
# If it's the correct character...
if [ "$inputChar" = "$(getTestChar)" ]; then
preDisplay+="$(tput setaf "${TPUT_COLOR[GREEN]}")"
setInputColor "${TPUT_COLOR[GREEN]}"
_addToOutput
((recognizedKeystrokes++))
# ...it's a backspace...
elif [ "$inputChar" = "$(tput kbs)" ]; then # Backspace
# If there's nothing to backspace, skip
if (($(getCurrInputColNum) <= 0 && currRow <= 0)); then continue; fi
doBackspace ' '
((recognizedKeystrokes++))
# ...it's an escape...
elif [ "$inputChar" = $'\E' ]; then # ESCAPE SEQUENCE
local escapeSequence
if ((${#cache} > 0)); then
local escapeSequence="$cache"
cache=
local fChunkedInput='false'
else
read -rsN $MAX_READ_INT -u $INPUT_FD -t .01 escapeSequence
local fChunkedInput='true'
fi
# From the end of cache, search for the longest matching escape sequence.
for ((iEsc = ${#escapeSequence}; iEsc > 0; iEsc--)); do
cache="${escapeSequence:$iEsc}$cache"
escapeSequence="${escapeSequence:0:$iEsc}"
if [ "${CTR_SEQ[home]}" = $'\e'"$escapeSequence" ]; then
# TODO: allow non-destructive scroll-back
##region################################# Actual Output #################################
# local -i currCol
# for ((currCol=$(getCurrInputColNum); currCol > 0; currCol--)); do
# logicalScrollLeft
# done; unset currCol
##endregion############################## Actual Output #################################
##region################################# Debug Output #################################
inputChar='H'
preDisplay+="$(tput setab "${TPUT_COLOR[BLUE]}")"
postDisplay+="$RESET_COLOR_BACKGROUND"
_addToOutput
##endregion############################## Debug Output #################################
break
elif [ "${CTR_SEQ[end]}" = $'\e'"$escapeSequence" ]; then
# TODO: Implement
##region################################# Debug Output #################################
inputChar='E'
preDisplay+="$(tput setab "${TPUT_COLOR[BLUE]}")"
postDisplay+="$RESET_COLOR_BACKGROUND"
_addToOutput
##endregion############################## Debug Output #################################
break
elif [ "${CTR_SEQ[left]}" = $'\e'"$escapeSequence" ]; then
# TODO: allow non-destructive scroll-back
##region################################# Debug Output #################################
inputChar='L'
preDisplay+="$(tput setab "${TPUT_COLOR[BLUE]}")"
postDisplay+="$RESET_COLOR_BACKGROUND"
visualAddToOutput
##endregion############################## Debug Output #################################
logicalScrollLeft
break
fi
done
# If a match wasn't found...
if ((iEsc <= 0)); then
# # ...and cache is empty, only an escape (& maybe 1 char) was sent; it's likely the Esc key was pressed
# if ((${#cache} <= 0)); then
# ...and sequence is empty, only an escape was sent; it's likely the Esc key was pressed
if ((${#escapeSequence} <= 0)); then
echo &>'/dev/null' # Do nothing
# ...and the entirety of the input stream was read at once, then use that as the failed sequence
elif eval "$fChunkedInput"; then
invalidCharacter "$escapeSequence$cache"
cache=
else invalidCharacter "$escapeSequence"; fi
else ((recognizedKeystrokes++)); fi
unset escapeSequence iEsc fChunkedInput
# ...it's a different printable character than expected...
elif [[ "$inputChar" =~ ^[[:print:]]$ ]]; then # Incorrect character
##region################################# Add to history #################################
((recognizedKeystrokes++))
((allMistakesCount++))
local mistakeId="$(getCoord):$inputChar"
if [ -n "${mistakeContext[$mistakeId]}" ]; then
((mistakeContext[$mistakeId]++))
else ((mistakeContext[$mistakeId]=1)); fi
local mistakeId="$(getTestChar):$inputChar"
if [ -n "${mistakeFreq[$mistakeId]}" ]; then
((mistakeFreq[$mistakeId]++))
else ((mistakeFreq[$mistakeId]=1)); fi
unset mistakeId
##endregion############################## Add to history #################################
# Output
preDisplay+="$(tput setaf "${TPUT_COLOR[RED]}")"
setInputColor "${TPUT_COLOR[RED]}"
if [ "$inputChar" = ' ' ]; then
preDisplay+="$(tput smso)"
postDisplay="$(tput rmso)$postDisplay"
inputChar="_"
fi
_addToOutput
# ...otherwise, it's a non-printable character that isn't a recognized control character.
else
invalidCharacter
fi
# if ((currUpdateTime - lastStatusUpdateTime > REFRESH_INTERVAL)); then
printStatus # --wordTimesLength
((lastStatusUpdateTime=currUpdateTime))
# fi
((lastUpdateTime=currUpdateTime))
done
}
while ((currRow < rows)); do _update; done
doExit