MCPcopy Create free account
hub / github.com/numpy/numpy / colour_text

Function colour_text

numpy/distutils/misc_util.py:353–366  ·  view source on GitHub ↗
(s, fg=None, bg=None, bold=False)

Source from the content-addressed store, hash-verified

351 _colour_codes = dict(black=0, red=1, green=2, yellow=3,
352 blue=4, magenta=5, cyan=6, white=7, default=9)
353 def colour_text(s, fg=None, bg=None, bold=False):
354 seq = []
355 if bold:
356 seq.append('1')
357 if fg:
358 fgcode = 30 + _colour_codes.get(fg.lower(), 0)
359 seq.append(str(fgcode))
360 if bg:
361 bgcode = 40 + _colour_codes.get(bg.lower(), 7)
362 seq.append(str(bgcode))
363 if seq:
364 return '\x1b[%sm%s\x1b[0m' % (';'.join(seq), s)
365 else:
366 return s
367else:
368 def colour_text(s, fg=None, bg=None):
369 return s

Callers 6

default_textFunction · 0.85
red_textFunction · 0.85
green_textFunction · 0.85
yellow_textFunction · 0.85
cyan_textFunction · 0.85
blue_textFunction · 0.85

Calls 3

lowerMethod · 0.80
getMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected