Skip to content

Commit

Permalink
docs(table): add docstring for sphinx documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsanima committed Aug 12, 2021
1 parent b5c26e0 commit bcb3028
Showing 1 changed file with 117 additions and 77 deletions.
194 changes: 117 additions & 77 deletions src/mdsanima_dev/utils/table.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""
# Table Module
Making a cool table.
Printing a colored table in the terminal console output.
"""

from mdsanima_dev import colors
Expand All @@ -16,25 +14,27 @@ def __init__(self):

def colors(self, color:int=255) -> int:
"""
Initial color table.
Initial color table. Only use for this class.
Args:
color (int, optional): Color of the table. Defaults to 255.
Returns:
int: Number of colors from `colors` module.
:param color: color of the table, defaults to 255
:type color: int, optional
:return: number of colors from ``colors`` module
:rtype: int
"""
self.tab_color = color

def connect(self, top: bool, length: int, bot: bool) -> str:
"""
Checking for connecting table.
Args:
top (bool): Top element of the table.
length (int): Length of the table.
bot (bool): Bottom element of the table.
Returns:
str: Element printing of the table in unicode value.
Checking for connectiong table.
:param top: top element of the table
:type top: bool
:param length: length of the table
:type length: int
:param bot: bottom element of the table
:type bot: bool
:return: element printing of the table in unicode value
:rtype: str
"""
header = ('\u250c' + ('\u2500' * length) + '\u2510')
conect = ('\u251c' + ('\u2500' * length) + '\u2524')
Expand All @@ -52,14 +52,31 @@ def headers(self,
"""
Headers of the template table.
Args:
header (str): Headers with connectiog or nor.
hcolor (int, optional): Color of text. Defaults to 255.
top (bool, optional): Check connecting top. Defaults to False.
bot (bool, optional): Check connection bootom. Defaults to False.
tcolor (int, optional): Table color. Defaults to 255.
Returns:
str: Headers element of tempalte table.
:param header: headers text
:type header: str
:param hcolor: color of text, defaults to 255
:type hcolor: int, optional
:param top: check connecting top, defaults to ``False``
:type top: bool, optional
:param bot: check connecting bootom, defaults to ``False``
:type bot: bool, optional
:param tcolor: table color, defaults to 255
:type tcolor: int, optional
:return: headers element of template table
:rtype: str
:usage:
assigning function calling to a variable
.. code:: python
from mdsanima_dev.utils.table import table
t = table()
t.headers('I Love Python mdsanima.com')
t.headers('I Love Python mdsanima.com', hcolor=50)
t.headers('I Love Python mdsanima.com', hcolor=197, tcolor=203)
t.headers('I Love Python mdsanima.com'.center(40),
hcolor=34, tcolor=220)
"""
self.header = header
self.color = hcolor
Expand All @@ -74,7 +91,7 @@ def headers(self,

# Table midle.
self.mds('\u2502', self.tab_color, '')
self.mds(' ' + self.header.ljust(head_len-2).upper(), self.color, ' ')
self.mds(' ' + self.header.ljust(head_len-2), self.color, ' ')
self.mds('\u2502', self.tab_color)

# Table bottom.
Expand All @@ -87,18 +104,38 @@ def content(self,
tcolor: int = 255
) -> str:
"""
Content of the tempalte table. This table constrain two text value.
Args:
content_key (str): First text value in the left.
content_val (str): Second text value in the right.
key_color (int, optional): Text color content key. Defaults to 255.
val_color (int, optional): Text color content val. Defaults to 255.
top (bool, optional): Check connecting top. Defaults to False.
bot (bool, optional): Check connecting bootom. Defaults to False.
tcolor (int, optional): Table color. Defaults to 255.
Returns:
str: Content elemento of template table.
Content of the template table. This table constrain two text value.
:param content_key: first text value in the left
:type content_key: str
:param content_val: second text value in the right
:type content_val: str
:param key_color: text color content key, defaults to 255
:type key_color: int, optional
:param val_color: text color content value, defaults to 255
:type val_color: int, optional
:param top: check connecting top, defaults to ``False``
:type top: bool, optional
:param bot: check connecting bootom, defaults to ``False``
:type bot: bool, optional
:param tcolor: table color, defaults to 255
:type tcolor: int, optional
:return: content element of template table
:rtype: str
:usage:
assigning function calling to a variable
.. code:: python
from mdsanima_dev.utils.table import table
t = table()
t.content('I Love Python', 'mdsanima.com')
t.content('I Love Python', 'mdsanima.com', tcolor=197)
t.content('I Love Python', 'mdsanima.com',
tcolor=227, key_color=86, val_color=76)
t.content('I Love Python'.rjust(20), 'mdsanima.com'.ljust(20),
tcolor=31, key_color=32, val_color=33)
"""
self.key = content_key
self.val = content_val
Expand Down Expand Up @@ -135,12 +172,12 @@ class table_elem:
"""
def __init__(self, color: int) -> str:
"""
Initial finction.
Initial function element of the table.
Args:
color (int): Number of colors from `colors` module.
Returns:
str: Color value.
:param color: number of color from ``colors`` module
:type color: int
:return: color value
:rtype: str
"""
self.mds = colors.get_complex_color
self.color = color
Expand All @@ -149,10 +186,10 @@ def top(self, length: int) -> str:
"""
Top element of the table.
Args:
length (int): Length of the table element.
Returns:
str: Unicode top element printing in one line.
:param length: length of the table element
:type length: int
:return: unicode top element printing in one line
:rtype: str
"""
self.header = ('\u250c' + ('\u2500' * length) + '\u2510')
self.mds(self.header, self.color)
Expand All @@ -161,10 +198,10 @@ def mid(self, length: int) -> str:
"""
Midle element of the table.
Args:
length (int): Length of the table element.
Returns:
str: Unicode midle element printing in one line.
:param length: length of the table element
:type length: int
:return: unicode midle element printing in one line
:rtype: str
"""
self.middle = ('\u251c' + ('\u2500' * length) + '\u2524')
self.mds(self.middle, self.color)
Expand All @@ -173,54 +210,57 @@ def bot(self, length: int) -> str:
"""
Bootom element of the table.
Args:
length (int): Length of the table element.
Returns:
str: Unicode bootom element printing in one line.
:param length: length of the table element
:type length: int
:return: unicode bootom element printing in one line
:rtype: str
"""
self.bottom = ('\u2514' + ('\u2500' * length) + '\u2518')
self.mds(self.bottom, self.color)

