jsvn: add ANSI color/reset functions
This commit is contained in:
parent
7b05ea18cb
commit
ea8f2ca8c6
25
jsvn
25
jsvn
@ -58,9 +58,34 @@ RET_OK = 0
|
|||||||
RET_ERR = 1
|
RET_ERR = 1
|
||||||
RET_REEXEC = 2
|
RET_REEXEC = 2
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
# ANSI escape color code values #
|
||||||
|
###########################################################################
|
||||||
|
COLORS = {
|
||||||
|
'black': 0,
|
||||||
|
'red': 1,
|
||||||
|
'green': 2,
|
||||||
|
'yellow': 3,
|
||||||
|
'blue': 4,
|
||||||
|
'magenta': 5,
|
||||||
|
'cyan': 6,
|
||||||
|
'white': 7,
|
||||||
|
}
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Utility Functions #
|
# Utility Functions #
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
def ansi_color(out, fg=None, bg=None, bold=False):
|
||||||
|
if bold is not None:
|
||||||
|
out.write('\033[1m')
|
||||||
|
if fg is not None:
|
||||||
|
out.write('\033[%dm' % (30 + COLORS[fg]))
|
||||||
|
if bg is not None:
|
||||||
|
out.write('\033[%dm' % (40 + COLORS[bg]))
|
||||||
|
|
||||||
|
def ansi_reset(out):
|
||||||
|
out.write('\033[0m')
|
||||||
|
|
||||||
def findInPath(cmd):
|
def findInPath(cmd):
|
||||||
path_entries = os.environ['PATH'].split(os.pathsep)
|
path_entries = os.environ['PATH'].split(os.pathsep)
|
||||||
for p in path_entries:
|
for p in path_entries:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user