Skip to content

Commit

Permalink
feat(colors): add function get_complex_color colored text in console
Browse files Browse the repository at this point in the history
* This function allows you to print colored text to the console output.
* Use your own text and color to print a color message on the console.
* Choose from 255 available colors.

Usage:

Assigning function to variable.

```python
mds = get_complex_color
```

Printing colored text on the same line by function calling.

```python
print(
    mds(),
    mds('example text', 77),
    mds(text='more example', color=99),
    mds(color=187) + mds('-dev', 86),
    mds('check it', 196)
)
```

feat(colors): add function `complex_color` define color console variable

* This function should not be changed.

fix(colors): moved variable from `show_complex_colort` to new function
fix(colors): cleanup docstring
  • Loading branch information
mdsanima committed Jun 3, 2021
1 parent 1d1bd60 commit 7a6704c
Showing 1 changed file with 55 additions and 8 deletions.
63 changes: 55 additions & 8 deletions src/mdsanima_dev/colors.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,75 @@
"""
# Colors Module
Definitions of the colors printed in to console output.
Definitions of complex colors printed in the console output with your own text.
"""

def complex_color():
"""
Define color console variables.
Returns:
literal: Color console variable.
Usage:
Assigning function calling to a variable.
.. code::
sx, xm, ex = complex_color()
start_c, middle_c, end_c = complex_color()
"""
sx = '\x1b[38;5;'
xm = 'm'
ex = '\x1b[0m'

return sx, xm, ex


def show_complex_color():
"""
This function prints all available colors with a number.
Function prints all available colors with a number.
Returns:
console_print: Show all colors.
print: Show all colors.
Usage:
Function calling.
.. code::
show_complex_color()
"""
# Define color console variables.
sx = '\x1b[38;5;'
ex = '\x1b[0m'
sx, xm, ex = complex_color()

# Print all colors with numbers.
for i in range(255):
color = (sx + str(i) + 'm' + 'color ' + str(i+1).ljust(3) + ex)
color = (sx + str(i) + xm + 'color -> ' + str(i+1).ljust(3) + ex)
print(color, sep = ' ', end = ' ', flush = True)

print('\n\nDONE')
return print('\n\nDONE')


def get_complex_color(text:str='mdsanima', color:int=255):
"""
This function allows you to print colored text to the console output.
Args:
text (str, optional): The text you want to use for color output
in the console. Defaults to 'mdsanima'.
color (int, optional): The color number you want to use for color
output in the console. Defaults to 255.
Returns:
str: Colored text output in the console.
Usage:
Assigning function to variable.
.. code::
mds = get_complex_color
Printing colored text on the same line by function calling.
.. code::
print(
mds(),
mds('example text', 77),
mds(text='more example', color=99),
mds(color=187) + mds('-dev', 86),
mds('check it', 196)
)
"""
sx, xm, ex = complex_color()

return (sx + str(color) + xm + text + ex)

0 comments on commit 7a6704c

Please sign in to comment.