def hed(self,
length: int, text: str, text_color: int
) -> str:
def hed(self, length: int, text: str, text_color: int) -> str:
"""
Header element of the table one text value.
Args:
length (int): Length of the table element.
text (str): Text printing inside table.
text_color (int): Text color.
Returns:
str: Unicode header element printing in one line.
Header element of the table on text value.
:param length: length of the table element
:type length: int
:param text: text printing inside table
:type text: str
:param text_color: text color value
:type text_color: int
:return: unicode header element printing in one line
:rtype: str
"""
self.text = text.ljust(length-1)
self.mds('\u2502', self.color, '')
self.mds(' ' + self.text.upper(), text_color, '')
self.mds('\u2502', self.color)

def con(self,
length: int, key: str, val: str,
k_clr: int, v_clr: int
length: int, key: str, val: str, k_clr: int, v_clr: int
) -> str:
"""
Content element of the table two text value.
Args:
length (int): Length of the table element.
key (str): Text printing inside table in the left.
val (str): Text printing inside table in the right.
k_clr (int): Text color key.
v_clr (int): Text color val.
Returns:
str: Unicode content element printing in one line.
:param length: length of the table element
:type length: int
:param key: text printing inside table in the left
:type key: str
:param val: text printing inside table in the right
:type val: str
:param k_clr: text color key
:type k_clr: int
:param v_clr: text color value
:type v_clr: int
:return: unicode content element printing in one line
:rtype: str
"""
self.con_key = key
self.con_val = val
k_len = len(key)
v_len = len(val)
ajst = k_len + v_len + 5
self.mds('\u2502', self.color, '')
self.mds(' ' + self.con_key.upper(), k_clr, ' ->')
self.mds(' ' + self.con_val.upper(), v_clr, ' '.ljust(length-ajst))
self.mds(' ' + self.con_key, k_clr, ' ->')
self.mds(' ' + self.con_val, v_clr, ' '.ljust(length-ajst))
self.mds('\u2502', self.color)

0 comments on commit bcb3028

Please sign in to comment.