Skip to content

Commit 57b00a4

Browse files
committed
bash3 support, Xcode bug fix & don't stall dumb terms.
[FIXED] bash 3 couldn't parse the file because of the coproc. [FIXED] Xcode has a weird bug where outputting :: X :: breaks it. This happened with set -x on. [FIXED] pinf could hang some dumb terminals due to its spinner. [FIXED] removed several references to the removed getArgs.
1 parent 7f52516 commit 57b00a4

File tree

1 file changed

+17
-90
lines changed

1 file changed

+17
-90
lines changed

bash/bashlib/bashlib

Lines changed: 17 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# ______________________________________________________________________
2929
# | |
30-
# | .:: TABLE OF CONTENTS ::. |
30+
# | .: TABLE OF CONTENTS :. |
3131
# |______________________________________________________________________|
3232
#
3333
# chr decimal
@@ -66,12 +66,6 @@
6666
# readwhile command [args]
6767
# Outputs the characters typed by the user into the terminal's input buffer while running the given command.
6868
#
69-
# pushqueue element ...
70-
# Pushes the given arguments as elements onto the queue.
71-
#
72-
# popqueue
73-
# Pops one element off the queue.
74-
#
7569
# log [format] [arguments...]
7670
# Log an event at a certain importance level.
7771
# The event is expressed as a printf(1) format argument.
@@ -97,9 +91,6 @@
9791
# fsleep time
9892
# Wait for the given (fractional) amount of seconds.
9993
#
100-
# getArgs [options] optstring [args...]
101-
# Retrieve all options present in the given arguments.
102-
#
10394
# showHelp name description author [option description]...
10495
# Generate a prettily formatted usage description of the application.
10596
#
@@ -135,7 +126,7 @@ _tocHash=71e13f42e1ea82c1c7019b27a3bc71f3
135126

136127
# ______________________________________________________________________
137128
# | |
138-
# | .:: GLOBAL CONFIGURATION ::. |
129+
# | .: GLOBAL CONFIGURATION :. |
139130
# |______________________________________________________________________|
140131

141132
# Unset all exported functions. Exported functions are evil.
@@ -180,7 +171,7 @@ genToc() {
180171

181172
# ______________________________________________________________________
182173
# | |
183-
# | .:: GLOBAL DECLARATIONS ::. |
174+
# | .: GLOBAL DECLARATIONS :. |
184175
# |______________________________________________________________________|
185176

186177
# Variables for convenience sequences.
@@ -193,8 +184,8 @@ runner=( '> >' \
193184

194185
# Variables for terminal requests.
195186
[[ -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
198189
alt=$( tput smcup || tput ti ) # Start alt display
199190
ealt=$( tput rmcup || tput te ) # End alt display
200191
hide=$( tput civis || tput vi ) # Hide cursor
@@ -233,15 +224,15 @@ runner=( '> >' \
233224
tput eA; tput as;
234225
tput ac; tput ae; } ) # Drawing characters
235226
back=$'\b'
236-
} 2>/dev/null ||:
227+
} 3>&2 2>/dev/null ||:
237228

238229

239230

240231

241232

242233
# ______________________________________________________________________
243234
# | |
244-
# | .:: FUNCTION DECLARATIONS ::. |
235+
# | .: FUNCTION DECLARATIONS :. |
245236
# |______________________________________________________________________|
246237

247238

@@ -468,44 +459,6 @@ readwhile() {
468459

469460

470461

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-
509462
# ______________________________________________________________________
510463
# |__ Latest ____________________________________________________________|
511464
#
@@ -638,7 +591,7 @@ log() {
638591
FTL) (( supported = 1 ))
639592
logLevelColor=$_logFtlColor ;;
640593
*)
641-
log FTL "Log level %s does not exist" "$level"
594+
log FTL 'Log level %s does not exist' "$level"
642595
exit 1 ;;
643596
esac
644597
(( ! supported )) && return "$exitcode"
@@ -651,7 +604,7 @@ log() {
651604
if (( _logColor )); then
652605
colorFormat=$(sed ${reset:+-e "s/$(requote "$reset")/$reset$logColor/g"} -e "s/%[^a-z]*[a-z]/$reset$bold$logColor&$reset$logColor/g" <<< "$format")
653606
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[@]}"
655608
else
656609
conMsg=$logMsg
657610
fi
@@ -718,15 +671,15 @@ log() {
718671
&& printf >> "$_logFile" '%s' "$logMsg"
719672

720673
# Start the spinner.
721-
if [[ $type = startProgress && ! $_logSpinner ]]; then
674+
if [[ $type = startProgress && ! $_logSpinner && $TERM != dumb ]]; then
722675
{
723676
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
727680
do :; done
728681
} & _logSpinner=$!
729-
fi 2>/dev/null
682+
fi
730683

731684
return $exitcode
732685
}
@@ -788,12 +741,6 @@ _logTrcColor=$grey _logDbgColor=$blue _logInfColor=$white _logWrnColor=$yellow _
788741
#
789742
ask() {
790743

791-
# Check usage.
792-
(( ! $# )) || getArgs -q :h "$@" && {
793-
wrn 'Please specify a question as argument.'
794-
return 1
795-
}
796-
797744
# Initialize the vars.
798745
local opt arg
799746
local option=
@@ -830,7 +777,7 @@ ask() {
830777

831778
# Ask the question.
832779
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"}
834781

835782
# Read the reply.
836783
exec 8<&0; [[ -t 8 ]] || exec 8</dev/tty
@@ -1211,13 +1158,6 @@ options() {
12111158
#
12121159
showHelp() {
12131160

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-
12211161
# Parse the options.
12221162
local appName=$1; shift
12231163
local appDesc=${1//+([[:space:]])/ }; shift
@@ -1340,12 +1280,6 @@ requote() {
13401280
#
13411281
shorten() {
13421282

1343-
# Check usage.
1344-
(( $# < 1 )) || getArgs -q :h "$@" && {
1345-
wrn 'Please provide the path to shorten.'
1346-
return 1
1347-
}
1348-
13491283
# Parse the options.
13501284
local suffix path pwd=$PWD
13511285
[[ $1 = -p ]] && { pwd=$2; shift 2; }
@@ -1459,13 +1393,6 @@ buildarray() {
14591393
#
14601394
inArray() {
14611395

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-
14691396
# Parse the options.
14701397
local element
14711398
local search=$1; shift
@@ -1616,7 +1543,7 @@ stackTrace() {
16161543

16171544
# ______________________________________________________________________
16181545
# | |
1619-
# | .:: ENTRY POINT ::. |
1546+
# | .: ENTRY POINT :. |
16201547
# |______________________________________________________________________|
16211548

16221549
# Make sure this file is sourced and not executed.
@@ -1636,6 +1563,6 @@ stackTrace() {
16361563
}
16371564

16381565
:
1639-
: .:: END SOURCING ::.
1566+
: .: END SOURCING :.
16401567
: ______________________________________________________________________
16411568
:

0 commit comments

Comments
 (0)