-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.bash
More file actions
executable file
·709 lines (669 loc) · 36.9 KB
/
Copy pathclock.bash
File metadata and controls
executable file
·709 lines (669 loc) · 36.9 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
#!/usr/bin/env bash
# -----------------------------------------------------------
TITLE="Terminal Clock"
AUTHOR="S. Widmer"
EMAIL="sery@solnet.ch"
VERSION="v0.50"
LICENSE="GNU GPLv3+"
# -----------------------------------------------------------
#
# Initial default values
#
COLOR="red"
STYLE=80
ALARM=""
STOPWATCH=""
COUNTDOWN=""
STATUSBAR=1
# map color names -> ANSI codes (0-15 supported -> 30-37,90-97)
declare -A _COLORS=(
[black]=30 [red]=31 [green]=32 [yellow]=33 [blue]=34 [magenta]=35 [cyan]=36 [white]=37
[bright_black]=90 [bright_red]=91 [bright_green]=92 [bright_yellow]=93 [bright_blue]=94 [bright_magenta]=95 [bright_cyan]=96 [bright_white]=97
)
# function: set COLOR_ESC from $COLOR (supports names, 0-15, ANSI codes 30-37/90-97, #RRGGBB, and R,G,B)
set_color_escape() {
local val="$COLOR"
# hex #RRGGBB
if [[ "$val" == \#* ]]; then
local h=${val#'#'}
if [[ ! $h =~ ^[0-9A-Fa-f]{6}$ ]]; then
printf "Invalid color value: %s\n" "$val" >&2
exit 1
fi
local r=$((16#${h:0:2}))
local g=$((16#${h:2:2}))
local b=$((16#${h:4:2}))
COLOR_ESC="\e[38;2;${r};${g};${b}m"
return
fi
# rgb "R,G,B" (0-255)
if [[ "$val" =~ ^([0-9]{1,3}),([0-9]{1,3}),([0-9]{1,3})$ ]]; then
local r=${BASH_REMATCH[1]}
local g=${BASH_REMATCH[2]}
local b=${BASH_REMATCH[3]}
for comp in "$r" "$g" "$b"; do
if (( comp < 0 || comp > 255 )); then
printf "Invalid RGB component: %s\n" "$comp" >&2
exit 1
fi
done
COLOR_ESC="\e[38;2;${r};${g};${b}m"
return
fi
# numeric: 0-15 -> map to 30..37 / 90..97; also accept 30-37 or 90-97 directly
if [[ "$val" =~ ^[0-9]+$ ]]; then
local n=$val
if (( n >= 0 && n <= 15 )); then
local code
if (( n < 8 )); then code=$((30 + n)); else code=$((90 + n - 8)); fi
COLOR_ESC="\e[${code}m"
return
elif (( (n >= 30 && n <= 37) || (n >= 90 && n <= 97) )); then
COLOR_ESC="\e[${n}m"
return
fi
printf "Unknown numeric color: %s\n" "$val" >&2
exit 1
fi
# named colors (case-insensitive)
local key="${val,,}"
if [[ -n "${_COLORS[$key]}" ]]; then
COLOR_ESC="\e[${_COLORS[$key]}m"
return
fi
printf "Unknown color: %s\n" "$val" >&2
exit 1
}
#
# parse command line arguments
#
while [[ $# -gt 0 ]]; do
case "$1" in
--style=*)
val="${1#--style=}"
val="${val,,}" # lowercase for case-insensitive matching
case "$val" in
50|e-13b) STYLE=50 ;;
51|e-13b-simple) STYLE=51 ;;
55|nixie) STYLE=55 ;;
60|ocr-a) STYLE=60 ;;
61|ocr-a-simple) STYLE=61 ;;
70|data-70) STYLE=70 ;;
71|data-70-simple) STYLE=71 ;;
72|segment|7-segment) STYLE=72 ;;
73|segment-thin|7-segment-thin) STYLE=73 ;;
74|segment-rounded|7-segment-rounded) STYLE=74 ;;
78|vt100) STYLE=78 ;;
82|thin) STYLE=82 ;;
83|vt220) STYLE=83 ;;
84|numbers) STYLE=84 ;;
85|hashes) STYLE=85 ;;
87|vt320) STYLE=87 ;;
88|dots) STYLE=88 ;;
90|modern) STYLE=90 ;;
80|default) STYLE=80 ;;
*)
printf "Unknown style: %s\nUse '%s --help' for help\n\n" "$val" "$(basename "$0")"
exit 1 ;;
esac
shift ;;
--color=*)
COLOR="${1#--color=}"
shift ;;
--alarm=*)
ALARM="${1#--alarm=}"
shift ;;
--countdown=*)
COUNTDOWN="${1#--countdown=}"
shift ;;
--statusbar=*)
STATUSBAR="${1#--statusbar=}"
shift ;;
--stopwatch=*)
STOPWATCH="${1#--stopwatch=}"
shift ;;
-h|--help) printf '\nChoose one of the following options:'
printf '\n --alarm=<HH:MM> \tSet alarm time (24h format), e.g., --alarm=07:30'
printf '\n --stopwatch=<triggerword> \t\tStart stopwatch mode, e.g., --stopwatch=start'
printf '\n --countdown=<HH:MM:SS> \tSet Countdown (24h format), e.g., --countdown=00:05:00\n\n'
printf '\n --style=<style> \tSupported styles:'
printf '\n --style=50 or --style=E-13B \t\tMagnetic MICR E-13B font'
printf '\n --style=51 or --style=E-13B-simple \tas above but blocks only version'
printf '\n --style=55 or --style=NIXIE \t\tnixie tube font'
printf '\n --style=60 or --style=OCR-A \t\tOCR-A font'
printf '\n --style=61 or --style=OCR-A-SIMPLE \tas above but blocks only version'
printf '\n --style=70 or --style=DATA-70 \ta futuristic font'
printf '\n --style=71 or --style=DATA-70-SIMPLE \tas above blocks only version'
printf '\n --style=72 or --style=7-SEGMENT \tseven segment display font'
printf '\n --style=73 or --style=7-SEGMENT-THIN \tseven segment display font, thin version'
printf '\n --style=74 or --style=7-SEGMENT-ROUNDED \tseven segment display font, rounded version'
printf '\n --style=78 or --VT100 \t\tVT100 font'
printf '\n --style=80 or --default \t\tdefault 80ies font'
printf '\n --style=82 or --thin \t\tThin font'
printf '\n --style=83 or --VT220 \t\tVT220 font'
printf '\n --style=84 or --NUMBERS \t\tnumbers font'
printf '\n --style=85 or --HASHES \t\thashes font'
printf '\n --style=87 or --VT320 \t\tVT320 font'
printf '\n --style=88 or --DOTS \t\tdots font'
printf '\n --style=90 or --MODERN \t\tmodern font'
printf '\n\n --color=<color> \t\tSet display color (default: red)\n'
printf '\nSupported:\n1. named colors: \n%s' "$(printf '%s ' "${!_COLORS[@]}")"
printf '\n\n2. numeric 0-15\n\n3. ANSI codes 30-37/90-97\n\n4. hex #RRGGBB\n\n5. R,G,B (0-255)\n\n'
printf "Example: %s --style=70 --color=red\n\n" "$(basename "$0")"; exit 0 ;;
*) printf "Unknown option: %s\nUse '%s --help' for help\n\n" "$1" "$(basename "$0")"; exit 1 ;;
#*) break ;;
esac
done
# Either alarm or stopwatch or countdown can be set, not more than one
if [[ -n "$ALARM" && -n "$STOPWATCH" ]] || [[ -n "$ALARM" && -n "$COUNTDOWN" ]] || [[ -n "$STOPWATCH" && -n "$COUNTDOWN" ]]; then
printf "Error: You can set either --alarm, --countdown, or --stopwatch, but not combining them\n\n"
exit 1
fi
# compute COLOR_ESC (escape sequence used to color the output)
set_color_escape
# declare an array
declare -A D
if [[ "$STYLE" -eq 50 ]]; then
D[0]=$' █▀▀▀▀█\n █ █\n █ █\n █ █\n █▄▄▄▄█'
D[1]=$' ██ \n █ \n █ \n ████\n ████'
D[2]=$' ▀▀▀▀█\n █\n █▀▀▀▀\n █ \n █▄▄▄▄'
D[3]=$' ▀▀▀█ \n █ \n ▀▀▀█▄\n ██\n ▄▄▄██'
D[4]=$' ██ \n ██ \n ██ \n ██▄▄██\n ██'
D[5]=$' █▀▀▀▀ \n █ \n ▀▀▀▀█ \n █ \n ▄▄▄▄█ '
D[6]=$' █▀▀█ \n █ \n █ \n █▀▀▀▀█\n █▄▄▄▄█'
D[7]=$' █▀▀▀█ \n ▀ ◢◤ \n ◢◤ \n █ \n █ '
D[8]=$' █▀▀▀█ \n █ █ \n◢█▀▀▀█◣\n██ ██\n██▄▄▄██'
D[9]=$' █▀▀▀▀█\n █ █\n ▀▀▀▀██\n ██\n ██'
D[:]=$' \n ██\n \n ██\n '
D[.]=$' \n \n \n \n ██'
elif [[ "$STYLE" -eq 51 ]]; then
D[0]=$' █▀▀▀▀█\n █ █\n █ █\n █ █\n █▄▄▄▄█'
D[1]=$' ██ \n █ \n █ \n ████\n ████'
D[2]=$' ▀▀▀▀█\n █\n █▀▀▀▀\n █ \n █▄▄▄▄'
D[3]=$' ▀▀▀█ \n █ \n ▀▀▀█▄\n ██\n ▄▄▄██'
D[4]=$' ██ \n ██ \n ██ \n ██▄▄██\n ██'
D[5]=$' █▀▀▀▀ \n █ \n ▀▀▀▀█ \n █ \n ▄▄▄▄█ '
D[6]=$' █▀▀█ \n █ \n █ \n █▀▀▀▀█\n █▄▄▄▄█'
D[7]=$' █▀▀▀█ \n ▀ ▗▘ \n ▗▘ \n █ \n █ '
D[8]=$' █▀▀▀█ \n █ █ \n▗█▀▀▀█▖\n██ ██\n██▄▄▄██'
D[9]=$' █▀▀▀▀█\n █ █\n ▀▀▀▀██\n ██\n ██'
D[:]=$' \n ██\n \n ██\n '
D[.]=$' \n \n \n \n ██'
elif [[ "$STYLE" -eq 55 ]]; then
D[0]=$' ▄▀▀▀▄ \n█ █\n█ █\n█ █\n ▀▄▄▄▀ '
D[1]=$' █ \n █ \n █ \n █ \n █ '
D[2]=$' ▄▀▀▄ \n ▀ █\n ▄▄▀ \n ▄▀ \n █▄▄▄▄▄'
D[3]=$' ▀▀▀▀▀█\n ▄▀ \n ▀▄\n █\n ▀▄▄▄▀ '
D[4]=$' ▄█ \n ▄▀ █ \n▄▀ █ \n▀▀▀▀▀█▀\n █ '
D[5]=$' █▀▀▀▀ \n █▄▄▄ \n ▀ ▀▄\n █\n ▀▄▄▄▀ '
D[6]=$' ▄▀ \n ▄█▄▄ \n▄▀ ▀▄\n█ █\n ▀▄▄▄▀ '
D[7]=$' ▀▀▀▀▀█\n █ \n █ \n █ \n █ '
D[8]=$' ▄▀▀▀▄ \n▀▄ ▄▀\n ▄▀▀▀▄ \n█ █\n ▀▄▄▄▀ '
D[9]=$' ▄▀▀▀▄ \n█ █\n▀▄ ▄▀\n ▀█▀ \n ▄▀ '
D[:]=$' \n ▄ \n \n ▄ \n '
D[.]=$' \n \n \n \n ▄ '
elif [[ "$STYLE" -eq 60 ]]; then
D[0]=$' █▀▀▀▀█\n █ █\n █ █\n █ █\n █▄▄▄▄█'
D[1]=$' ▀▀█ \n █ \n █ \n █ ▄ \n ▄▄█▄█ '
D[2]=$' ▀▀▀▀▀█\n █\n █▀▀▀▀▀\n █ \n █▄▄▄▄▄'
D[3]=$' ▀▀▀▀▀█\n █\n ▀▀▀▀█\n █\n ▄▄▄▄▄█'
D[4]=$' █ ▄ \n █ █ \n █▄▄▄█▄\n █ \n █ '
D[5]=$' █▀▀▀ \n █ \n ▀▀▀█ \n █ \n █▄▄▄█ '
D[6]=$' █▀ \n █ \n █ \n █▀▀▀█ \n █▄▄▄█ '
D[7]=$' █▀▀▀█ \n ◢◤ \n ◢◤ \n █ \n █ '
D[8]=$' █▀█ \n █ █ \n █▀▀▀█ \n █ █ \n █▄▄▄█ '
D[9]=$' █▀▀▀█ \n █ █ \n ▀▀▀▀█ \n █ \n ▄█ '
D[:]=$' \n ██\n \n ██\n '
D[.]=$' \n \n \n \n ██'
elif [[ "$STYLE" -eq 61 ]]; then
D[0]=$' █▀▀▀▀█\n █ █\n █ █\n █ █\n █▄▄▄▄█'
D[1]=$' ▀▀█ \n █ \n █ \n █ ▄ \n ▄▄█▄█ '
D[2]=$' ▀▀▀▀▀█\n █\n █▀▀▀▀▀\n █ \n █▄▄▄▄▄'
D[3]=$' ▀▀▀▀▀█\n █\n ▀▀▀▀█\n █\n ▄▄▄▄▄█'
D[4]=$' █ ▄ \n █ █ \n █▄▄▄█▄\n █ \n █ '
D[5]=$' █▀▀▀ \n █ \n ▀▀▀█ \n █ \n █▄▄▄█ '
D[6]=$' █▀ \n █ \n █ \n █▀▀▀█ \n █▄▄▄█ '
D[7]=$' █▀▀▀█ \n ▗▘ \n ▗▘ \n █ \n █ '
D[8]=$' █▀█ \n █ █ \n █▀▀▀█ \n █ █ \n █▄▄▄█ '
D[9]=$' █▀▀▀█ \n █ █ \n ▀▀▀▀█ \n █ \n ▄█ '
D[:]=$' \n ██\n \n ██\n '
D[.]=$' \n \n \n \n ██'
elif [[ "$STYLE" -eq 70 ]]; then
D[0]=$' █▀▀▀▀█\n █ █\n █ ◢█\n █ ██\n █▄▄▄██'
D[1]=$' █ \n █ \n ◢█ \n ██ \n ██ '
D[2]=$' █▀▀▀▀█\n █\n ▄▄▄▄▄█\n ██ \n ██▄▄▄▄'
D[3]=$' █▀▀▀█ \n █ \n ▀▀▀█◣\n ██\n █▄▄▄██'
D[4]=$' █ █ \n █ █ \n █ █ \n ▀▀▀██▀\n ██ '
D[5]=$' █▀▀▀▀ \n █ \n ▀▀▀▀██\n ██\n █▄▄▄██'
D[6]=$' █▀▀▀▀█\n █ \n █▀▀▀██\n █ ██\n █▄▄▄██'
D[7]=$' ▀▀▀▀▀█\n █\n ◢█\n ██\n ██'
D[8]=$' █▀▀█ \n █ █ \n ◢▀▀▀█◣\n █ ██\n █▄▄▄██'
D[9]=$' █▀▀▀▀█\n █ █\n █ █\n ▀▀▀▀██\n ██'
D[:]=$' \n ██\n \n ██\n '
D[.]=$' \n \n \n \n ██'
elif [[ "$STYLE" -eq 71 ]]; then
D[0]=$' █▀▀▀▀█\n █ █\n █ ▗█\n █ ██\n █▄▄▄██'
D[1]=$' █ \n █ \n ▗█ \n ██ \n ██ '
D[2]=$' █▀▀▀▀█\n █\n ▄▄▄▄▄█\n ██ \n ██▄▄▄▄'
D[3]=$' █▀▀▀█ \n █ \n ▀▀▀█▖\n ██\n █▄▄▄██'
D[4]=$' █ █ \n █ █ \n █ █ \n ▀▀▀██▀\n ██ '
D[5]=$' █▀▀▀▀ \n █ \n ▀▀▀▀██\n ██\n █▄▄▄██'
D[6]=$' █▀▀▀▀█\n █ \n █▀▀▀██\n █ ██\n █▄▄▄██'
D[7]=$' ▀▀▀▀▀█\n █\n ▗█\n ██\n ██'
D[8]=$' █▀▀█ \n █ █ \n ▗▀▀▀█▖\n █ ██\n █▄▄▄██'
D[9]=$' █▀▀▀▀█\n █ █\n █ █\n ▀▀▀▀██\n ██'
D[:]=$' \n ██\n \n ██\n '
D[.]=$' \n \n \n \n ██'
elif [[ "$STYLE" -eq 72 ]]; then
D[0]=$' █▀▀▀▀█\n █ █\n █ █\n █ █\n █▄▄▄▄█'
D[1]=$' █\n █\n █\n █\n █'
D[2]=$' ▀▀▀▀▀█\n █\n █▀▀▀▀▀\n █ \n █▄▄▄▄▄'
D[3]=$' ▀▀▀▀▀█\n █\n ▀▀▀▀█\n █\n ▄▄▄▄▄█'
D[4]=$' █ █\n █ █\n ▀▀▀▀▀█\n █\n █'
D[5]=$' █▀▀▀▀▀\n █ \n ▀▀▀▀▀█\n █\n ▄▄▄▄▄█'
D[6]=$' █▀▀▀▀▀\n █ \n █▀▀▀▀█\n █ █\n █▄▄▄▄█'
D[7]=$' ▀▀▀▀▀█\n █\n █\n █\n █'
D[8]=$' █▀▀▀▀█\n █ █\n █▀▀▀▀█\n █ █\n █▄▄▄▄█'
D[9]=$' █▀▀▀▀█\n █ █\n ▀▀▀▀▀█\n █\n ▄▄▄▄▄│'
D[:]=$' \n ▄\n \n ▄\n '
D[.]=$' \n \n \n \n ▄'
elif [[ "$STYLE" -eq 73 ]]; then
D[0]=$'┌────┐\n│ │\n│ │\n│ │\n└────┘'
D[1]=$' ╷\n │\n │\n │\n ╵'
D[2]=$'╶────┐\n │\n┌────┘\n│ \n└────╴'
D[3]=$'╶────┐\n │\n╶────┤\n │\n╶────┘'
D[4]=$'╷ ╷\n│ │\n└────┤\n │\n ╵'
D[5]=$'┌────╴\n│ \n└────┐\n │\n╶────┘'
D[6]=$'┌────╴\n│ \n├────┐\n│ │\n└────┘'
D[7]=$'╶────┐\n │\n │\n │\n ╵'
D[8]=$'┌────┐\n│ │\n├────┤\n│ │\n└────┘'
D[9]=$'┌────┐\n│ │\n└────┤\n │\n╶────┘'
D[:]=$' \n▪\n \n▪\n '
D[.]=$' \n \n \n \n▪'
elif [[ "$STYLE" -eq 74 ]]; then
D[0]=$'╭────╮\n│ │\n│ │\n│ │\n╰────╯'
D[1]=$' ╷\n │\n │\n │\n ╵'
D[2]=$'╶────╮\n │\n╭────╯\n│ \n╰────╴'
D[3]=$'╶────╮\n │\n╶────┤\n │\n╶────╯'
D[4]=$'╷ ╷\n│ │\n╰────┤\n │\n ╵'
D[5]=$'╭────╴\n│ \n╰────╮\n │\n╶────╯'
D[6]=$'╭────╴\n│ \n├────╮\n│ │\n╰────╯'
D[7]=$'╶────╮\n │\n │\n │\n ╵'
D[8]=$'╭────╮\n│ │\n├────┤\n│ │\n╰────╯'
D[9]=$'╭────╮\n│ │\n╰────┤\n │\n╶────╯'
D[:]=$' \n▪\n \n▪\n '
D[.]=$' \n \n \n \n▪'
elif [[ "$STYLE" -eq 78 ]]; then
D[0]=$'\n ▄▀▀▀▄ \n█ █\n▀▄ ▄▀\n ▀▀▀ '
D[1]=$'\n ▄█ \n ▀ █ \n █ \n ▀▀▀▀▀ '
D[2]=$'\n▄▀▀▀▀▄ \n ▄▄▄▀\n▄▀▀ \n▀▀▀▀▀▀▀'
D[3]=$'\n▀▀▀▀▀█▀\n ▄█▄ \n▄ █\n ▀▀▀▀▀ '
D[4]=$'\n ▄█ \n ▄▀ █ \n▀▀▀▀█▀▀\n ▀ '
D[5]=$'\n█▀▀▀▀▀▀\n█▄▀▀▀▀▄\n▄ █\n ▀▀▀▀▀ '
D[6]=$'\n ▄▀▀▀▀▄\n█ ▄▄▄▄ \n█▀ █\n ▀▀▀▀▀ '
D[7]=$'\n▀▀▀▀▀▀█\n ▄▀ \n ▄▀ \n ▀ '
D[8]=$'\n▄▀▀▀▀▀▄\n▀▄▄▄▄▄▀\n█ █\n ▀▀▀▀▀ '
D[9]=$'\n▄▀▀▀▀▄ \n▀▄▄▄▄▀█\n▄ ▄▀\n ▀▀▀▀ '
D[:]=$'\n ▄▄ \n ▀▀ \n ██ \n '
D[.]=$'\n \n \n ▄▄ \n ▀▀ '
elif [[ "$STYLE" -eq 90 ]]; then
D[0]=$' ▄▀▀▄ \n █ █\n █ █\n █ █\n ▀▄▄▀ '
D[1]=$' ▄█ \n ▄▀ █ \n █ \n █ \n █ '
D[2]=$' ▄▀▀▄ \n ▀ █\n ▄▀ \n ▄▀ \n █▄▄▄▄▄'
D[3]=$' ▄▀▀▀▄ \n ▄▀\n ▀▀▀▄ \n █\n ▀▄▄▄▀ '
D[4]=$' ▄█ \n ▄▀ █ \n █▄▄▄█▄\n █ \n █ '
D[5]=$' █▀▀▀▀ \n █ \n ▀▀▀▀▄ \n █\n ▀▄▄▄▀ '
D[6]=$' ▄▀▀▄ \n █ \n █▄▀▀▄ \n █ █\n ▀▄▄▀ '
D[7]=$' ▀▀▀▀▀█\n █ \n █ \n █ \n █ '
D[8]=$' ▄▀▀▄ \n ▀▄ ▄▀\n ▄▀▀▄ \n █ █\n ▀▄▄▀ '
D[9]=$' ▄▀▀▄ \n █ █\n ▀▄▄▀█\n █\n ▀▄▄▄▀ '
D[:]=$' \n ▄\n \n ▄\n '
D[.]=$' \n \n \n \n ▄'
elif [[ "$STYLE" -eq 82 ]]; then
D[0]=$' ▄▀▀▀▀▄\n █ ▗▖ █\n █ ▐▌ █\n █ ▝▘ █\n ▀▄▄▄▄▀'
D[1]=$' ▄█ \n ▄▀ █ \n █ \n █ \n █ '
D[2]=$' ▄▀▀▀▀▄\n █\n ▄▀ \n ▄▀ \n █▄▄▄▄▄'
D[3]=$' ▄▀▀▀▀▄\n █\n ▀▀▀▀▄\n █\n ▀▄▄▄▄▀'
D[4]=$' ▄█ \n ▄▀ █ \n █▄▄▄█▄\n █ \n █ '
D[5]=$' █▀▀▀▀ \n █ \n ▀▀▀▀▀▄\n █\n ▀▄▄▄▄▀'
D[6]=$' ▄▀▀▀▀▄\n █ \n █▀▀▀▀▄\n █ █\n ▀▄▄▄▄▀'
D[7]=$' ▀▀▀▀▀█\n █ \n █ \n █ \n █ '
D[8]=$' ▄▀▀▀▀▄\n █ █\n ▄▀▀▀▀▄\n █ █\n ▀▄▄▄▄▀'
D[9]=$' ▄▀▀▀▀▄\n █ █\n ▀▀▀▀█\n █\n ▀▄▄▄▄▀'
D[:]=$' \n ▀\n \n ▀\n '
D[.]=$' \n \n \n \n ▄'
elif [[ "$STYLE" -eq 83 ]]; then
D[0]=$'\n ▄▀▀▀▄ \n█ █\n▀▄ ▄▀\n ▀▀▀ '
D[1]=$'\n ▄█ \n ▀ █ \n █ \n ▀▀▀▀▀ '
D[2]=$'\n▄▀▀▀▀▀▄\n ▄▄▄▀\n▄▀▀ \n▀▀▀▀▀▀▀'
D[3]=$'\n▀▀▀▀▀█▀\n ▄█▄ \n▄ █\n ▀▀▀▀▀ '
D[4]=$'\n ▄█ \n ▄▀ █ \n▀▀▀▀█▀▀\n ▀ '
D[5]=$'\n█▀▀▀▀▀▀\n█▄▀▀▀▀▄\n▄ █\n ▀▀▀▀▀ '
D[6]=$'\n ▄▀▀▀▀ \n█ ▄▄▄▄ \n█▀ █\n ▀▀▀▀▀ '
D[7]=$'\n▀▀▀▀▀▀█\n ▄▀ \n ▄▀ \n ▀ '
D[8]=$'\n▄▀▀▀▀▀▄\n▀▄▄▄▄▄▀\n█ █\n ▀▀▀▀▀ '
D[9]=$'\n▄▀▀▀▀▀▄\n▀▄▄▄▄▀█\n ▄▀\n ▀▀▀▀ '
D[:]=$'\n ▄▄ \n ▀▀ \n ██ \n '
D[.]=$'\n \n \n ▄▄ \n ▀▀ '
elif [[ "$STYLE" -eq 84 ]]; then
D[0]=$' 000000\n 00 00\n 00 00\n 00 00\n 000000'
D[1]=$' 11 \n 11 \n 11 \n 11 \n 11 '
D[2]=$' 222222\n 22\n 222222\n 22 \n 222222'
D[3]=$' 333333\n 33\n 333333\n 33\n 333333'
D[4]=$' 44 44\n 44 44\n 444444\n 44\n 44'
D[5]=$' 555555\n 55 \n 555555\n 55\n 555555'
D[6]=$' 666666\n 66 \n 666666\n 66 66\n 666666'
D[7]=$' 777777\n 77\n 77\n 77\n 77'
D[8]=$' 888888\n 88 88\n 888888\n 88 88\n 888888'
D[9]=$' 999999\n 99 99\n 999999\n 99\n 999999'
D[:]=$' \n #\n \n #\n '
D[.]=$' \n \n \n \n #'
elif [[ "$STYLE" -eq 85 ]]; then
D[0]=$' ######\n ## ##\n ## ##\n ## ##\n ######'
D[1]=$' ## \n ## \n ## \n ## \n ## '
D[2]=$' ######\n ##\n ######\n ## \n ######'
D[3]=$' ######\n ##\n ######\n ##\n ######'
D[4]=$' ## ##\n ## ##\n ######\n ##\n ##'
D[5]=$' ######\n ## \n ######\n ##\n ######'
D[6]=$' ######\n ## \n ######\n ## ##\n ######'
D[7]=$' ######\n ##\n ##\n ##\n ##'
D[8]=$' ######\n ## ##\n ######\n ## ##\n ######'
D[9]=$' ######\n ## ##\n ######\n ##\n ######'
D[:]=$' \n #\n \n #\n '
D[.]=$' \n \n \n \n #'
elif [[ "$STYLE" -eq 87 ]]; then
D[0]=$'\n ▄▀▀▄ \n ██ ██ \n ▀█ █▀ \n ▀▀ '
D[1]=$'\n ▄▄██ \n ██ \n ██ \n ▀▀▀▀▀▀ '
D[2]=$'\n ▄▀▀▀█▄ \n ▄█▀ \n ▄█▀ \n ▀▀▀▀▀▀ '
D[3]=$'\n ▄█▀▀▀█▄\n ▄▄▄█▀\n ▄▄ ██\n ▀▀▀▀▀ '
D[4]=$'\n ▄▀██ \n ▄▀ ██ \n▀▀▀▀▀██▀\n ▀▀ '
D[5]=$'\n██▀▀▀▀ \n██▄▀▀█▄ \n▄ ▄█▀\n ▀▀▀▀▀ '
D[6]=$'\n ▄▄▀▀▀ \n██ ▄▄▄ \n▀██ ██\n ▀▀▀▀▀ '
D[7]=$'\n ▀▀▀▀▀██\n ▄█▀ \n ▄█▀ \n ▀▀ '
D[8]=$'\n ▄█▀▀█▄ \n ▀█▄▄█▀ \n ██ ██ \n ▀▀▀▀ '
D[9]=$'\n▄█▀▀█▄ \n▀█▄▄█▀█▄\n ▄█▀\n ▀▀▀▀▀ '
D[:]=$'\n ▄▄ \n ▀▀ \n ██ \n '
D[.]=$'\n \n \n ▄▄ \n ▀▀ '
elif [[ "$STYLE" -eq 88 ]]; then
D[0]=$' ● ● \n ● ● \n ● ● \n ● ● \n ● ● '
D[1]=$' ● \n ● ● \n ● \n ● \n ● ● ● '
D[2]=$' ● ● \n ● ● \n ● \n ● \n ● ● ● ● '
D[3]=$' ● ● ● \n ● \n ● ● \n ● \n ● ● ● '
D[4]=$' ● ● \n ● ● \n ● ● ● ● \n ● \n ● '
D[5]=$' ● ● ● \n ● \n ● ● ● \n ● \n ● ● ● '
D[6]=$' ● ● \n ● \n ● ● ● \n ● ● \n ● ● '
D[7]=$' ● ● ● ● \n ● \n ● \n ● \n ● '
D[8]=$' ● ● \n ● ● \n ● ● \n ● ● \n ● ● '
D[9]=$' ● ● \n ● ● \n ● ● ● \n ● \n ● ● '
D[:]=$' \n ● \n \n ● \n '
D[.]=$' \n \n \n \n ● '
# Define digit representations for style 80ies
else
D[0]=$' ██████\n ██ ██\n ██ ██\n ██ ██\n ██████'
D[1]=$' ██\n ██\n ██\n ██\n ██'
D[2]=$' ██████\n ██\n ██████\n ██ \n ██████'
D[3]=$' ██████\n ██\n ██████\n ██\n ██████'
D[4]=$' ██ ██\n ██ ██\n ██████\n ██\n ██'
D[5]=$' ██████\n ██ \n ██████\n ██\n ██████'
D[6]=$' ██████\n ██ \n ██████\n ██ ██\n ██████'
D[7]=$' ██████\n ██\n ██\n ██\n ██'
D[8]=$' ██████\n ██ ██\n ██████\n ██ ██\n ██████'
D[9]=$' ██████\n ██ ██\n ██████\n ██\n ██████'
D[:]=$' \n ██\n \n ██\n '
D[.]=$' \n \n \n \n ██'
fi
# Hide cursor (civis:cursor_invisible) and ensure it is restored on exit (cnorm:cursor_normal)
tput civis
trap 'tput cnorm; printf "\n"; exit' INT TERM EXIT ERR HUP
# Clear once, then update in-place
printf '\033[2J' # clear screen
prev=""
prev_cols=$(tput cols)
prev_lines=$(tput lines)
while true; do
# detect terminal resize and force a redraw when it happens
cur_cols=$(tput cols)
cur_lines=$(tput lines)
resized=0
if (( cur_cols != prev_cols || cur_lines != prev_lines )); then
prev_cols=$cur_cols
prev_lines=$cur_lines
resized=1
prev="" # force redraw even if time hasn't changed
printf '\033[2J' # clear screen to avoid artifacts
fi
now=$(date +"%H:%M:%S")
if [[ "$now" != "$prev" ]] || (( resized )); then
prev="$now"
# prepare 5 rows for time
rows=("" "" "" "" "")
for ((i=0;i<${#now};i++)); do
ch=${now:i:1}
digit="${D[$ch]}"
readarray -t lines <<< "$digit"
rows[0]+="${lines[0]} "
rows[1]+="${lines[1]} "
rows[2]+="${lines[2]} "
rows[3]+="${lines[3]} "
rows[4]+="${lines[4]} "
done
# prepare 5 rows for date (DD.MM.YYYY)
date_str=$(date +"%d.%m.%Y")
date_rows=("" "" "" "" "")
for ((i=0;i<${#date_str};i++)); do
ch=${date_str:i:1}
digit="${D[$ch]}"
readarray -t lines <<< "$digit"
date_rows[0]+="${lines[0]} "
date_rows[1]+="${lines[1]} "
date_rows[2]+="${lines[2]} "
date_rows[3]+="${lines[3]} "
date_rows[4]+="${lines[4]} "
done
# move cursor to top-left and print (no whole-screen clear)
printf '\033[H'
printf '\n' # small top padding
printf '%b%b%b\n' "$COLOR_ESC" " ${rows[0]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${rows[1]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${rows[2]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${rows[3]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${rows[4]}" $'\e[0m'
# separator line
cols=$(tput cols)
printf '\n%b' "$COLOR_ESC"
printf -v __bar '%*s' "$cols" ''
__bar=${__bar// /━}
printf '%s' "$__bar"
printf '%b\n\n' $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${date_rows[0]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${date_rows[1]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${date_rows[2]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${date_rows[3]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${date_rows[4]}" $'\e[0m'
# separator line
printf '\n%b' "$COLOR_ESC"
printf -v __bar '%*s' "$cols" ''
__bar=${__bar// /━}
printf '%s' "$__bar"
#printf '%b\n\n' $'\e[0m'
#
# Alarm handling
#
# separator line if alarm is set
if [ "$ALARM" ]; then
if ! [[ "$ALARM" =~ ^([01][0-9]|2[0-3]):[0-5][0-9]$ ]]; then
ALARM=""
printf '%b\n\n' $'\e[0m'
printf '%b%s%b\n\n' "$COLOR_ESC" " ██ INVALID ALARM TIME FORMAT ██" $'\e[0m'
# get out of here and put terminal back to normal!
tput cnorm
exit 0
# check if alarm time is reached
elif [[ "$now" == "$ALARM:00" ]]; then
ALARM=""
printf '%b\n\n' $'\e[0m' # clear formatting
printf '%b%s%b\n' "$COLOR_ESC" " ██████ ██ ██████ ██████ ██████████ ██" $'\e[0m'
printf '%b%s%b\n' "$COLOR_ESC" " ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██" $'\e[0m'
printf '%b%s%b\n' "$COLOR_ESC" " ██████ ██ ██████ ██████ ██ ██ ██ ██" $'\e[0m'
printf '%b%s%b\n' "$COLOR_ESC" " ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ " $'\e[0m'
printf '%b%s%b\n' "$COLOR_ESC" " ██ ██ █████ ██ ██ ██ ██ ██ ██ ██ ██" $'\e[0m'
# delete status bar
cols=$(tput cols)
lines=$(tput lines)
printf '%s' "$(tput cup $((lines-1)) 0)$(printf '%*s' "$cols" '')"
# get out of here and put terminal back to normal!
tput cnorm
exit 0
#check if alarm is not in the past
elif [[ "$(date -d "$ALARM" +%s)" -lt "$(date +%s)" ]]; then
ALARM=""
printf '%b\n\n' $'\e[0m'
printf '%b%s%b\n\n' "$COLOR_ESC" " ██ ALARM TIME IS IN THE PAST ██" $'\e[0m'
# get out of here and put terminal back to normal!
tput cnorm
exit 0
elif [[ -n "$ALARM" ]]; then
printf '%b\n\n' $'\e[0m'
printf '%b%s%b\n\n' "$COLOR_ESC" " ALARM SET FOR $ALARM..." $'\e[0m'
fi
fi
#
# Countdown handling
#
if [[ "$COUNTDOWN" ]]; then
if ! [[ "$COUNTDOWN" =~ ^([0-9]+):([0-5][0-9]):([0-5][0-9])$ ]]; then
COUNTDOWN=""
printf '%b\n\n' $'\e[0m'
printf '%b%s%b\n\n' "$COLOR_ESC" " ██ INVALID COUNTDOWN TIME FORMAT ██" $'\e[0m'
# get out of here and put terminal back to normal!
tput cnorm
exit 0
fi
# calculate remaining seconds
IFS=':' read -r cd_hours cd_minutes cd_seconds <<< "$COUNTDOWN"
TOTAL_SECONDS=$(( cd_hours * 3600 + cd_minutes * 60 + cd_seconds ))
if [[ -z "$COUNTDOWN_START_TIME" ]]; then
COUNTDOWN_START_TIME=$(date +%s)
fi
ELAPSED=$(( $(date +%s) - COUNTDOWN_START_TIME ))
REMAINING=$(( TOTAL_SECONDS - ELAPSED ))
# check if countdown has reached zero
if (( REMAINING <= 0 )); then
COUNTDOWN=""
printf '%b\n\n' $'\e[0m' # clear formatting
printf '%b%s%b\n' "$COLOR_ESC" " ██████ ██ ██████████ ██████ ██ ██████ ██ ██ ██████ ██" $'\e[0m'
printf '%b%s%b\n' "$COLOR_ESC" " ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██" $'\e[0m'
printf '%b%s%b\n' "$COLOR_ESC" " ██ ██ ██ ██ ██ ████ ██ ██████ ██ ██ ██████ ██" $'\e[0m'
printf '%b%s%b\n' "$COLOR_ESC" " ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ " $'\e[0m'
printf '%b%s%b\n' "$COLOR_ESC" " ██ ██ ██ ██ ██ ██████ ██ ██████ ██████ ██ ██" $'\e[0m'
# delete status bar
cols=$(tput cols)
lines=$(tput lines)
printf '%s' "$(tput cup $((lines-1)) 0)$(printf '%*s' "$cols" '')"
# get out of here and put terminal back to normal!
tput cnorm
exit 0
else
# continue countdown display
HOURS=$(( REMAINING / 3600 ))
MINUTES=$(( (REMAINING % 3600) / 60 ))
SECONDS=$(( REMAINING % 60 ))
# show larger digits for countdown including leading zeros and colon separators
#HOURS=$(printf "%02d" $HOURS)
countdown_rows=("" "" "" "" "")
COUNTDOWN_STR=$(printf "%02d:%02d:%02d" $HOURS $MINUTES $SECONDS)
for ((i=0;i<${#COUNTDOWN_STR};i++)); do
ch=${COUNTDOWN_STR:i:1}
digit="${D[$ch]}"
readarray -t lines <<< "$digit"
countdown_rows[0]+="${lines[0]} "
countdown_rows[1]+="${lines[1]} "
countdown_rows[2]+="${lines[2]} "
countdown_rows[3]+="${lines[3]} "
countdown_rows[4]+="${lines[4]} "
done
printf '%b\n\n' $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${countdown_rows[0]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${countdown_rows[1]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${countdown_rows[2]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${countdown_rows[3]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${countdown_rows[4]}" $'\e[0m'
fi
fi
#
# Stopwatch handling
#
if [[ "$STOPWATCH" == "start" || "$STOPWATCH" == "on" || "$STOPWATCH" == "1" ]]; then
START_TIME=$(date +%s)
# change state to running
STOPWATCH="running"
fi
if [[ "$STOPWATCH" == "running" ]]; then
ELAPSED=$(( $(date +%s) - START_TIME ))
HOURS=$(( ELAPSED / 3600 ))
MINUTES=$(( (ELAPSED % 3600) / 60 ))
SECONDS=$(( ELAPSED % 60 ))
# show larger digits for stopwatch including leading zeros and colon separators
#HOURS=$(printf "%02d" $HOURS)
stopwatch_rows=("" "" "" "" "")
STOPWATCH_STR=$(printf "%02d:%02d:%02d" $HOURS $MINUTES $SECONDS)
for ((i=0;i<${#STOPWATCH_STR};i++)); do
ch=${STOPWATCH_STR:i:1}
digit="${D[$ch]}"
readarray -t lines <<< "$digit"
stopwatch_rows[0]+="${lines[0]} "
stopwatch_rows[1]+="${lines[1]} "
stopwatch_rows[2]+="${lines[2]} "
stopwatch_rows[3]+="${lines[3]} "
stopwatch_rows[4]+="${lines[4]} "
done
#printf '%b%s%b\n' "$COLOR_ESC" " STOPWATCH: " $'\e[0m'
printf '%b\n\n' $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${stopwatch_rows[0]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${stopwatch_rows[1]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${stopwatch_rows[2]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${stopwatch_rows[3]}" $'\e[0m'
printf '%b%b%b\n' "$COLOR_ESC" " ${stopwatch_rows[4]}" $'\e[0m'
fi
#
# Status bar at the bottom
#
if [[ "$STATUSBAR" == 1 || "$STATUSBAR" == "on" || "$STATUSBAR" == "true" || "$STATUSBAR" == "yes" ]]; then
cols=$(tput cols)
lines=$(tput lines)
right_msg="| Q: Quit "
left_msg="${TITLE} ${VERSION}"
left_len=${#left_msg}
right_len=${#right_msg}
pad=$((cols - left_len - right_len))
if (( pad < 1 )); then
# truncate left_msg to make room for right_msg and at least one space
max_left=$((cols - right_len - 1))
(( max_left < 0 )) && max_left=0
left_msg="${left_msg:0:max_left}"
left_len=${#left_msg}
pad=$((cols - left_len - right_len))
(( pad < 0 )) && pad=0
fi
# enforce default terminal colors for status line, not colored
printf '\033[0m'
# move to last row and print reversed full-width status line: left_msg + padding + right_msg
printf '%s' "$(tput cup $((lines-1)) 0)$(tput rev)${left_msg}$(printf '%*s' "$pad" '')${right_msg}$(tput sgr0)"
fi
fi
#
# Key handling
#
# wait a short time (0.2s) and check for a keypress; quit on 'q' or 'Q'
if read -rsn1 -t 0.2 key; then
if [[ $key == 'q' || $key == 'Q' || $key == $'\e' ]]; then
# delete status bar to avoid overwriting the stopwatch time
cols=$(tput cols)
lines=$(tput lines)
printf '%s' "$(tput cup $((lines-1)) 0)$(printf '%*s' "$cols" '')"
# get out of here and put terminal back to normal!
tput cnorm
exit 0
fi
fi
done