Use named constants for terminal control codes.
(apenwarr slightly changed the minimal/do tty detection.)
This commit is contained in:
parent
eea3f5446a
commit
cb1512b14b
2 changed files with 36 additions and 24 deletions
44
log.py
44
log.py
|
|
@ -1,6 +1,22 @@
|
|||
import sys, os
|
||||
import vars
|
||||
|
||||
# By default, no output colouring.
|
||||
RED = ""
|
||||
GREEN = ""
|
||||
YELLOW = ""
|
||||
BOLD = ""
|
||||
PLAIN = ""
|
||||
|
||||
if sys.stderr.isatty():
|
||||
# ...use ANSI formatting codes.
|
||||
RED = "\x1b[31m"
|
||||
GREEN = "\x1b[32m"
|
||||
YELLOW = "\x1b[33m"
|
||||
BOLD = "\x1b[1m"
|
||||
PLAIN = "\x1b[m"
|
||||
|
||||
|
||||
def log_(s):
|
||||
sys.stdout.flush()
|
||||
if vars.DEBUG_PIDS:
|
||||
|
|
@ -10,30 +26,14 @@ def log_(s):
|
|||
sys.stderr.flush()
|
||||
|
||||
|
||||
def _clog(s):
|
||||
log_('\x1b[32mredo %s\x1b[1m%s\x1b[m' % (vars.DEPTH, s))
|
||||
def _bwlog(s):
|
||||
log_('redo %s%s' % (vars.DEPTH, s))
|
||||
def log(s):
|
||||
log_(''.join([GREEN, "redo ", vars.DEPTH, BOLD, s, PLAIN]))
|
||||
|
||||
def _cerr(s):
|
||||
log_('\x1b[31mredo: %s\x1b[1m%s\x1b[m' % (vars.DEPTH, s))
|
||||
def _bwerr(s):
|
||||
log_('redo: %s%s' % (vars.DEPTH, s))
|
||||
def err(s):
|
||||
log_(''.join([RED, "redo ", vars.DEPTH, BOLD, s, PLAIN]))
|
||||
|
||||
def _cwarn(s):
|
||||
log_('\x1b[33mredo: %s\x1b[1m%s\x1b[m' % (vars.DEPTH, s))
|
||||
def _bwwarn(s):
|
||||
log_('redo: %s%s' % (vars.DEPTH, s))
|
||||
|
||||
|
||||
if os.isatty(2):
|
||||
log = _clog
|
||||
err = _cerr
|
||||
warn = _cwarn
|
||||
else:
|
||||
log = _bwlog
|
||||
err = _bwerr
|
||||
warn = _bwwarn
|
||||
def warn(s):
|
||||
log_(''.join([YELLOW, "redo ", vars.DEPTH, BOLD, s, PLAIN]))
|
||||
|
||||
|
||||
def debug(s):
|
||||
|
|
|
|||
16
minimal/do
16
minimal/do
|
|
@ -6,6 +6,18 @@
|
|||
# The author disclaims copyright to this source file and hereby places it in
|
||||
# the public domain. (2010 12 14)
|
||||
#
|
||||
|
||||
# By default, no output coloring.
|
||||
GREEN=""
|
||||
BOLD=""
|
||||
PLAIN=""
|
||||
|
||||
if tty <&2 >/dev/null 2>&1; then
|
||||
GREEN="$(printf '\033[32m')"
|
||||
BOLD="$(printf '\033[1m')"
|
||||
PLAIN="$(printf '\033[m')"
|
||||
fi
|
||||
|
||||
_dirsplit()
|
||||
{
|
||||
base=${1##*/}
|
||||
|
|
@ -72,8 +84,8 @@ _do()
|
|||
DIR=$1
|
||||
TARGET=$2
|
||||
if [ ! -e "$TARGET" ] || [ -e "$TARGET/." -a ! -e "$TARGET.did" ]; then
|
||||
printf '\033[32mdo %s\033[1m%s\033[m\n' \
|
||||
"$DO_DEPTH" "$DIR$TARGET" >&2
|
||||
printf '%sdo %s%s%s%s\n' \
|
||||
"$GREEN" "$DO_DEPTH" "$BOLD" "$DIR$TARGET" "$PLAIN" >&2
|
||||
echo "$PWD/$TARGET" >>"$DO_BUILT"
|
||||
DOFILE=$TARGET.do
|
||||
BASE=$TARGET
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue