*,
force_16color: bool = False,
force_216color: bool = False) -> str:
+ """Return the ANSI escape sequence to change the foreground color
+ being printed. Target colors may be indicated by name or R/G/B.
+ Result will use the 16 or 216 color scheme if force_16color or
+ force_216color are passed (respectively). Otherwise the code will
+ do what it thinks best.
+
+ >>> import string_utils as su
+ >>> su.to_base64(fg('blue'))
+ b'G1szODs1OzIxbQ==\\n'
+
+ """
import string_utils
if name is not None and name == 'reset':
red: Optional[int] = None,
green: Optional[int] = None,
blue: Optional[int] = None) -> Tuple[int, int, int]:
+ """This method will return a red, green, blue tuple representing a
+ contrasting color given the red, green, blue of a background
+ color or a color name of the background color.
+
+ >>> pick_contrasting_color(None, 20, 20, 20)
+ (255, 255, 255)
+
+ >>> pick_contrasting_color("white")
+ (0, 0, 0)
+
+ """
import string_utils
if name is not None and string_utils.is_full_string(name):
*,
force_16color: bool = False,
force_216color: bool = False) -> str:
+ """Returns an ANSI color code for changing the current background
+ color.
+
+ >>> import string_utils as su
+ >>> su.to_base64(bg("red")) # b'\x1b[48;5;196m'
+ b'G1s0ODs1OzE5Nm0=\\n'
+
+ """
import string_utils
if name is not None and name == 'reset':
class ProgrammableColorizer(StdoutInterceptor):
- def __init__(self, patterns: Iterable[Tuple[re.Pattern, Callable[[Any, re.Pattern], str]]]):
+ def __init__(
+ self,
+ patterns: Iterable[Tuple[re.Pattern, Callable[[Any, re.Pattern], str]]]
+ ):
super().__init__()
self.patterns = [_ for _ in patterns]
if __name__ == '__main__':
def main() -> None:
+ import doctest
+ doctest.testmod()
+
name = " ".join(sys.argv[1:])
for possibility in COLOR_NAMES_TO_RGB:
if name in possibility: