-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
show_ascii_art
executable file
·1521 lines (1466 loc) · 41.3 KB
/
show_ascii_art
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
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
#
platform=`uname -s`
if [ "${platform}" == "Darwin" ]
then
TOP="/usr/local/share"
else
TOP="/usr/share"
fi
ARTDIR="${TOP}/asciiville/art"
FIG_FONTS="${TOP}/figlet-fonts"
MUSEDIR="${TOP}/asciiville/music"
FIG_WELCOME="Welcome"
FIG_TO="To"
FIG_ASCII="Asciiville"
FIG_CONT="Press Enter To Continue"
LARGE_FONT="Bolger"
SMALL_FONT="Small"
SONG="${MUSEDIR}/Chronos.mp3"
ALTSONG="${MUSEDIR}/Epic_Dramatic-Yuriy_Bespalov.wav"
LOLCAT_NORM="lolcat"
LOLCAT_ANIM="lolcat --animate --speed=60.0"
LOLCAT="${LOLCAT_ANIM}"
artfiles="Friends/tux,Friends/yinyang"
custom_song=
art_font_size=4
bro_font_size=${def_font_size}
txt_font_size=18
platform=`uname -s`
if [ "${platform}" == "Darwin" ]
then
KITTY_QUIT_OPT="--override macos_quit_when_last_window_closed=yes"
else
KITTY_QUIT_OPT=
fi
pathadd() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="$1${PATH:+":$PATH"}"
fi
}
pathadd "/usr/local/bin"
pathadd "${HOME}/.local/bin"
export PATH
# Default palette used by jp2a
# defchars=" ...',;:clodxkO0KXNWM"
defchars=" ...,;:clodxkO0KXNWM"
# Reversed default palette
# revchars="MWNXK0Okxdolc:;,'... "
revchars="MWNXK0Okxdolc:;,... "
# Dark to light character set
# revlong="8WMoahkbdpqwmZO0QLCJUYXzcvunxrjft1-_+ilI;:,^..."
revlong="WMZO0QLCJUYXzcvun1il;:,^.. "
# Light to Dark character set
# longchars="...^,:;Ili+_-1tfjrxnuvczXYUJCLQ0OZmwqpdbkhaoMW8"
longchars=" ..^,:;li1nuvczXYUJCLQ0OZMW"
# Some configuration can be maintained here
CONFIG="${HOME}/.config/asciiville/config"
[ -f ${CONFIG} ] && . ${CONFIG}
# Convert 0 settings to unset
[ "${AUDIO}" == "0" ] && AUDIO=
[ "${FULLSCREEN}" == "0" ] && FULLSCREEN=
[ "${CURRENT}" == "0" ] && CURRENT=
[ "${GNOME}" == "0" ] && GNOME=
[ "${RETRO}" == "0" ] && RETRO=
[ "${TILIX}" == "0" ] && TILIX=
[ "${KITTY}" == "0" ] && KITTY=
[ "${XFCE4}" == "0" ] && XFCE4=
[ "${use_lolcat}" == "0" ] && use_lolcat=
[ "${zoom_depth}" ] || zoom_depth=7
[ "${zoom_interval}" ] || zoom_interval=4
saved_art_size=${art_font_size}
saved_txt_size=${txt_font_size}
set -m
usage() {
printf "\nUsage: show_ascii_art [-a art[,art2,...]] [-A art_dir] [-b] [-B] [-c] [-C]"
printf "\n\t[-d font_dir] [-D seconds] [-e term] [-E] [-F large_font] [-f small_font]"
printf "\n\t[-g] [-i image] [-I input_dir] [-O output_dir] [-K fifo|socket] [-l level]"
printf "\n\t[-L] [-n tabs] [-N depth] [-o] [-p palette] [-P] [-q] [-r] [-R len]"
printf "\n\t[-s show] [-S song] [-t first_text] [-T second_text]"
printf "\n\t[-h height] [-w width] [-W] [-v] [-z] [-Z] [-u]"
printf "\nWhere:"
printf "\n\t-a 'art' specifies ascii art file(s) to display"
printf "\n\t\tmultiple files are separated by a comma with no spaces"
printf "\n\t\t(e.g. '-a Friends/tux,Doctorwhen/Capitola_Village_Vivid')"
printf "\n\t\t'art' can be the relative path to a file in:"
printf "\n\t\t\t${ARTDIR}"
printf "\n\t\tor the path to a file, with or without file extension"
printf "\n\t-A 'art_dir' specifies the path to the ascii art folder"
printf "\n\t-b when generating ascii art use a border"
printf "\n\t-B use backup song when playing audio in slideshows"
printf "\n\t-c cycle slideshow endlessly (Ctrl-c to exit show)"
printf "\n\t-C center ascii art on screen if border detected"
printf "\n\t-d 'font_dir' specifies the path to the figlet fonts"
printf "\n\t-D 'seconds' specifies the delay, in seconds, between screens"
printf "\n\t-e 'term' specifies the terminal in which execution occurs"
printf "\n\t\t'term' can be one of 'gnome', 'xfce4', or 'tilix'"
printf "\n\t-E disables font size changing"
printf "\n\t-g convert image to grayscale"
printf "\n\t-i 'image' specifies an image file to convert to ascii art"
printf "\n\t-I 'input_dir' generates ascii art from all images in 'input_dir'"
printf "\n\t\tand saves them in the directory specified with '-O output_dir'"
printf "\n\t\t(defaults to current directory if '-O output_dir' is specified)"
printf "\n\t-K 'fifo|socket' use a FIFO or socket to communicate back to caller"
printf "\n\t-l 'level' use lolcat coloring, 'level' can be '1' or '2' (animate)"
printf "\n\t-L lists the ascii art in the 'art_dir' and exits"
printf "\n\t-f 'small_font' specifies the figlet font to use for small text"
printf "\n\t-F 'large_font' specifies the figlet font to use for large text"
printf "\n\t-n 'tabs' specifies the number of tabs to indent image display"
printf "\n\t-N 'depth' specifies the color depth"
printf "\n\t\t'depth' can be '4' (for ANSI), '8' (for 256 color palette)"
printf "\n\t\tor '24' (for truecolor or 24-bit color)"
printf "\n\t-o indicates overwrite any existing ascii art when saving"
printf "\n\t-O 'output_dir' generates ascii art from all images in the"
printf "\n\t\tdirectory specified with '-I' and saves them in 'output_dir'"
printf "\n\t-P indicates play audio during slideshow"
printf "\n\t-p 'palette' specifies which character set to use for ascii art"
printf "\n\t\t'palette' can be one of 'def', 'long', 'rev', 'longrev'"
printf "\n\t\t'def' is the default set, 'long' a long set,"
printf "\n\t\t'rev' reverses default, 'longrev' reverses long"
printf "\n\t\tAny other argument to '-p' will be taken as the character set"
printf "\n\t-q don't display text, just the ascii art"
printf "\n\t-r indicates select random fonts"
printf "\n\t-R 'len' indicates random slideshow of length 'len' (0 'len' infinite show)"
printf "\n\t-s 'show' slide show of ascii art"
printf "\n\t\t'show' can be:"
printf "\n\t\t\t'Art', 'Doctorwhen', 'Dragonflies', 'Fractals', 'Friends', 'Iterated'"
printf "\n\t\t\t'Lyapunov', 'Nature', 'Owls', 'Space', 'Wallpapers', 'Waterfalls'"
printf "\n\t\tor a custom folder name (with '-A art_dir')"
printf "\n\t-S 'song' use 'song' as audio track"
printf "\n\t-t 'first_text' specifies the first text to display"
printf "\n\t-T 'second_text' specifies the second text to display"
printf "\n\t-u displays this usage message and exits"
printf "\n\t-h 'height' specifies the height of the converted ascii art"
printf "\n\t-w 'width' specifies the width of the converted ascii art"
printf "\n\t\tIf only one of 'width' and 'height' is provided,"
printf "\n\t\tcalculate the other from image aspect ratio"
printf "\n\t-W indicates do not wait for input to continue viewing ascii art"
printf "\n\t-v indicates view ascii art and prompt to continue"
printf "\n\t-Z indicates no ANSI escape sequences used in ascii art"
printf "\n\t-z indicates save converted image ascii art in art_dir\n\n"
exit 1
}
send_done() {
if [ -p "${fifo_name}" ]
then
printf "done\n" > "${fifo_name}"
else
printf "\n Error fifo '%s' not found.\n\n" "${fifo_name}"
fi
clear
rm -f ${fifo_name}
}
set_spaces() {
space=0
while [ ${space} -lt ${numspaces} ]
do
spaces="${spaces} "
((space++))
done
}
set_tabs() {
tab=0
while [ ${tab} -lt ${numtabs} ]
do
tabs="${tabs}\t"
((tab++))
done
}
set_prep() {
prepart="$1"
# Filter non-printable characters from first line and get character count
awide=`head -1 "${prepart}" | sed 's/\x1B\[[0-9;]*[A-Za-z]//g' | wc -m`
termwide=`stty size | awk '{print $2}'`
mwide=`printf "$2" | wc -c`
fullwide=$((awide + mwide))
h_margin="$((termwide - fullwide))"
if [ ${h_margin} -gt 1 ]
then
numspaces="$((h_margin / 2))"
else
numspaces=0
fi
spaces=
set_spaces
prep="${prep}${spaces}"
}
vert_center() {
ahigh=`cat "$1" | wc -l`
termhigh=`stty size | awk '{print $1}'`
v_margin="$((termhigh - ahigh))"
if [ ${v_margin} -gt 1 ]
then
numlines="$((v_margin / 2))"
else
numlines=0
fi
line=0
while [ ${line} -lt ${numlines} ]
do
printf "\n"
((line++))
done
}
# Apply any gallery customization
# First argument is folder where art resides
# Second argument can be -a or -t to set art font or text font size
custom_gallery() {
showdir="$1"
setterm="$2"
scale_art_font=1
scale_txt_font=1
set_font_size=1
uses_ansi_escape=1
show_filename=
art_font_size=${saved_art_size}
txt_font_size=${saved_txt_size}
[ -f ${showdir}/.config ] && {
. ${showdir}/.config
[ ${scale_art_font} -eq 1 ] || {
art_font_size=$((saved_art_size * scale_art_font))
}
[ ${scale_txt_font} -eq 1 ] || {
txt_font_size=$((saved_txt_size * scale_txt_font))
}
}
[ "${setterm}" == "-a" ] && {
[ "${set_font_size}" ] && termprofset ${termarg} -s ${art_font_size}
}
[ "${setterm}" == "-t" ] && {
[ "${set_font_size}" ] && termprofset ${termarg} -s ${txt_font_size}
}
}
browser() {
bro_font_size=${art_font_size}
printf "\n"
figlet -c -d "${FIG_FONTS}" -f "${SMALL_FONT}" \
-k -t "Zoom/Browser Mode" 2> /dev/null
figlet -c -d "${FIG_FONTS}" -f "${SMALL_FONT}" \
-k -t "Zoom In: 'i' / 'j' / 'n'" 2> /dev/null
figlet -c -d "${FIG_FONTS}" -f "${SMALL_FONT}" \
-k -t "Zoom Out: 'o' / 'k' / 'm'" 2> /dev/null
figlet -c -d "${FIG_FONTS}" -f "${SMALL_FONT}" \
-k -t "Help: 'h' Exit: 'q'" 2> /dev/null
exitzoom=
skipredraw=
while true
do
read -rsn1 input
case "${input}" in
a) # Auto zoom
autozoom=1
;;
d) # Set default art font size
[ ${art_font_size} -eq ${bro_font_size} ] || {
art_font_size=${bro_font_size}
[ -f ${CONFIG} ] && {
cat "${CONFIG}" | \
sed -e "s/art_font_size=.*/art_font_size=${art_font_size}/" > /tmp/a$$
cp /tmp/a$$ ${CONFIG}
rm -f /tmp/a$$
}
}
skipredraw=1
;;
i) # Zoom in
((bro_font_size++))
;;
o) # Zoom out
((bro_font_size--))
;;
j) # Zoom in more
bro_font_size=$((bro_font_size + 3))
;;
k) # Zoom out more
bro_font_size=$((bro_font_size - 3))
[ ${bro_font_size} -lt 1 ] && bro_font_size=1
;;
n) # Zoom in most
bro_font_size=$((bro_font_size + 9))
;;
m) # Zoom out most
bro_font_size=$((bro_font_size - 9))
[ ${bro_font_size} -lt 1 ] && bro_font_size=1
;;
r) # Restore font size
bro_font_size=${art_font_size}
;;
f) # Toggle show filename
if [ "${show_filename}" ]
then
show_filename=
else
show_filename=1
fi
;;
q|x)
exitzoom=1
show_filename=
autozoom=
bro_font_size=${art_font_size}
;;
*) # Display simple help/usage for browser
clear
termprofset ${termarg} -s ${txt_font_size}
printf "\n\n\n\t'i' zoom in\n\t'j' zoom in more\n\t'n' zoom in even more"
printf "\n\t'o' zoom out\n\t'k' zoom out more\n\t'm' zoom out even more"
printf "\n\t'a' auto zoom\n\t'd' use current font size as default"
printf "\n\t'f' toggle show filename"
printf "\n\t'r' restore to original\n\t'h' display this help"
printf "\n\t'q' or 'x' to exit browse/zoom mode\n\n\t"
read -p "Press Enter to continue" answer
;;
esac
if [ "${autozoom}" ]
then
bro_font_size=${art_font_size}
numzoom=1
autozoom=
while [ ${numzoom} -lt ${zoom_depth} ]
do
((bro_font_size++))
((numzoom++))
clear
termprofset ${termarg} -s ${bro_font_size}
prep_and_show "$1" "$2"
sleep ${zoom_interval}
done
numzoom=1
while [ ${numzoom} -lt ${zoom_depth} ]
do
((bro_font_size--))
((numzoom++))
clear
termprofset ${termarg} -s ${bro_font_size}
prep_and_show "$1" "$2"
sleep ${zoom_interval}
done
clear
termprofset ${termarg} -s ${art_font_size}
prep_and_show "$1" "$2"
[ "${show_filename}" ] && {
printf "\n"
figlet -c -d "${FIG_FONTS}" -f "${SMALL_FONT}" \
-k -t `basename $1` 2> /dev/null
}
else
if [ "${skipredraw}" ]
then
skipredraw=
else
clear
termprofset ${termarg} -s ${bro_font_size}
prep_and_show "$1" "$2"
[ "${show_filename}" ] && {
printf "\n"
figlet -c -d "${FIG_FONTS}" -f "${SMALL_FONT}" \
-k -t `basename $1` 2> /dev/null
}
fi
fi
[ "${exitzoom}" ] && break
done
}
show_vintage() {
vintart="$1"
baseart=`basename "${vintart}"`
slow=
echo ${baseart} | grep _ > /dev/null && slow=1
if [ "${center}" ]
then
columns="$(tput cols 2>/dev/null)"
# Find longest line and calculate margin
longest=0
while IFS= read -r line; do
length=${#line}
[ ${length} -gt ${longest} ] && longest=${length}
done < "${vintart}"
margin=$(( (columns - ${longest}) / 2))
[ ${margin} -lt 0 ] && margin=0
padding=`printf '%*s' "${margin}"`
if [ "${slow}" ]
then
while IFS= read -r line; do
if [ "${have_lolcat}" ]
then
printf "%s%s\n" "${padding}" "${line}" | ${LOLCAT}
tput civis -- invisible 2> /dev/null
else
printf "%s%s\n" "${padding}" "${line}"
fi
done < "${vintart}"
else
if [ "${have_lolcat}" ]
then
/bin/cat "${vintart}" | sed "s/^/${padding}/" | ${LOLCAT}
tput civis -- invisible 2> /dev/null
else
/bin/cat "${vintart}" | sed "s/^/${padding}/"
fi
fi
else
if [ "${slow}" ]
then
while IFS= read -r line; do
if [ "${have_lolcat}" ]
then
printf "%s\n" "${line}" | ${LOLCAT}
tput civis -- invisible 2> /dev/null
else
printf "%s\n" "${line}"
fi
done < "${vintart}"
else
if [ "${have_lolcat}" ]
then
/bin/cat "${vintart}" | ${LOLCAT}
tput civis -- invisible 2> /dev/null
else
/bin/cat "${vintart}"
fi
fi
fi
}
show_art() {
artfile="$1"
marg="$2"
if [ "${set_font_size}" ]
then
if [ "${uses_ansi_escape}" ]
then
while read l
do
printf "${marg}$l"
done < <(/bin/cat "${artfile}")
else
show_vintage "${artfile}"
fi
else
printf "${marg}"
show_vintage "${artfile}"
fi
}
prep_and_show() {
prep="\n$2"
numlines=0
[ "${center}" ] && [ "${set_font_size}" ] && [ "${uses_ansi_escape}" ] && {
set_prep "$1" "$2"
}
vert_center "$1"
show_art "$1" "${prep}"
}
prep="\n"
# Display the ascii art
# first argument is the file
# second argument is prepended on each line of output (e.g. "\t\t")
show_ascii() {
[ -f "$1" ] || {
[ "${set_font_size}" ] && termprofset ${termarg} -R
echo "File: $1 does not exist"
echo "Exiting"
exit 1
}
case "$1" in
*.asc)
compressed=
asciiart="$1"
;;
*.gz)
compressed=1
gzip -cd "$1" > /tmp/asciiart$$
asciiart="/tmp/asciiart$$"
;;
*)
echo "Unsupported filename. Skipping ${asciiart}"
return 2
;;
esac
prep_and_show "${asciiart}" "$2"
[ "${viewshow}" ] && {
[ "${wait_for_input}" ] && {
[ "${show_filename}" ] && {
figlet -c -k -t `basename ${asciiart}` 2> /dev/null
}
while true
do
browse=
read -sp "" answer
case "${answer}" in
b|B|z|Z)
browse=1
;;
f|F)
if [ "${show_filename}" ]
then
show_filename=
else
show_filename=1
fi
;;
s|S)
wait_for_input=
break
;;
*)
break
;;
esac
[ "${browse}" ] && browser "${asciiart}" "$2"
done
}
}
[ "${compressed}" ] && rm -f "${asciiart}"
[ "${viewshow}" ] && [ "${wait_for_input}" ] && return 4
}
args="$*"
audio=
border=
center=
charopt=
charset=
colordepth=
colors=
cycle=
execute=
fifo_name=
sock_name=
termarg=
grayscale=
list=
lolcat=
make_inp=
make_out=
quiet=
delay=5
input_image=
randfont=
overwrite=
save_art=
height=
numtabs=0
randomshow=
showlength=0
slideshow=
viewshow=
tabs=
width=
scale_art_font=1
scale_txt_font=1
set_font_size=1
uses_ansi_escape=1
show_filename=
wait_for_input=1
have_convert=`type -p convert`
have_jp2a=`type -p jp2a`
have_setterm=`type -p setterm`
while getopts "a:A:bBcCD:d:e:Egh:i:I:K:l:LF:f:n:N:oO:Pp:qrR:s:S:t:T:vw:WzZu" flag; do
case $flag in
a)
artfiles="${OPTARG}"
;;
A)
ARTDIR="${OPTARG}"
;;
b)
border="--border"
;;
B)
SONG="${ALTSONG}"
;;
c)
cycle=1
;;
C)
center=1
;;
d)
FIG_FONTS="${OPTARG}"
;;
D)
delay="${OPTARG}"
;;
e)
execute="${OPTARG}"
case "${execute}" in
gnome*)
termarg="-g"
;;
kitty*)
termarg="-k"
;;
tilix*)
termarg="-t"
;;
xfce4*)
termarg="-x"
;;
*)
termarg=
;;
esac
;;
E)
set_font_size=
;;
F)
LARGE_FONT="${OPTARG}"
;;
f)
SMALL_FONT="${OPTARG}"
;;
g)
grayscale="--grayscale"
;;
i)
if [ "${have_jp2a}" ]
then
input_image="${OPTARG}"
else
echo "The jp2a command not installed or not in PATH"
echo "Skipping conversion and using default ascii art"
fi
;;
I)
make_inp=${OPTARG}
;;
K)
fifo_name="${OPTARG}"
;;
L)
list=1
;;
l)
lolcat=${OPTARG}
if [ "${lolcat}" == "2" ]
then
LOLCAT="${LOLCAT_ANIM}"
else
LOLCAT="${LOLCAT_NORM}"
fi
;;
O)
make_out=${OPTARG}
;;
n)
numtabs=${OPTARG}
;;
N)
colordepth="--colors --color-depth=${OPTARG}"
;;
o)
overwrite=1
;;
P)
audio=1
;;
p)
charset="${OPTARG}"
case "${charset}" in
def)
charopt=
;;
long)
charopt="--chars=${longchars}"
;;
rev)
charopt="--chars=${revchars}"
;;
longrev)
charopt="--chars=${revlong}"
;;
*)
charopt="--chars=${charset}"
;;
esac
;;
q)
quiet=1
;;
r)
randfont=1
;;
R)
randomshow=1
showlength=${OPTARG}
;;
s)
slideshow="${OPTARG}"
;;
S)
[ -f "${OPTARG}" ] && {
SONG="${OPTARG}"
custom_song=1
}
;;
t)
FIG_WELCOME="${OPTARG}"
;;
T)
FIG_ASCII="${OPTARG}"
;;
h)
height="${OPTARG}"
;;
v)
viewshow=1
;;
w)
width="${OPTARG}"
;;
W)
wait_for_input=
;;
z)
save_art=1
;;
Z)
uses_ansi_escape=
;;
u)
usage
;;
esac
done
# If using Kitty the socket name was passed in with -K socket
[ "${termarg}" == "-k" ] && [ "${fifo_name}" ] && {
sock_name="${fifo_name}"
termarg="-k -K ${sock_name}"
fifo_name=
}
[ "${list}" ] && {
first=1
have_asc=1
have_agz=1
for art in ${ARTDIR}/*/*.asc ${ARTDIR}/*/*.asc.gz
do
[ "${art}" == "${ARTDIR}/*/*.asc" ] && {
have_asc=
continue
}
[ "${art}" == "${ARTDIR}/*/*.asc.gz" ] && have_agz=
[ "${have_asc}" ] || [ "${have_agz}" ] || {
echo "No ascii art found in ${ARTDIR}"
echo "Ascii art files must have a '.asc' suffix"
[ "${fifo_name}" ] && send_done
exit 0
}
[ "${art}" == "${ARTDIR}/*/*.asc.gz" ] && continue
[ "${first}" ] && echo "Ascii Art in ${ARTDIR} :"
bart=`basename "${art}"`
bdir=`dirname "${art}"`
bdir=`basename "${bdir}"`
printf "\n\t${bdir}/${bart}"
first=
done
printf "\n\n"
[ "${fifo_name}" ] && send_done
exit 0
}
[ "${make_inp}" ] || [ "${make_out}" ] && {
[ "${make_inp}" ] || make_inp="."
[ "${make_out}" ] || make_out="ascii"
have_kitty=`type -p kitty`
have_gnome=`type -p gnome-terminal`
have_tilix=`type -p tilix`
have_xfce4=`type -p xfce4-terminal`
convargs="-c -f"
[ "${border}" ] && convargs="-b ${convargs}"
[ "${charset}" ] && convargs="${convargs} -p ${charset}"
mkartcomm="make_ascii_art ${convargs} -i"
if [ "${have_kitty}" ]
then
echo "Invoking kitty to convert ${make_inp} to ${make_out}"
kitty --title="Make Ascii Art" \
--start-as normal \
--override font_size=${art_font_size} \
--override initial_window_width=320c \
--override initial_window_height=96c \
--override tab_bar_min_tabs=2 \
--override startup_session=none \
${KITTY_QUIT_OPT} \
${mkartcomm} "${make_inp}" -o "${make_out}"
else
if [ "${have_gnome}" ]
then
echo "Invoking gnome-terminal to convert ${make_inp} to ${make_out}"
[ "${set_font_size}" ] && termprofset -S -g -s ${art_font_size}
gnome-terminal --window --geometry=320x96 --profile=Asciiville \
-- ${mkartcomm} "${make_inp}" -o "${make_out}"
else
if [ "${have_tilix}" ]
then
echo "Invoking Tilix to convert ${make_inp} to ${make_out}"
[ "${set_font_size}" ] && termprofset -S -t -s ${art_font_size}
tilix --geometry=320x96 \
--profile=Asciiville \
--window-style=borderless \
--command="${mkartcomm} '${make_inp}' -o '${make_out}'" \
2> /dev/null
else
if [ "${have_xfce4}" ]
then
[ "${set_font_size}" ] && termprofset -S -x -s ${art_font_size}
xfce4-terminal \
--hide-menubar \
--hide-toolbar \
--hide-scrollbar \
--geometry=320x96 \
--command="${mkartcomm} '${make_inp}' -o '${make_out}'"
else
${mkartcomm} "${make_inp}" -o "${make_out}"
fi
fi
fi
fi
sleep 2
[ "${set_font_size}" ] && termprofset -g -R
[ "${fifo_name}" ] && send_done
exit 0
}
have_lolcat=
[ "${lolcat}" ] && {
have_lolcat=`type -p lolcat`
}
# Save the current terminal profile or config
# Set the xfce4-terminal background to black and no transparency
# Set the terminal profile or config font size for ascii art
[ "${set_font_size}" ] && {
termprofset ${termarg} -S -B -s ${art_font_size}
sleep 2
}
fade_audio() {
vol=75
while [ ${vol} -gt 0 ]
do
echo "volume ${vol} 1" > ${fifo}
vol=$((vol - 5))
sleep 0.1
done
echo "stop" > ${fifo}
sleep 0.1
echo "quit" > ${fifo}
rm -f ${fifo}
}
goodbye() {
clear
[ "${quiet}" ] || {
[ "${set_font_size}" ] && termprofset ${termarg} -s ${txt_font_size}
printf "\n\n\n"
if [ "${have_lolcat}" ]
then
figlet -c -d "${FIG_FONTS}" -f "Bolger" -k -t "Thanks For" 2> /dev/null | ${LOLCAT}
printf "\n\n"
figlet -c -d "${FIG_FONTS}" -f "Bolger" -k -t "Viewing" 2> /dev/null | ${LOLCAT}
printf "\n\n"
figlet -c -d "${FIG_FONTS}" -f "Bolger" -k -t "Ascii Art !" 2> /dev/null | ${LOLCAT}
tput civis -- invisible 2> /dev/null
else
figlet -c -d "${FIG_FONTS}" -f "Bolger" -k -t "Thanks For" 2> /dev/null
printf "\n\n"
figlet -c -d "${FIG_FONTS}" -f "Bolger" -k -t "Viewing" 2> /dev/null
printf "\n\n"
figlet -c -d "${FIG_FONTS}" -f "Bolger" -k -t "Ascii Art !" 2> /dev/null
fi
sleep $((delay / 2))
clear
[ "${set_font_size}" ] && termprofset ${termarg} -R
}
}
cleanup() {
goodbye
tput cnorm 2> /dev/null
if [ "${have_setterm}" ]
then
setterm -linewrap on
else
tput smam 2> /dev/null
fi
[ "${fifo_name}" ] && send_done
[ "${playing}" ] && fade_audio
exit 0
}
play_random_show() {
tput civis -- invisible 2> /dev/null
numslide=0
[ ${showlength} -eq 0 ] || ((numslide++))
a=( ${ARTDIR}/* )
while [ ${numslide} -le ${showlength} ]
do
# Pick a random gallery
while true
do
have_asc=1
have_agz=1
((j=RANDOM%${#a[@]}))
showdir="${a[j]}"
for tstart in ${showdir}/*.asc ${showdir}/*.asc.gz
do
[ "${tstart}" == "${showdir}/*.asc" ] && {
have_asc=
continue
}
[ "${tstart}" == "${showdir}/*.asc.gz" ] && have_agz=
[ "${have_asc}" ] || [ "${have_agz}" ] || break
[ -f "${tstart}" ] || break
break 2
done
done
# Apply any gallery customization
custom_gallery "${showdir}"
# Pick a random ascii art from the randomly selected gallery
f=( ${showdir}/* )
((k=RANDOM%${#f[@]}))
art="${f[k]}"
[ "${first}" ] && {
[ "${quiet}" ] || {
[ "${set_font_size}" ] && termprofset ${termarg} -s ${txt_font_size}
printf "\n\n\n"
if [ "${have_lolcat}" ]
then
figlet -c -d "${FIG_FONTS}" -f "${SLIDE_FONT}" -k -t ${FIG_WELCOME} 2> /dev/null | ${LOLCAT}
figlet -c -d "${FIG_FONTS}" -f "${SLIDE_FONT}" -k -t ${FIG_ASCII} 2> /dev/null | ${LOLCAT}
figlet -c -d "${FIG_FONTS}" -f "${SLIDE_FONT}" -k -t "Ascii Art" 2> /dev/null | ${LOLCAT}
tput civis -- invisible 2> /dev/null
else
figlet -c -d "${FIG_FONTS}" -f "${SLIDE_FONT}" -k -t ${FIG_WELCOME} 2> /dev/null
figlet -c -d "${FIG_FONTS}" -f "${SLIDE_FONT}" -k -t ${FIG_ASCII} 2> /dev/null
figlet -c -d "${FIG_FONTS}" -f "${SLIDE_FONT}" -k -t "Ascii Art" 2> /dev/null
fi
figlet -c -d "${FIG_FONTS}" -f "Digital" -k -t "Ctrl-c Exits" 2> /dev/null
sleep ${delay}
}
first=
}
clear
[ "${set_font_size}" ] && termprofset ${termarg} -s ${art_font_size}
show_ascii "${art}"
[ $? -gt 1 ] || {
[ "${show_filename}" ] && figlet -c -k -t `basename ${art}` 2> /dev/null
sleep ${delay}
[ ${showlength} -eq 0 ] || ((numslide++))
}
[ ${scale_art_font} -eq 1 ] || art_font_size=${saved_art_size}
[ ${scale_txt_font} -eq 1 ] || txt_font_size=${saved_txt_size}
done
}
play_slide_show() {
tput civis -- invisible 2> /dev/null
have_asc=1
have_agz=1
for art in ${SLIDE_DIR}/*.asc ${SLIDE_DIR}/*.asc.gz
do
[ "${art}" == "${SLIDE_DIR}/*.asc" ] && {
have_asc=
continue
}
[ "${art}" == "${SLIDE_DIR}/*.asc.gz" ] && have_agz=
[ "${have_asc}" ] || [ "${have_agz}" ] || {
[ "${set_font_size}" ] && termprofset ${termarg} -s ${txt_font_size}
echo "No ascii art found in ${SLIDE_DIR}"
echo "Ascii art files must have a '.asc' or '.asc.gz' suffix"
[ "${set_font_size}" ] && termprofset ${termarg} -R
[ "${fifo_name}" ] && send_done
exit 0