Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added missing termcolors module

  • Loading branch information...
commit ea72550684a455fc19b7adffc48b5dfe472f0b24 1 parent 1f69b84
Armin Ronacher authored

Showing 2 changed files with 74 additions and 1 deletion. Show diff stats Hide diff stats

  1. +4 1 Makefile
  2. +70 0 logbook/_termcolors.py
5 Makefile
@@ -8,6 +8,9 @@ clean-pyc:
8 8 test:
9 9 @python test_logbook.py --verbose
10 10
  11 +bench:
  12 + @python benchmark/run.py
  13 +
11 14 upload-docs:
12 15 make -C docs html SPHINXOPTS=-Aonline=1
13 16 python setup.py upload_docs
@@ -19,4 +22,4 @@ logbook/_speedups.so: logbook/_speedups.pyx
19 22
20 23 cybuild: logbook/_speedups.so
21 24
22   -.PHONY: test upload-docs clean-pyc cybuild all
  25 +.PHONY: test upload-docs clean-pyc cybuild bench all
70 logbook/_termcolors.py
... ... @@ -0,0 +1,70 @@
  1 +# -*- coding: utf-8 -*-
  2 +"""
  3 + logbook._termcolors
  4 + ~~~~~~~~~~~~~~~~~~~
  5 +
  6 + Provides terminal color mappings.
  7 +
  8 + :copyright: (c) 2010 by Armin Ronacher, Georg Brandl.
  9 + :license: BSD, see LICENSE for more details.
  10 +"""
  11 +
  12 +esc = "\x1b["
  13 +
  14 +codes = {}
  15 +codes[""] = ""
  16 +codes["reset"] = esc + "39;49;00m"
  17 +
  18 +codes["bold"] = esc + "01m"
  19 +codes["faint"] = esc + "02m"
  20 +codes["standout"] = esc + "03m"
  21 +codes["underline"] = esc + "04m"
  22 +codes["blink"] = esc + "05m"
  23 +codes["overline"] = esc + "06m"
  24 +
  25 +dark_colors = ["black", "darkred", "darkgreen", "brown", "darkblue",
  26 + "purple", "teal", "lightgray"]
  27 +light_colors = ["darkgray", "red", "green", "yellow", "blue",
  28 + "fuchsia", "turquoise", "white"]
  29 +
  30 +x = 30
  31 +for d, l in zip(dark_colors, light_colors):
  32 + codes[d] = esc + "%im" % x
  33 + codes[l] = esc + "%i;01m" % x
  34 + x += 1
  35 +
  36 +del d, l, x
  37 +
  38 +codes["darkteal"] = codes["turquoise"]
  39 +codes["darkyellow"] = codes["brown"]
  40 +codes["fuscia"] = codes["fuchsia"]
  41 +codes["white"] = codes["bold"]
  42 +
  43 +
  44 +def colorize(color_key, text):
  45 + """Returns an ANSI formatted text with the given color."""
  46 + return codes[color_key] + text + codes["reset"]
  47 +
  48 +
  49 +def ansiformat(attr, text):
  50 + """Format ``text`` with a color and/or some attributes::
  51 +
  52 + color normal color
  53 + *color* bold color
  54 + _color_ underlined color
  55 + +color+ blinking color
  56 + """
  57 + result = []
  58 + if attr[:1] == attr[-1:] == '+':
  59 + result.append(codes['blink'])
  60 + attr = attr[1:-1]
  61 + if attr[:1] == attr[-1:] == '*':
  62 + result.append(codes['bold'])
  63 + attr = attr[1:-1]
  64 + if attr[:1] == attr[-1:] == '_':
  65 + result.append(codes['underline'])
  66 + attr = attr[1:-1]
  67 + result.append(codes[attr])
  68 + result.append(text)
  69 + result.append(codes['reset'])
  70 + return ''.join(result)

0 comments on commit ea72550

Please sign in to comment.
Something went wrong with that request. Please try again.