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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
from easyansi._core.codes import CSI as _CSI
from easyansi._core.prnt import prnt as _prnt
from easyansi._core.colors.common_colors import reset_code, reset
def _build_attribute_code(color_cd: str) -> str:
"""Take an attribute code and return the ANSI sequence."""
return _CSI + color_cd + "m"
_COLOR_DICT = {"bright": _build_attribute_code("1"),
"dim": _build_attribute_code("2"),
"normal": _build_attribute_code("22"),
"italic": _build_attribute_code("3"),
"italic_off": _build_attribute_code("23"),
"underline": _build_attribute_code("4"),
"underline_off": _build_attribute_code("24"),
"blink": _build_attribute_code("5"),
"blink_off": _build_attribute_code("25"),
"reverse": _build_attribute_code("7"),
"reverse_off": _build_attribute_code("27"),
"conceal": _build_attribute_code("8"),
"conceal_off": _build_attribute_code("28"),
"strikethrough": _build_attribute_code("9"),
"strikethrough_off": _build_attribute_code("29"),
}
def bright_code() -> str:
"""Return the ANSI code to turn bright on."""
# Testing has shown bright does not always work unless the normal code is sent first.
return _COLOR_DICT["normal"] + _COLOR_DICT["bright"]
def bright() -> None:
"""Output the ANSI code to turn bright on."""
_prnt(bright_code())
def dim_code() -> str:
"""Return the ANSI code to turn dim on."""
# Testing has shown dim does not always work unless the normal code is sent first.
return _COLOR_DICT["normal"] + _COLOR_DICT["dim"]
def dim() -> None:
"""Output the ANSI code to turn dim on."""
_prnt(dim_code())
def normal_code() -> str:
"""Return the ANSI code to turn normal (not bright or dim) on."""
return _COLOR_DICT["normal"]
def normal() -> None:
"""Output the ANSI code to turn normal (not bright or dim) on."""
_prnt(normal_code())
def italic_code() -> str:
"""Return the ANSI code to turn italics on."""
return _COLOR_DICT["italic"]
def italic() -> None:
"""Output the ANSI code to turn italics on."""
_prnt(italic_code())
def italic_off_code() -> str:
"""Return the ANSI code to turn italics off."""
return _COLOR_DICT["italic_off"]
def italic_off() -> None:
"""Output the ANSI code to turn italics off."""
_prnt(italic_off_code())
def underline_code() -> str:
"""Return the ANSI code to turn underline on."""
return _COLOR_DICT["underline"]
def underline() -> None:
"""Output the ANSI code to turn underline on."""
_prnt(underline_code())
def underline_off_code() -> str:
"""Return the ANSI code to turn underline off."""
return _COLOR_DICT["underline_off"]
def underline_off() -> None:
"""Output the ANSI code to turn underline off."""
_prnt(underline_off_code())
def blink_code() -> str:
"""Return the ANSI code to turn blink on."""
return _COLOR_DICT["blink"]
def blink() -> None:
"""Output the ANSI code to turn blink on."""
_prnt(blink_code())
def blink_off_code() -> str:
"""Return the ANSI code to turn blink off."""
return _COLOR_DICT["blink_off"]
def blink_off() -> None:
"""Output the ANSI code to turn blink off."""
_prnt(blink_off_code())
def reverse_code() -> str:
"""Return the ANSI code to turn reverse on."""
return _COLOR_DICT["reverse"]
def reverse() -> None:
"""Output the ANSI code to turn reverse on."""
_prnt(reverse_code())
def reverse_off_code() -> str:
"""Return the ANSI code to turn reverse off."""
return _COLOR_DICT["reverse_off"]
def reverse_off() -> None:
"""Output the ANSI code to turn reverse off."""
_prnt(reverse_off_code())
def conceal_code() -> str:
"""Return the ANSI code to turn conceal on."""
return _COLOR_DICT["conceal"]
def conceal() -> None:
"""Output the ANSI code to turn conceal on."""
_prnt(conceal_code())
def conceal_off_code() -> str:
"""Return the ANSI code to turn conceal off."""
return _COLOR_DICT["conceal_off"]
def conceal_off() -> None:
"""Output the ANSI code to turn conceal off."""
_prnt(conceal_off_code())
def strikethrough_code() -> str:
"""Return the ANSI code to turn strikethrough on."""
return _COLOR_DICT["strikethrough"]
def strikethrough() -> None:
"""Output the ANSI code to turn strikethrough on."""
_prnt(strikethrough_code())
def strikethrough_off_code() -> str:
"""Return the ANSI code to turn strikethrough off."""
return _COLOR_DICT["strikethrough_off"]
def strikethrough_off() -> None:
"""Output the ANSI code to turn strikethrough off."""
_prnt(strikethrough_off_code())
|