diff options
-rw-r--r-- | data/graphics/jump | 5 | ||||
-rw-r--r-- | library/pippy/console.py | 50 |
2 files changed, 54 insertions, 1 deletions
diff --git a/data/graphics/jump b/data/graphics/jump index be9b49e..f74ea71 100644 --- a/data/graphics/jump +++ b/data/graphics/jump @@ -2,6 +2,11 @@ import pippy for i in xrange(0,50): pippy.console.clear() + if i < 25: + pippy.console.red() + else: + pippy.console.blue() + # Note that we have to escape backslashes print "\\o/" print "_|_" diff --git a/library/pippy/console.py b/library/pippy/console.py index cdbb023..1a00c89 100644 --- a/library/pippy/console.py +++ b/library/pippy/console.py @@ -1,5 +1,53 @@ """Console helpers for pippy.""" +import sys def clear(): """Clear screen on console.""" # magic escape sequence - print '\x1B[H\x1B[J' # clear screen + sys.stdout.write('\x1B[H\x1B[J') + +def red(): + """Change text color to red.""" + # magic escape sequence. + sys.stdout.write('\x1B[0;31m') + +def green(): + """Change text color to green.""" + # magic escape sequence. + sys.stdout.write('\x1B[0;32m') + +def orange(): + """Change text color to orange.""" + # magic escape sequence. + sys.stdout.write('\x1B[0;33m') + +def blue(): + """Change text color to blue.""" + # magic escape sequence. + sys.stdout.write('\x1B[0;34m') + +def purple(): + """Change text color to purple.""" + # magic escape sequence. + sys.stdout.write('\x1B[0;35m') + +def cyan(): + """Change text color to cyan.""" + # magic escape sequence. + sys.stdout.write('\x1B[0;36m') + +def grey(): + """Change text color to grey.""" + # magic escape sequence. + sys.stdout.write('\x1B[0;37m') +gray=grey + +def black(): + """Change text color to blue.""" + # magic escape sequence. + # ;38m seems to be identical to this one. + sys.stdout.write('\x1B[0;39m') + +def reset(): + """Clear screen and reset text color to black.""" + clear() + black() |