Commit aba3fa8e authored by Vitaly Lipatov's avatar Vitaly Lipatov

hdd: add outputformat.sh

parent 8f6ed82f
# copied from /etc/init.d/outformat (ALT Linux)
# FIXME on Android: FIX ME! implement ttyname_r() bionic/libc/bionic/stubs.c:366
inputisatty()
{
# check stdin
#tty -s 2>/dev/null
test -t 0
}
isatty()
{
# check stdout
test -t 1
}
isatty2()
{
# check stderr
test -t 2
}
check_tty()
{
isatty2 || return
# Set a sane TERM required for tput
[ -n "$TERM" ] || TERM=dumb
export TERM
# egrep from busybox may not --color
# egrep from MacOS print help to stderr
if grep -E --help 2>&1 | grep -q -- "--color" ; then
export EGREPCOLOR="--color"
fi
which tput >/dev/null 2>/dev/null || return
# FreeBSD does not support tput -S
echo | tput -S >/dev/null 2>/dev/null || return
[ -z "$USETTY" ] || return
export USETTY=1
}
: ${BLACK:=0} ${RED:=1} ${GREEN:=2} ${YELLOW:=3} ${BLUE:=4} ${MAGENTA:=5} ${CYAN:=6} ${WHITE:=7}
set_boldcolor()
{
[ "$USETTY" = "1" ] || return
{
echo bold
echo setaf $1
} |tput -S
}
restore_color()
{
[ "$USETTY" = "1" ] || return
{
echo op; # set Original color Pair.
echo sgr0; # turn off all special graphics mode (bold in our case).
} |tput -S
}
pcolor()
{
set_boldcolor "$1"
shift
echo -n "$*"
restore_color
}
test_main()
{
check_tty
pcolor $BLUE "Hello, world!"
echo "Hello"
N="$(pcolor $BLUE "Hello, world!")"
pcolor $RED "Hello, world!"
echo "$N NONO"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment