blob: 49df8233a8aaf3a007af126d05141dcecd1488d3 [file] [log] [blame]
#!/bin/bash
#
# Copyright 2022 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Returns true if colors are supported.
function is-stderr-tty {
[[ -t 2 ]]
}
# echo-info prints a line to stderr with a green INFO: prefix.
function echo-info {
if is-stderr-tty; then
echo -e >&2 "\033[1;32mINFO:\033[0m $*"
else
echo -e >&2 "INFO: $*"
fi
}
# echo-warning prints a line to stderr with a yellow WARNING: prefix.
function echo-warning {
if is-stderr-tty; then
echo -e >&2 "\033[1;33mWARNING:\033[0m $*"
else
echo -e >&2 "WARNING: $*"
fi
}
# echo-error prints a line to stderr with a red ERROR: prefix.
function echo-error {
if is-stderr-tty; then
echo -e >&2 "\033[1;31mERROR:\033[0m $*"
else
echo -e >&2 "ERROR: $*"
fi
}