From 896739353a613f23c007d9acaa2809010a522a37 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 16 Sep 2022 11:10:14 +0200 Subject: Adding upstream version 2.2.0. Signed-off-by: Daniel Baumann --- colorclass/toggles.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 colorclass/toggles.py (limited to 'colorclass/toggles.py') diff --git a/colorclass/toggles.py b/colorclass/toggles.py new file mode 100644 index 0000000..1ba6bce --- /dev/null +++ b/colorclass/toggles.py @@ -0,0 +1,42 @@ +"""Convenience functions to enable/disable features.""" + +from colorclass.codes import ANSICodeMapping + + +def disable_all_colors(): + """Disable all colors. Strip any color tags or codes.""" + ANSICodeMapping.disable_all_colors() + + +def enable_all_colors(): + """Enable colors.""" + ANSICodeMapping.enable_all_colors() + + +def disable_if_no_tty(): + """Disable all colors if there is no TTY available. + + :return: True if colors are disabled, False if stderr or stdout is a TTY. + :rtype: bool + """ + return ANSICodeMapping.disable_if_no_tty() + + +def is_enabled(): + """Are colors enabled.""" + return not ANSICodeMapping.DISABLE_COLORS + + +def set_light_background(): + """Choose dark colors for all 'auto'-prefixed codes for readability on light backgrounds.""" + ANSICodeMapping.set_light_background() + + +def set_dark_background(): + """Choose dark colors for all 'auto'-prefixed codes for readability on light backgrounds.""" + ANSICodeMapping.set_dark_background() + + +def is_light(): + """Are background colors for light backgrounds.""" + return ANSICodeMapping.LIGHT_BACKGROUND -- cgit v1.2.3