Commit bd56ce32 authored by Vitaly Lipatov's avatar Vitaly Lipatov

common: introduce docmd and showcmd funcs

parent 6f40be9d
......@@ -11,7 +11,7 @@ realpath()
readlink -f "$@"
}
# Выводит указанное сообщение об ошибке и завершает программу
# Print error message and stop the program
fatal()
{
if [ -z "$TEXTDOMAIN" ] ; then
......@@ -22,7 +22,7 @@ fatal()
exit 1
}
# Выводит указанное сообщение
# Just print warning message
warning()
{
if [ -z "$TEXTDOMAIN" ] ; then
......@@ -32,6 +32,7 @@ warning()
fi
}
set_eterbuilddir()
{
[ -z "$ETERBUILDDIR" ] || return 0
......@@ -135,7 +136,7 @@ load_mod()
done
}
load_mod config gettext alt spec strings
load_mod config gettext alt spec strings outformat
# check for needed version
......@@ -277,3 +278,20 @@ check_display()
[ -n "$XSET" ] || return
$XSET -b
}
# Print command line and run command line
docmd()
{
SETCOLOR_SUCCESS
echo " \$ $@"
SETCOLOR_NORMAL
$@
}
# Print command line only
showcmd()
{
SETCOLOR_SUCCESS
echo " \$ $@"
SETCOLOR_NORMAL
}
#!/bin/sh
# Output formatting functions.
#
# Copyright (C) 2002 Ivan Zakharyaschev <imz@altlinux.ru>.
# Copyright (C) 2002 Dmitry V. Levin <ldv@altlinux.org>.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Set a sane TERM required for tput
[ -n "$TERM" ] || TERM=dumb
export TERM
# Offset from right margin of the screen to start status labels at.
: {RES_OFFSET:=8}
[ -n "$RES_OFFSET" ] && [ "$RES_OFFSET" -gt 0 ] 2>/dev/null || RES_OFFSET=8
isatty()
{
# see http://perl.plover.com/yak/commands-perl/samples/slide016.html
# python -c 'import os, sys; sys.exit(int(not os.isatty(1)))'
test -t 1
}
# Use color or no
isatty && TERMOUTPUT=1 || TERMOUTPUT=
# The cmd names and color codes used as arguments for tput(1)
# were taken from terminfo(5).
# Terminal sequence to move to that position.
MOVE_TO_COL()
{
[ -n "$COLUMNS" ] || COLUMNS=80
# "tput hpa N" moves to col N; on dumb terms does nothing.
local pos=$(($COLUMNS - $RES_OFFSET))
[ $pos -le 0 ] ||
tput -- hpa $(($COLUMNS - $RES_OFFSET)) # Horizontal Position Absolute.
}
# Enumerate colors
: ${BLACK:=0} ${RED:=1} ${GREEN:=2} ${YELLOW:=3} ${BLUE:=4} ${MAGENTA:=5} ${CYAN:=6} ${WHITE:=7}
# Set 'success' color (currently: green)
SETCOLOR_SUCCESS()
{
[ -n "$TERMOUTPUT" ] || return
{
echo bold
echo setaf $GREEN
} |tput -S
}
# Set 'failure' color (currently: red)
SETCOLOR_FAILURE()
{
[ -n "$TERMOUTPUT" ] || return
{
echo bold
echo setaf $RED
} |tput -S
}
# Set 'warning' color (currently: yellow)
SETCOLOR_WARNING()
{
[ -n "$TERMOUTPUT" ] || return
{
echo bold
echo setaf $YELLOW
} |tput -S
}
# Set 'info' color (currently: cyan)
SETCOLOR_INFO()
{
[ -n "$TERMOUTPUT" ] || return
{
echo bold
echo setaf $CYAN
} |tput -S
}
# Set 'banner' color (currently: blue on yellow)
SETCOLOR_BANNER()
{
[ -n "$TERMOUTPUT" ] || return
{
echo setaf $BLUE
echo setab $YELLOW
} |tput -S
}
# Terminal sequence to reset to the default color.
SETCOLOR_NORMAL()
{
[ -n "$TERMOUTPUT" ] || return
{
echo op; # set Original color Pair.
echo sgr0; # turn off all special graphics mode (bold in our case).
} |tput -S
}
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