Skip to content

Commit a4bbae9

Browse files
committed
- Update colors library to support auto-colors based on TTY
1 parent 29c5e60 commit a4bbae9

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/bashly/libraries/colors/colors.sh

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
## Color output will be disabled if `NO_COLOR` environment variable is set
1111
## in compliance with https://no-color.org/
1212
##
13+
## In case you wish to enable auto detection for color output based on the
14+
## terminal being interactive (TTY), call `enable_auto_colors` in your
15+
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
16+
##
17+
enable_auto_colors() {
18+
[[ -z ${NO_COLOR+x} && ! -t 1 ]] && NO_COLOR=1 || true
19+
}
20+
1321
print_in_color() {
1422
local color="$1"
1523
shift

lib/bashly/libraries/libraries.yml

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ colors:
33
files:
44
- source: "colors/colors.sh"
55
target: "%{user_lib_dir}/colors.%{user_ext}"
6+
post_install_message: |
7+
The colors library supports the g`NO_COLOR` standard out of the box.
8+
9+
In case you wish to also enable automatic output of colors based on the
10+
terminal being interactive (TTY), call g`enable_auto_colors` in your
11+
g`src/initialize.sh`. You may run the following command to add this file:
12+
13+
m`$ bashly add hooks`
614
715
completions:
816
help: Generate a bash completions function.

0 commit comments

Comments
 (0)