Skip to content

Commit

Permalink
docs: add color badge and fix tab item path
Browse files Browse the repository at this point in the history
fix: code cleanup
  • Loading branch information
mdsanima committed Apr 1, 2022
1 parent d5fb5ff commit aaaa37a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 85 deletions.
39 changes: 20 additions & 19 deletions docs/source/modules/colors.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
# Module `colors`
# Module {bdg-success-line}`colors`

```{eval-rst}
.. automodule:: mdsanima_dev.colors
```

## Function `set_complex_color`
## Function {bdg-primary-line}`set_complex_color`

```{eval-rst}
.. autofunction:: mdsanima_dev.colors.set_complex_color
```

## Function `get_color`
## Function {bdg-primary-line}`get_color`

```{eval-rst}
.. autofunction:: mdsanima_dev.colors.get_color
```

## Function `get_complex_color`
## Function {bdg-primary-line}`get_complex_color`

```{eval-rst}
.. autofunction:: mdsanima_dev.colors.get_complex_color
```

## Function `show_complex_color`
## Function {bdg-primary-line}`show_complex_color`

```{eval-rst}
.. autofunction:: mdsanima_dev.colors.show_complex_color
```

### Example ``show_complex_color(False)``
### Example {bdg-primary-line}`show_complex_color(False)`

```{eval-rst}
This is a example screenshots of the ``Shell Terminal`` in different variants,
This is a example screenshots of the `Shell Terminal` in different variants,
just for fun.
```

Expand All @@ -40,30 +40,30 @@ just for fun.
.. tab-item:: Shell Acrylic
.. figure:: ../_static/screenshot/color_show_01_acrylic_a.jpg
.. figure:: ../_static/img/screenshot/color_show_01_acrylic_a.jpg
:name: show-complex-color-false-ac-a
.. tab-item:: Shell Dark
.. figure:: ../_static/screenshot/color_show_01_dark_a.jpg
.. figure:: ../_static/img/screenshot/color_show_01_dark_a.jpg
:name: show-complex-color-false-dk-a
.. tab-item:: Shell Acrylic Border
:selected:
.. figure:: ../_static/screenshot/color_show_01_acrylic_b.jpg
.. figure:: ../_static/img/screenshot/color_show_01_acrylic_b.jpg
:name: show-complex-color-false-ac-b
.. tab-item:: Shell Dark Border
.. figure:: ../_static/screenshot/color_show_01_dark_b.jpg
.. figure:: ../_static/img/screenshot/color_show_01_dark_b.jpg
:name: show-complex-color-false-dk-b
```

### Example ``show_complex_color(True)``
### Example {bdg-primary-line}`show_complex_color(True)`

```{eval-rst}
This is a example screenshots of the ``Shell Terminal`` in different variants,
This is a example screenshots of the `Shell Terminal` in different variants,
just for fun.
```

Expand All @@ -72,27 +72,28 @@ just for fun.
.. tab-item:: Shell Acrylic
.. figure:: ../_static/screenshot/color_show_02_acrylic_a.jpg
.. figure:: ../_static/img/screenshot/color_show_02_acrylic_a.jpg
:name: show-complex-color-true-ac-a
.. tab-item:: Shell Dark
:selected:
.. figure:: ../_static/screenshot/color_show_02_dark_a.jpg
.. figure:: ../_static/img/screenshot/color_show_02_dark_a.jpg
:name: show-complex-color-true-dk-a
.. tab-item:: Shell Acrylic Border
.. figure:: ../_static/screenshot/color_show_02_acrylic_b.jpg
.. figure:: ../_static/img/screenshot/color_show_02_acrylic_b.jpg
:name: show-complex-color-true-ac-b
.. tab-item:: Shell Dark Border
.. figure:: ../_static/screenshot/color_show_02_dark_b.jpg
.. figure:: ../_static/img/screenshot/color_show_02_dark_b.jpg
:name: show-complex-color-true-dk-b
```

