Skip to content

Commit

Permalink
Documented the src package
Browse files Browse the repository at this point in the history
  • Loading branch information
Nakama3942 committed Jun 30, 2023
1 parent 465bf55 commit 050218a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 8 deletions.
2 changes: 2 additions & 0 deletions mighty_logger/src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""
A package with the implementation of various data (ANSI, colors, etc.).
.. versionadded:: 0.0.0
\n
Copyright © 2023 Kalynovsky Valentin. All rights reserved.
Expand Down
6 changes: 4 additions & 2 deletions mighty_logger/src/animations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
A module with realisation of animations.
\n
The source of IndefiniteAnimation:
https://github.com/kopensource/colored_logs/blob/develop/colored_logs/models/animation_type.py
\n
Expand All @@ -24,6 +22,8 @@
class IndefiniteAnimations:
"""
The class with sets indefinite animations.
.. versionadded:: 0.0.0
"""
Dots = IndefiniteAnimationType([
'. ',
Expand Down Expand Up @@ -438,6 +438,8 @@ class IndefiniteAnimations:
class DefiniteAnimations:
"""
The class with sets definite animations.
.. versionadded:: 0.0.0
"""
Dots = DefiniteAnimationType([
' ',
Expand Down
11 changes: 9 additions & 2 deletions mighty_logger/src/ansi_format.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
A module with implementation of ANSI escape codes.
\n
Copyright © 2023 Kalynovsky Valentin. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -155,9 +153,14 @@ def _RecursiveGetAnsiFormat(ansi_address: str, ansi: dict) -> str:
"""
Recursively extracts a string with an ANSI escape code from a heavily nested dictionary.
.. versionadded:: 0.0.0
:param ansi_address: Path to ANSI escape code value
:type ansi_address: str
:param ansi: External/nested dictionary
:type ansi: dict
:return: value - ANSI escape code
:rtype: str
"""
split_address = ansi_address.split("/")
# print(split_address)
Expand All @@ -182,7 +185,11 @@ def GetAnsiFormat(ansi_address: str) -> str:
print(f"{GetAnsiFormat('color/set/background/255;255;255')}Test string")\n
print(f"{GetAnsiFormat('reset/on')}Test string")\n
.. versionadded:: 0.0.0
:param ansi_address: Path to ANSI escape code value
:type ansi_address: str
:return: ANSI escape code
:rtype: str
"""
return _RecursiveGetAnsiFormat(ansi_address, AnsiFormat)
54 changes: 50 additions & 4 deletions mighty_logger/src/color_picker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
A module with implementation of colors and their formatter functions.
\n
Copyright © 2023 Kalynovsky Valentin. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -179,8 +177,13 @@ def DecColor(color_name: str) -> list[int, int, int]:
"""
Returns a decimal color value.
.. versionadded:: 0.0.0
:param color_name: Color name
:type color_name: str
:return: Decimal color value
:rtype: list[int, int, int]
:raises ColorException: This color is not in the dictionary
"""
if color_name in ColorPicker:
return ColorPicker[color_name]
Expand All @@ -191,10 +194,18 @@ def HexColor(color_name: str) -> str:
"""
Returns a hexadecimal color value.
.. versionadded:: 0.0.0
:param color_name: Color name
:type color_name: str
:return: Hexadecimal color value
:rtype: str
:raises ColorException: This color is not in the dictionary
"""
return '{:02x}{:02x}{:02x}'.format(*DecColor(color_name))
if color_name in ColorPicker:
return '{:02x}{:02x}{:02x}'.format(*ColorPicker[color_name])
else:
raise ColorException("This color is not in the dictionary")

def AnsiColor(color_name: str, color_ground: str) -> str:
"""
Expand All @@ -206,37 +217,59 @@ def AnsiColor(color_name: str, color_ground: str) -> str:
- bright background
- underline
.. versionadded:: 0.0.0
:param color_name: Color name
:type color_name: str
:param color_ground: Color level
:type color_ground: str
:return: ANSI color value
:rtype: str
:raises ColorException: This color is not in the dictionary
"""
return GetAnsiFormat("color/set/{}/{};{};{}".format(color_ground, *DecColor(color_name)))
if color_name in ColorPicker:
return GetAnsiFormat("color/set/{}/{};{};{}".format(color_ground, *ColorPicker[color_name]))
else:
raise ColorException("This color is not in the dictionary")

def Dec2Hex(dec_colors: list[int, int, int]) -> str:
"""
Converts a decimal color value to a hexadecimal.
.. versionadded:: 0.0.0
:param dec_colors: Decimal color value
:type dec_colors: list[int, int, int]
:return: Hexadecimal color value
:rtype: str
"""
return '{:02x}{:02x}{:02x}'.format(*dec_colors)

def Dec2Ansi(dec_colors: list[int, int, int], color_ground: str) -> str:
"""
Converts a decimal color value to an ANSI escape code.
.. versionadded:: 0.0.0
:param dec_colors: Decimal color value
:type dec_colors: list[int, int, int]
:param color_ground: Color level (read AnsiColor() function documentation)
:type color_ground: str
:return: ANSI escape code color value
:rtype: str
"""
return GetAnsiFormat("color/set/{}/{};{};{}".format(color_ground, *dec_colors))

def Hex2Dec(hex_color: str) -> list[int, int, int]:
"""
Converts a hexadecimal color value to a decimal.
.. versionadded:: 0.0.0
:param hex_color: Hexadecimal color value
:type hex_color: str
:return: Decimal color value
:rtype: list[int, int, int]
"""
return [
int(hex_color[:2], base=16),
Expand All @@ -248,9 +281,14 @@ def Hex2Ansi(hex_color: str, color_ground: str) -> str:
"""
Converts a hexadecimal color value to an ANSI escape code.
.. versionadded:: 0.0.0
:param hex_color: Hexadecimal color value
:type hex_color: str
:param color_ground: Color level (read AnsiColor() function documentation)
:type color_ground: str
:return: ANSI escape code color value
:rtype: str
"""
return GetAnsiFormat("color/set/{}/{};{};{}".format(
color_ground,
Expand All @@ -266,8 +304,12 @@ def Ansi2Dec(ansi_color: str) -> list[int, int, int]:
to, and when from ANSI escape code, you don’t need to, because in other formats the levels
are defined differently and are not included in the command along with the color.
.. versionadded:: 0.0.0
:param ansi_color: ANSI escape code color value
:type ansi_color: str
:return: Decimal color value
:rtype: list[int, int, int]
"""
return [
int(ansi_color.split(';')[2]),
Expand All @@ -282,8 +324,12 @@ def Ansi2Hex(ansi_color: str) -> str:
to, and when from ANSI escape code, you don’t need to, because in other formats the levels
are defined differently and are not included in the command along with the color.
.. versionadded:: 0.0.0
:param ansi_color: ANSI escape code color value
:type ansi_color: str
:return: Hexadecimal color value
:rtype: str
"""
return '{:02x}{:02x}{:02x}'.format(
int(ansi_color.split(';')[2]),
Expand Down

0 comments on commit 050218a

Please sign in to comment.