diff options
author | Martin Matusiak <numerodix@gmail.com> | 2014-03-08 23:50:39 +0100 |
---|---|---|
committer | Martin Matusiak <numerodix@gmail.com> | 2014-03-08 23:50:39 +0100 |
commit | 479f6830d9def3664c41dd4ba50c18f5125f961e (patch) | |
tree | f3586544de02d220131fc5c2230e0fbc768e38ae | |
parent | 42268817c0b4da7aaa57ebbb2fc6665c8b01b601 (diff) | |
parent | f85ef8221807457909a91b543b338b0bc0b0af9e (diff) | |
download | ansicolor-479f6830d9def3664c41dd4ba50c18f5125f961e.tar.gz |
Merge branch 'release/0.1.2'0.1.2
-rw-r--r-- | README.rst | 5 | ||||
-rw-r--r-- | ansicolor/ansicolor.py | 57 | ||||
-rw-r--r-- | docs/conf.py | 5 | ||||
-rw-r--r-- | setup.cfg | 2 |
4 files changed, 59 insertions, 10 deletions
@@ -103,3 +103,8 @@ Take a look at the ``demos`` to see what's possible. $ python -m ansicolor.demos --color $ python -m ansicolor.demos --highlight $ python -m ansicolor.demos --diff + +Also see the `API documentation`_. + + +.. _`API documentation`: https://ansicolor.readthedocs.org/ diff --git a/ansicolor/ansicolor.py b/ansicolor/ansicolor.py index 628078a..526d87d 100644 --- a/ansicolor/ansicolor.py +++ b/ansicolor/ansicolor.py @@ -13,6 +13,7 @@ __all__ = ['Colors', import difflib import os +import re import sys # Don't write escapes to dumb terminals @@ -53,7 +54,14 @@ Colors.new("White") def make_func(color): def f(s, bold=False, reverse=False): return colorize(s, color, bold=bold, reverse=reverse) - f.__doc__ = "Colorize string with %s" % color.__name__.lower() + f.__doc__ = """ + Colorize string in %s + + :param string s: The string to colorize. + :param bool bold: Whether to mark up in bold. + :param bool reverse: Whether to mark up in reverse video. + :rtype: string + """ % color.__name__.lower() return f for color in Colors.iter(): @@ -79,7 +87,16 @@ def get_highlighter(colorid): return highlight_map[colorid % len(highlights)] def get_code(color, bold=False, reverse=False): - '''Return escape code for styling with color, bold or reverse''' + """Returns the escape code for styling with the given color, + in bold and/or reverse. + + :param color: The color to use. + :type color: :class:`Colors` class + :param bool bold: Whether to mark up in bold. + :param bool reverse: Whether to mark up in reverse video. + :rtype: string + """ + if _disabled: return "" @@ -95,7 +112,16 @@ def get_code(color, bold=False, reverse=False): return '\033[' + fmt + color + 'm' def colorize(s, color, bold=False, reverse=False): - '''Colorize the string''' + """ + Colorize string with the color given. + + :param string s: The string to colorize. + :param color: The color to use. + :type color: :class:`Colors` class + :param bool bold: Whether to mark up in bold. + :param bool reverse: Whether to mark up in reverse video. + :rtype: string + """ return ("%s%s%s" % (get_code(color, bold=bold, reverse=reverse), s, get_code(None))) @@ -197,7 +223,22 @@ def highlight_string(s, *spanlists, **kw): return ''.join(segments) def colordiff(x, y, color_x=Colors.Cyan, color_y=Colors.Green, debug=False): - """Format diff of inputs using longest common subsequence""" + """ + Formats a diff of two strings using the longest common subsequence by + highlighting characters that differ between the strings. + + Returns the strings `x` and `y` with highlighting. + + :param string x: The first string. + :param string y: The second string. + :param color_x: The color to use for the first string. + :type color_x: :class:`Colors` class + :param color_y: The color to use for the second string. + :type color_y: :class:`Colors` class + :param bool debug: Whether to print debug output underway. + :rtype: tuple + """ + def compute_seq(x, y): """SequenceMatcher computes the longest common contiguous subsequence rather than the longest common subsequence, but this just causes the @@ -281,8 +322,12 @@ def justify_formatted(s, justify_func, width): return justify_func(s, width + dx) def strip_escapes(s): - '''Strip escapes from string''' - import re + """Strips escapes from the string. + + :param string s: The string. + :rtype: string + """ + return re.sub('\033[[](?:(?:[0-9]*;)*)(?:[0-9]*m)', '', s) ## Output functions diff --git a/docs/conf.py b/docs/conf.py index 9b51d7a..afcc661 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -13,7 +13,6 @@ # serve to show the default. import sys -import os try: import ansicolor @@ -56,7 +55,7 @@ master_doc = 'index' # General information about the project. project = ansicolor.__name__ -copyright = u'2014, %s' % author +copyright = u'2010-2014, %s' % author # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -276,7 +275,7 @@ texinfo_documents = [ epub_title = ansicolor.__name__ epub_author = author epub_publisher = author -epub_copyright = u'2014, %s' % author +epub_copyright = u'2010-2014, %s' % author # The basename for the epub file. It defaults to the project name. #epub_basename = u'ansicolor' @@ -1,5 +1,5 @@ [flake8] -exclude = .tox/,build/ +exclude = .tox/,build/,docs/ ignore = E301,E302,E303 [wheel] |