aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-03-23 10:04:53 +0100
committerPatrick Spek <p.spek@tyil.nl>2020-03-23 10:04:53 +0100
commita55793cca8749cca991983c1d035631127fa1372 (patch)
treedaced85f58b2734c8b437c7115a84c744e6af23c
parent964e1eac3bf7060bd96bb819f8fb82c2cc1a5cae (diff)
Keep list of terminals where color support is known to work
-rw-r--r--etc/color-terminals.txt2
-rw-r--r--lib/logging.bash78
2 files changed, 56 insertions, 24 deletions
diff --git a/etc/color-terminals.txt b/etc/color-terminals.txt
new file mode 100644
index 0000000..56f5d5a
--- /dev/null
+++ b/etc/color-terminals.txt
@@ -0,0 +1,2 @@
+screen-256color
+xterm-termite
diff --git a/lib/logging.bash b/lib/logging.bash
index a1ef767..76df937 100644
--- a/lib/logging.bash
+++ b/lib/logging.bash
@@ -1,7 +1,5 @@
#!/usr/bin/env bash
-# TODO: Only use colors on terminals that are known to work well with them.
-
# The base function to output logging information. This should *not* be used
# directly, but the helper functions can be used safely.
log() {
@@ -21,31 +19,63 @@ log() {
printf "${color}[%s] %s\e[0m\n" "$(date +%FT%T)" "$*" >&2
}
-debug() {
- [[ -z $RSTAR_DEBUG ]] && return
- log -c "\e[1;30m" -- "$*"
-}
+if [[ "$(awk '$1 == "'"$TERM"'" {print 1}' "$BASEDIR/etc/color-terminals.txt")" ]]
+then
+ debug() {
+ [[ -z $RSTAR_DEBUG ]] && return
+ log -c "\e[1;30m" -- "$*"
+ }
-info() {
- log -- "$*"
-}
+ info() {
+ log -- "$*"
+ }
-notice() {
- log -c "\e[0;34m" -- "$*"
-}
+ notice() {
+ log -c "\e[0;34m" -- "$*"
+ }
-warn() {
- log -c "\e[0;33m" -- "$*"
-}
+ warn() {
+ log -c "\e[0;33m" -- "$*"
+ }
-crit() {
- log -c "\e[0;31m" -- "$*"
-}
+ crit() {
+ log -c "\e[0;31m" -- "$*"
+ }
-alert() {
- log -c "\e[1;31m" -- "$*"
-}
+ alert() {
+ log -c "\e[1;31m" -- "$*"
+ }
-emerg() {
- log -c "\e[1;4;31m" -- "$*"
-}
+ emerg() {
+ log -c "\e[1;4;31m" -- "$*"
+ }
+else
+ debug() {
+ [[ -z $RSTAR_DEBUG ]] && return
+ log -- "[DEBUG] $*"
+ }
+
+ info() {
+ log -- "[INFO] $*"
+ }
+
+ notice() {
+ log -- "[NOTIC] $*"
+ }
+
+ warn() {
+ log -- "[WARN] $*"
+ }
+
+ crit() {
+ log -- "[CRIT] $*"
+ }
+
+ alert() {
+ log -- "[ALERT] $*"
+ }
+
+ emerg() {
+ log -- "[EMERG] $*"
+ }
+fi