27
27
28
28
# ______________________________________________________________________
29
29
# | |
30
- # | .:: TABLE OF CONTENTS : :. |
30
+ # | .: TABLE OF CONTENTS :. |
31
31
# |______________________________________________________________________|
32
32
#
33
33
# chr decimal
66
66
# readwhile command [args]
67
67
# Outputs the characters typed by the user into the terminal's input buffer while running the given command.
68
68
#
69
- # pushqueue element ...
70
- # Pushes the given arguments as elements onto the queue.
71
- #
72
- # popqueue
73
- # Pops one element off the queue.
74
- #
75
69
# log [format] [arguments...]
76
70
# Log an event at a certain importance level.
77
71
# The event is expressed as a printf(1) format argument.
97
91
# fsleep time
98
92
# Wait for the given (fractional) amount of seconds.
99
93
#
100
- # getArgs [options] optstring [args...]
101
- # Retrieve all options present in the given arguments.
102
- #
103
94
# showHelp name description author [option description]...
104
95
# Generate a prettily formatted usage description of the application.
105
96
#
@@ -135,7 +126,7 @@ _tocHash=71e13f42e1ea82c1c7019b27a3bc71f3
135
126
136
127
# ______________________________________________________________________
137
128
# | |
138
- # | .:: GLOBAL CONFIGURATION : :. |
129
+ # | .: GLOBAL CONFIGURATION :. |
139
130
# |______________________________________________________________________|
140
131
141
132
# Unset all exported functions. Exported functions are evil.
@@ -180,7 +171,7 @@ genToc() {
180
171
181
172
# ______________________________________________________________________
182
173
# | |
183
- # | .:: GLOBAL DECLARATIONS : :. |
174
+ # | .: GLOBAL DECLARATIONS :. |
184
175
# |______________________________________________________________________|
185
176
186
177
# Variables for convenience sequences.
@@ -193,8 +184,8 @@ runner=( '> >' \
193
184
194
185
# Variables for terminal requests.
195
186
[[ -t 2 && $TERM != dumb ]] && {
196
- COLUMNS=$( tput cols || tput co ) # Columns in a line
197
- LINES=$( tput lines || tput li ) # Lines on screen
187
+ COLUMNS=$( { tput cols || tput co; } 2>&3 ) # Columns in a line
188
+ LINES=$( { tput lines || tput li; } 2>&3 ) # Lines on screen
198
189
alt=$( tput smcup || tput ti ) # Start alt display
199
190
ealt=$( tput rmcup || tput te ) # End alt display
200
191
hide=$( tput civis || tput vi ) # Hide cursor
@@ -233,15 +224,15 @@ runner=( '> >' \
233
224
tput eA; tput as;
234
225
tput ac; tput ae; } ) # Drawing characters
235
226
back=$' \b '
236
- } 2> /dev/null || :
227
+ } 3>&2 2> /dev/null || :
237
228
238
229
239
230
240
231
241
232
242
233
# ______________________________________________________________________
243
234
# | |
244
- # | .:: FUNCTION DECLARATIONS : :. |
235
+ # | .: FUNCTION DECLARATIONS :. |
245
236
# |______________________________________________________________________|
246
237
247
238
@@ -468,44 +459,6 @@ readwhile() {
468
459
469
460
470
461
471
- # ___________________________________________________________________________
472
- # |__ pushqueue ______________________________________________________________|
473
- #
474
- # pushqueue element ...
475
- #
476
- # Pushes the given arguments as elements onto the queue.
477
- #
478
- pushqueue () {
479
- [[ $_queue ]] || {
480
- coproc _queue {
481
- while IFS= read -r -d ' ' ; do
482
- printf ' %s\0' " $REPLY "
483
- done
484
- }
485
- }
486
-
487
- printf ' %s\0' " $@ " >& " ${_queue[1]} "
488
- } # _____________________________________________________________________
489
-
490
-
491
-
492
- # __________________________________________________________________________
493
- # |__ popqueue ______________________________________________________________|
494
- #
495
- # popqueue
496
- #
497
- # Pops one element off the queue.
498
- # If no elements are available on the queue, this command fails with exit code 1.
499
- #
500
- popqueue () {
501
- local REPLY
502
- [[ $_queue ]] && read -t0 < & " ${_queue[0]} " || return
503
- IFS= read -r -d ' ' < & " ${_queue[0]} "
504
- printf %s " $REPLY "
505
- } # _____________________________________________________________________
506
-
507
-
508
-
509
462
# ______________________________________________________________________
510
463
# |__ Latest ____________________________________________________________|
511
464
#
@@ -638,7 +591,7 @@ log() {
638
591
FTL) (( supported = 1 ))
639
592
logLevelColor=$_logFtlColor ;;
640
593
* )
641
- log FTL " Log level %s does not exist" " $level "
594
+ log FTL ' Log level %s does not exist' " $level "
642
595
exit 1 ;;
643
596
esac
644
597
(( ! supported )) && return " $exitcode "
@@ -651,7 +604,7 @@ log() {
651
604
if (( _logColor )) ; then
652
605
colorFormat=$( sed ${reset: +-e " s/$( requote " $reset " ) /$reset$logColor /g" } -e " s/%[^a-z]*[a-z]/$reset$bold$logColor &$reset$logColor /g" <<< " $format" )
653
606
colorArgs=(" ${args[@]// $reset / $reset$bold$logColor } " )
654
- printf -v conMsg " $reset [${date: +% s } $logColor %-3s$reset ] $logColor$colorFormat$reset$black \$ $reset$end$save " ${date: +" $date " } " $level " " ${colorArgs[@]} "
607
+ printf -v conMsg " $reset [${date: +% s } $logColor$bold %-3s$reset ] $logColor$colorFormat$reset$black \$ $reset$end$save " ${date: +" $date " } " $level " " ${colorArgs[@]} "
655
608
else
656
609
conMsg=$logMsg
657
610
fi
@@ -718,15 +671,15 @@ log() {
718
671
&& printf >> " $_logFile " ' %s' " $logMsg "
719
672
720
673
# Start the spinner.
721
- if [[ $type = startProgress && ! $_logSpinner ]]; then
674
+ if [[ $type = startProgress && ! $_logSpinner && $TERM != dumb ]]; then
722
675
{
723
676
set +m
724
- trap ' printf %s "$show"' EXIT
725
- printf %s " $hide "
726
- while printf " $eel$blue$bold [$reset %s$reset$blue$bold ]$reset \b\b\b" " ${spinner[s++ % ${#spinner[@]} ]}" && sleep .1
677
+ trap ' printf >&2 %s "$show"' EXIT
678
+ printf >&2 %s " $hide "
679
+ while printf >&2 " $eel$blue$bold [$reset %s$reset$blue$bold ]$reset \b\b\b" " ${spinner[s++ % ${#spinner[@]} ]}" && sleep .1
727
680
do : ; done
728
681
} & _logSpinner=$!
729
- fi 2> /dev/null
682
+ fi
730
683
731
684
return $exitcode
732
685
}
@@ -788,12 +741,6 @@ _logTrcColor=$grey _logDbgColor=$blue _logInfColor=$white _logWrnColor=$yellow _
788
741
#
789
742
ask () {
790
743
791
- # Check usage.
792
- (( ! $# )) || getArgs -q :h " $@ " && {
793
- wrn ' Please specify a question as argument.'
794
- return 1
795
- }
796
-
797
744
# Initialize the vars.
798
745
local opt arg
799
746
local option=
@@ -830,7 +777,7 @@ ask() {
830
777
831
778
# Ask the question.
832
779
format=$1 ; shift
833
- level=${level:- WRN} log -n " $format ${option: + [%s]}${options: + [%s]} " " $@ " ${option: +" $option " } ${options: +" $options " }
780
+ level=${level:- WRN} log -n " $format ${option: + [%s]}${options: + [%s]} " " $@ " ${option: +" $option " } ${options: +" $options " }
834
781
835
782
# Read the reply.
836
783
exec 8< & 0; [[ -t 8 ]] || exec 8< /dev/tty
@@ -1211,13 +1158,6 @@ options() {
1211
1158
#
1212
1159
showHelp () {
1213
1160
1214
- # Check usage.
1215
- (( $# < 3 )) || getArgs -q :h " $@ " && {
1216
- wrn ' Please provide the name, description, author and options' \
1217
- ' of the application.'
1218
- return 1
1219
- }
1220
-
1221
1161
# Parse the options.
1222
1162
local appName=$1 ; shift
1223
1163
local appDesc=${1// +([[:space:]])/ } ; shift
@@ -1340,12 +1280,6 @@ requote() {
1340
1280
#
1341
1281
shorten () {
1342
1282
1343
- # Check usage.
1344
- (( $# < 1 )) || getArgs -q :h " $@ " && {
1345
- wrn ' Please provide the path to shorten.'
1346
- return 1
1347
- }
1348
-
1349
1283
# Parse the options.
1350
1284
local suffix path pwd=$PWD
1351
1285
[[ $1 = -p ]] && { pwd=$2 ; shift 2; }
@@ -1459,13 +1393,6 @@ buildarray() {
1459
1393
#
1460
1394
inArray () {
1461
1395
1462
- # Check usage.
1463
- (( $# < 1 )) || getArgs -q :h " $@ " && {
1464
- wrn ' Please provide the element to search for and the array' \
1465
- ' to search through.'
1466
- return 1
1467
- }
1468
-
1469
1396
# Parse the options.
1470
1397
local element
1471
1398
local search=$1 ; shift
@@ -1616,7 +1543,7 @@ stackTrace() {
1616
1543
1617
1544
# ______________________________________________________________________
1618
1545
# | |
1619
- # | .:: ENTRY POINT : :. |
1546
+ # | .: ENTRY POINT :. |
1620
1547
# |______________________________________________________________________|
1621
1548
1622
1549
# Make sure this file is sourced and not executed.
@@ -1636,6 +1563,6 @@ stackTrace() {
1636
1563
}
1637
1564
1638
1565
:
1639
- : .:: END SOURCING ::.
1566
+ : .: END SOURCING :.
1640
1567
: ______________________________________________________________________
1641
1568
:
0 commit comments