Skip to content

Base#

Color #

Color(content, fg=None, bg=None, style=None)

Color decorator

Parameters:

Name Type Description Default
content Any

string to be colored

required
fg ColorTypes

font color (or) foreground color

None
bg BgColorTypes

background color

None
style FontTypes

font style

None

properties property #

properties: Tuple[ColorTypes, BgColorTypes, FontTypes]

Properties of the string/font

Returns:

Type Description
Tuple[ColorTypes, BgColorTypes, FontTypes]

foreground, background color and font style

value property #

value: ColorString

Returns:

Type Description
ColorString

colored string

__add__ #

__add__(color)

Concatenates two colors

Parameters:

Name Type Description Default
color Any

color decorator or string

required

Returns:

Type Description
ColorString

colored string

Raises:

Type Description
ValueError

if the color is not Color type and not string

__eq__ #

__eq__(color)

Compares the two Colors properties and values

Parameters:

Name Type Description Default
color Any

color decorator or normal string

required

Returns:

Type Description
bool

True if the properties & values are same else False

Raises:

Type Description
ValueError

if the color is not Color type

__len__ #

__len__()

Returns:

Name Type Description
length int

length of the string

__str__ #

__str__()

Returns:

Type Description
ColorString

colored string

replace #

replace(
    value=MISSING, fg=MISSING, bg=MISSING, style=MISSING
)

Replaces the properties

Parameters:

Name Type Description Default
value Any

string to be colored

MISSING
fg ColorTypes

font color (or) foreground color

MISSING
bg BgColorTypes

background color

MISSING
style FontTypes

font style

MISSING

RGB #

RGB(red, green, blue)

RGB color decorator

Parameters:

Name Type Description Default
red int

ranges from 0 to 255

required
green int

ranges from 0 to 255

required
blue int

ranges from 0 to 255

required

Raises:

Type Description
ValueError

if the rgb color code is invalid

hex_code property #

hex_code: str

Returns:

Name Type Description
code str

hex color code

value property #

value: Tuple[int, int, int]

Returns:

Name Type Description
code Tuple[int, int, int]

rgb color code

from_hex classmethod #

from_hex(color)

Converts hex color code to rgb color code

Parameters:

Name Type Description Default
color Union[str, int]

hex color code

required

Returns:

Type Description
RGB

RGB color decorator

Raises:

Type Description
ValueError

if the hex color code is invalid

Examples:

# orange color
RGB.from_hex("#ffa500")
RGB.from_hex("ffa500")
RGB.from_hex(0xffa500)

Template #

Template(fg=None, bg=None, style=None)

Color/Font template

Parameters:

Name Type Description Default
fg ColorTypes

font color (or) foreground color

None
bg BgColorTypes

background color

None
style FontTypes

font style

None

Raises:

Type Description
ValueError

if no argument is passed

Examples:

T1 = Template(fg=Colors.red, style=FontStyles.bold)
print(T1("hello"), T1("world"))

__call__ #

__call__(content)

color decorator

Parameters:

Name Type Description Default
content Any

string to be colored

required

Returns:

Type Description
Color

color decorator

__eq__ #

__eq__(template)

compares the two templates

:param template:

Returns:

Type Description
bool

True if the properties are same else False

Raises:

Type Description
ValueError

if the color is not Template type

edit #

edit(fg=MISSING, bg=MISSING, style=MISSING)

Edits the template properties

Parameters:

Name Type Description Default
fg ColorTypes

font color (or) foreground color

MISSING
bg BgColorTypes

background color

MISSING
style FontTypes

font style

MISSING