@@ -309,41 +309,58 @@ core.stacktrace_print() {
309309 fi
310310} >&2
311311
312- # @description Determine if color should be printed
313- # @internal
314- core.should_color_output () {
315- # TODO: 'COLORTERM'
316-
312+ # @description Determine if color should be printed. Note that this doesn't
313+ # use tput because simple environment variable checking heuristics suffice
314+ core.should_output_color () {
317315 # https://no-color.org
318- if [[ -v NO_COLOR ] ]; then
316+ if [ ${ NO_COLOR+x} ]; then
319317 return 1
320318 fi
321319
322- # 0 => 2 colors
323- # 1 => 16 colors
324- # 2 => 256 colors
325- # 3 => 16,777,216 colors
326- if [[ -v FORCE_COLOR ]]; then
320+ # FIXME
321+ # # 0 => 2 colors
322+ # # 1 => 16 colors
323+ # # 2 => 256 colors
324+ # # 3 => 16,777,216 colors
325+ # if [[ -v FORCE_COLOR ]]; then
326+ # return 0
327+ # fi
328+
329+ if [ " $COLORTERM " = " truecolor" ] || [ " $COLORTERM " = " 24bit" ]; then
327330 return 0
328331 fi
329332
330- if [[ $TERM == dumb ]]; then
333+ if [ " $TERM " = ' dumb' ]; then
334+ return 1
335+ fi
336+
337+ if [ -t 0 ]; then
331338 return 0
332339 fi
340+
341+ return 1
333342}
334343
335- # @description Get version of the package, from the point of the callsite. In other words, it
336- # returns the version of the package that has the file containing the direct caller of this
337- # @set REPLY The full path to the directory
338- # @internal
339- core.get_package_dir () {
344+ # @description Gets information from a particular package. If the key does not exist, then the value
345+ # is an empty string
346+ # @arg $1 string The `$BASALT_PACKAGE_DIR` of the caller
347+ # @set REPLY string The full path to the directory
348+ core.get_package_info () {
349+ unset REPLY; REPLY=
350+ local basalt_package_dir=" $1 "
351+ local key_name=" $2 "
340352
341- # local start_dir="${1:-"${BASH_SOURCE[1]}"}"
342-
343- # while [ ! -f 'basalt.toml' ] && [ "$PWD" != / ]; do
344- # if ! cd ..; then
345- # return 1
346- # fi
347- # done
348- :
353+ local toml_file=" $basalt_package_dir /basalt.toml"
354+
355+ if [ ! -f " $toml_file " ]; then
356+ printf ' %s\n' " Error: core.get_package_data: File '$toml_file ' could not be found"
357+ fi
358+
359+ local regex=" ^[ \t]*${key_name} [ \t]*=[ \t]*['\" ](.*)['\" ]"
360+ while IFS= read -r line || [ -n " $line " ]; do
361+ if [[ $line =~ $regex ]]; then
362+ REPLY=${BASH_REMATCH[1]}
363+ break
364+ fi
365+ done < " $toml_file " ; unset -v line
349366}
0 commit comments