```{admonition} Note
Now you know what numbers you have withs different colors, now you can use
the function [``get_complex_color``](#function-get-complex-color) in your code.
Now you know what numbers you have withs different colors, now you can use the
function {bdg-link-primary-line}`get_complex_color <#function-get-complex-color>`
in your code.
```
122 changes: 56 additions & 66 deletions src/mdsanima_dev/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ def set_complex_color() -> str:
:return: Color console literal variable.
:rtype: str
.. admonition:: USAGE PYTHON
:class: hint
:usage: Assigning a function to a variable:
*Assigning a function to a variable:*
.. code:: python
.. code:: python
sx, xm, ex = complex_color()
start_c, middle_c, end_c = complex_color()
sx, xm, ex = complex_color()
start_c, middle_c, end_c = complex_color()
.. admonition:: WARNING
:class: warning
Do not use this function in your code, it is needed to perform other
functions.
Do not use this function in your code, it is needed to perform
other functions.
"""
sx = "\x1b[38;5;"
xm = "m"
Expand All @@ -33,117 +30,110 @@ def set_complex_color() -> str:
return sx, xm, ex


def get_color(text: str = "mdsanima", color: int = 255) -> str:
def get_color(text: str="mdsanima", color: int=255) -> str:
"""This function is almost the same as
`get_complex_color <#function-get-complex-color>`_ function.
:bdg-link-primary-line:`get_complex_color <#function-get-complex-color>`
function.
The difference is that the return is a sequence of unicode characters
and to get the output in the terminal in a color you need to use the
print function.
:param text: The text you want to use for color output in the console,
defaults to ``mdsanima``.
defaults to mdsanima.
:type text: str, optional
:param color: The color number you want to use for color output in the
console, defaults to 255.
:type color: int, optional
:return: Colored text output in the console.
:rtype: str
.. admonition:: USAGE PYTHON
:class: hint
:usage:
Assigning a function by calling to variable:
.. code:: python
*Assigning a function by* `calling <#code-calling>`_ *to variable.*
`Assigning <#code-assigning>`_ *a function to a variable.*
*Also you can use* `machine <../modules/tools.html#function-machine>`_
*function on this* `code example <#code-machine>`_ *block:*
mds_a = get_color("I love Python", 86)
mds_b = get_color("mdsanima", 186)
print(mds_a, mds_b)
.. _code-calling:
.. code:: python
Assigning a function to a variable:
mds_a = get_color("I love Python", 86)
mds_b = get_color("mdsanima", 186)
print(mds_a, mds_b)
.. code:: python
.. _code-assigning:
.. code:: python
mds = get_color
mds_a = mds("I love Python", 86)
mds_b = mds("mdsanima", 186)
print(mds_a, mds_b)
mds = get_color
mds_a = mds("I love Python", 86)
mds_b = mds("mdsanima", 186)
print(mds_a, mds_b)
Also you can use
:bdg-link-primary-line:`machine <../modules/tools.html#function-machine>`
function:
.. _code-machine:
.. code:: python
.. code:: python
from mdsanima_dev.utils.tools import machine
mds = get_color
mds_a = mds("I love Python", 86)
mds_b = mds("mdsanima", 186)
machine(mds_a + " " + mds_b, 0.01)
from mdsanima_dev.utils.tools import machine
mds = get_color
mds_a = mds("I love Python", 86)
mds_b = mds("mdsanima", 186)
machine(mds_a + " " + mds_b, 0.01)
"""
sx, xm, ex = set_complex_color()

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


def get_complex_color(
text: str = "mdsanima", color: int = 255, end=None
) -> str:
"""
This feature allows you to print colored text to the output of the console.
Now the function works the same like print function.
def get_complex_color(text: str="mdsanima", color: int=255, end=None) -> str:
"""This feature allows you to print colored text to the output of the
console. Now the function works the same like print function.
:param text: The text you want to use for color output in the console,
defaults to ``mdsanima``.
defaults to mdsanima.
:type text: str, optional
:param color: The color number you want to use for color output in the
console, defaults to 255.
:type color: int, optional
:param end: End of line print, defaults to ``None``.
:param end: End of line print, defaults to None.
:type end: str, optional
:return: Colored text output in the console.
:rtype: str
.. admonition:: USAGE PYTHON
:class: hint
:usage:
*Assigning a function to a variable* `mds` then *function calling*
Assigning a function to a variable `mds` then function calling
returning printing colored text on the same line:
.. code:: python
.. code:: python
mds = get_complex_color
mds(color=44)
mds("mdsa", 160, " ")
mds("mds", 88, " ")
mds(text="mds", color=99, end=" ")
mds("mds", 86)
mds(end="mdsanima-dev", color=85, text="mds")
mds = get_complex_color
mds(color=44)
mds("mdsa", 160, " ")
mds("mds", 88, " ")
mds(text="mds", color=99, end=" ")
mds("mds", 86)
mds(end="mdsanima-dev", color=85, text="mds")
"""
sx, xm, ex = set_complex_color()
print(sx + str(color - 1) + xm + text + ex, end=end)

return str


def show_complex_color(number: bool = False) -> str:
def show_complex_color(number: bool=False) -> str:
"""Function prints all available colors with a number or only text.
:param number: Show color number, defaults to ``False``.
:param number: Show color number, defaults to False.
:type number: bool, optional
:return: Show all colors in the console output.
:rtype: str
.. admonition:: USAGE PYTHON
:class: hint
*Function calling:*
:usage: Function calling:
.. code:: python
.. code:: python
show_complex_color(False)
show_complex_color(True)
show_complex_color(False)
show_complex_color(True)
"""
sx, xm, ex = set_complex_color()
col = [251, 246, 243, 197, 161]
Expand All @@ -156,7 +146,7 @@ def show_complex_color(number: bool = False) -> str:
cnc = sx + str(col[0] - 1) + xm + "]" + ex
cne = sx + str(col[0] - 1) + xm + "]\n" + ex

# Print info options.
# print info options
if number == False:
show = "mdsanima".ljust(9)
print(cna + csh + cmd + cne)
Expand All @@ -165,7 +155,7 @@ def show_complex_color(number: bool = False) -> str:
print(cna + csh + cnu + cne)
done = cnb + cdo + cnu + cnc

# Print all colors.
# print all colors
for i in range(255):
if number == True:
show = "--> " + str(i + 1).ljust(5)
Expand Down

0 comments on commit aaaa37a

Please sign in to comment.