Skip to content

Commit

Permalink
ColorPrinter: Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sils committed Mar 19, 2015
1 parent 6ed620c commit f9550ec
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions coalib/output/printers/ColorPrinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@

class ColorPrinter(Printer):
"""
Just use
p = AnyColorPrinter()
p.print("some", "output", delimiter=" ", end="", color="green");
Usage:
p = AnyColorPrinter()
p.print("some", "output", delimiter=" ", end="", color="green");
How to implement a color printer:
Just override the _print_colored() and _print_uncolored method.
Note that if _print_colored throws an exception, _print_uncolored
will be invoked.
Do not override _print() like usual printers do since the ColorPrinter
class handles this for you.
"""

def __init__(self):
Expand All @@ -21,7 +32,20 @@ def _print(self, output, **kwargs):
return self._print_uncolored(output, **kwargs)

def _print_colored(self, output, color=None, **kwargs):
"""
Override this! Prints the output colored.
:param output: The string to print.
:param color: The color to print the output in, as a string.
:param kwargs: Arbitrary additional keyword arguments you might need.
"""
raise NotImplementedError

def _print_uncolored(self, output, **kwargs):
"""
Override this! Prints the output uncolored.
:param output: The string to print.
:param kwargs: Arbitrary additional keyword arguments you might need.
"""
raise NotImplementedError

1 comment on commit f9550ec

@Udayan12167
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack.

Please sign in to comment.