summaryrefslogtreecommitdiffstats
path: root/colorclass/toggles.py
blob: 1ba6bce1993848ae1fc9bb724f7e8d8c9a8f6063 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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