diff --git a/jutl/formatting/__init__.py b/jutl/formatting/__init__.py index e69de29..34ec760 100644 --- a/jutl/formatting/__init__.py +++ b/jutl/formatting/__init__.py @@ -0,0 +1,10 @@ +# Import color.py, text.py, and utils.py so +# module classes and functions are usable at +# 'from jutl import formatting' level. +from .color import * +from .text import * +from .utils import * + +# Only show functions specified in +# submodule files to the outside world. +__all__ = color.__all__, text.__all__, utils.__all__ \ No newline at end of file diff --git a/jutl/formatting/color.py b/jutl/formatting/color.py new file mode 100644 index 0000000..491da7b --- /dev/null +++ b/jutl/formatting/color.py @@ -0,0 +1,62 @@ +# External class visibility +__all__ = ['Text', 'Background'] + + +class Text: + # Text color dictionary + colors = { + 'DEFAULT': '\033[39m', + + 'BLACK': '\033[30m', + 'RED': '\033[31m', + 'GREEN': '\033[32m', + 'YELLOW': '\033[33m', + 'BLUE': '\033[34m', + 'MAGENTA': '\033[35m', + 'CYAN': '\033[36m', + 'LIGHTGRAY': '\033[37m', + 'DARKGRAY': '\033[90m', + 'LIGHTRED': '\033[91m', + 'LIGHTGREEN': '\033[92m', + 'LIGHTYELLOW': '\033[93m', + 'LIGHTBLUE': '\033[94m', + 'LIGHTMAGENTA': '\033[95m', + 'LIGHTCYAN': '\033[96m', + 'WHITE': '\033[97m' + } + + def test() -> None: + print(f"\nTesting {__name__}.Text...\n") + print(f"{Text.colors['DEFAULT']}█████{Text.colors['BLACK']}█████{Text.colors['DARKGRAY']}█████{Text.colors['LIGHTGRAY']}█████{Text.colors['WHITE']}█████{Text.colors['DEFAULT']}") + print(f"{Text.colors['RED']}█████{Text.colors['GREEN']}█████{Text.colors['YELLOW']}█████{Text.colors['BLUE']}█████{Text.colors['MAGENTA']}█████{Text.colors['CYAN']}█████{Text.colors['DEFAULT']}") + print(f"{Text.colors['LIGHTRED']}█████{Text.colors['LIGHTGREEN']}█████{Text.colors['LIGHTYELLOW']}█████{Text.colors['LIGHTBLUE']}█████{Text.colors['LIGHTMAGENTA']}█████{Text.colors['LIGHTCYAN']}█████{Text.colors['DEFAULT']}\n") + + +class Background: + # Background color dictionary + colors = { + 'DEFAULT': '\033[49m', + + 'BLACK': '\033[40m', + 'RED': '\033[41m', + 'GREEN': '\033[42m', + 'YELLOW': '\033[43m', + 'BLUE': '\033[44m', + 'MAGENTA': '\033[45m', + 'CYAN': '\033[46m', + 'LIGHTGRAY': '\033[47m', + 'DARKGRAY': '\033[100m', + 'LIGHTRED': '\033[101m', + 'LIGHTGREEN': '\033[102m', + 'LIGHTYELLOW': '\033[103m', + 'LIGHTBLUE': '\033[104m', + 'LIGHTMAGENTA': '\033[105m', + 'LIGHTCYAN': '\033[106m', + 'WHITE': '\033[107m' + } + + def test() -> None: + print(f"\nTesting {__name__}.Background...\n") + print(f"{Background.colors['DEFAULT']}|||||{Background.colors['BLACK']}|||||{Background.colors['DARKGRAY']}|||||{Background.colors['LIGHTGRAY']}|||||{Background.colors['WHITE']}|||||{Background.colors['DEFAULT']}") + print(f"{Background.colors['RED']}|||||{Background.colors['GREEN']}|||||{Background.colors['YELLOW']}|||||{Background.colors['BLUE']}|||||{Background.colors['MAGENTA']}|||||{Background.colors['CYAN']}|||||{Background.colors['DEFAULT']}") + print(f"{Background.colors['LIGHTRED']}|||||{Background.colors['LIGHTGREEN']}|||||{Background.colors['LIGHTYELLOW']}|||||{Background.colors['LIGHTBLUE']}|||||{Background.colors['LIGHTMAGENTA']}|||||{Background.colors['LIGHTCYAN']}|||||{Background.colors['DEFAULT']}\n") diff --git a/jutl/formatting/text.py b/jutl/formatting/text.py new file mode 100644 index 0000000..99847c2 --- /dev/null +++ b/jutl/formatting/text.py @@ -0,0 +1,42 @@ +# External class visibility +__all__ = ['Typography', 'Reset'] + + +class Typography: + # Text typography dictionary + types = { + 'DEFAULT': '\033[0m', + + 'BOLD': '\033[1m', + 'DIM': '\033[2m', + 'ITALIC': '\033[3m', + 'UNDERLINED': '\033[4m', + 'BLINKING1': '\033[5m', + 'BLINKING2': '\033[6m', + 'INVERTED': '\033[7m', + 'HIDDEN': '\033[8m', + 'STRIKETHROUGH': '\033[9m' + } + + def test() -> None: + print(f"\nTesting {__name__}.Typogrddaphy...\n") + print(f"{Typography.types['DEFAULT']}Default{Reset.types['ALL']}, {Typography.types['BOLD']}Bold{Reset.types['ALL']}, {Typography.types['DIM']}Dim{Reset.types['ALL']}, {Typography.types['ITALIC']}Italic{Reset.types['ALL']}, {Typography.types['UNDERLINED']}Underlined{Reset.types['ALL']},") + print(f"{Typography.types['BLINKING1']}Blinking{Reset.types['ALL']}, {Typography.types['BLINKING2']}Blinking{Reset.types['ALL']}, {Typography.types['INVERTED']}Inverted{Reset.types['ALL']}, {Typography.types['HIDDEN']}Hidden{Reset.types['ALL']}, {Typography.types['STRIKETHROUGH']}Strikethrough{Reset.types['ALL']}\n") + + +class Reset: + # Reset typography dictionary + types = { + 'ALL': '\033[0m', + + 'BOLD': '\033[21m', + 'DIM': '\033[22m', + 'ITALIC': '\033[23m', + 'UNDERLINED': '\033[24m', + 'BLINKING1': '\033[25m', + 'BLINKING2': '\033[26m', + 'INVERTED': '\033[27m', + 'HIDDEN': '\033[28m', + 'STRIKETHROUGH': '\033[29m' + } + diff --git a/jutl/formatting/utils.py b/jutl/formatting/utils.py new file mode 100644 index 0000000..e33128f --- /dev/null +++ b/jutl/formatting/utils.py @@ -0,0 +1,24 @@ +from .color import Text, Background +from .text import Typography, Reset + +__all__ = ['apply', 'test'] + +def apply(text: str, text_color: str = None, background_color: str = None, typography: str = None) -> str: + formatting = "" + + if text_color is not None: + formatting += Text.colors[text_color.upper()] if text_color.upper() in Text.colors else '' + if background_color is not None: + formatting += Background.colors[background_color.upper()] if background_color.upper() in Background.colors else '' + if typography is not None: + formatting += Typography.types[typography.upper()] if typography.upper() in Typography.types else '' + return formatting + text + Reset.types['ALL'] + +def test(): + """ + Test function which executes test + functions from formatting classes. + """ + Text.test() + Background.test() + Typography.test() diff --git a/jutl/utilities/__init__.py b/jutl/utilities/__init__.py index 5f368ea..fb533d0 100644 --- a/jutl/utilities/__init__.py +++ b/jutl/utilities/__init__.py @@ -1,3 +1,8 @@ -# Import hello_world.py from /utilities/ so hello_world() is -# usable at 'from jutils import utilities' level. -from .hello_world import hello_world \ No newline at end of file +# Import utils.py so module +# functions are usable at +# 'from jutl import utilities' level. +from .utils import * + +# Only show functions specified in +# submodule files to the outside world. +__all__ = utils.__all__ \ No newline at end of file diff --git a/jutl/utilities/hello_world.py b/jutl/utilities/utils.py similarity index 84% rename from jutl/utilities/hello_world.py rename to jutl/utilities/utils.py index 89e0226..5f12fe3 100644 --- a/jutl/utilities/hello_world.py +++ b/jutl/utilities/utils.py @@ -1,6 +1,9 @@ +# External function visibility +__all__ = ['hello_world'] + def hello_world(name: str = None) -> str: """ - Greet the user. + Greets the user. Returns "Hello, 'user!'" where 'user' is 'name' if passed, or "Hello, World!" if 'name' is not passed. diff --git a/setup.py b/setup.py index 3b28141..ce32cae 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ # Arguments git_name = "jutils" pypi_name = "jutl" -version = "0.0.1a" +version = "0.2.0" python_version = ">=3.10" # Long description from README.md @@ -23,7 +23,7 @@ 'pipelining/*', 'sorters/*', 'timers/*', - 'utilities' + 'utilities/*' ] # Run setup function @@ -42,7 +42,7 @@ python_requires=python_version, # jutils package information classifiers=[ - 'Development Status :: 2 - Pre-Alpha', + 'Development Status :: 3 - Alpha', 'Intended Audience :: Developers', 'Intended Audience :: Education', 'License :: OSI Approved :: MIT License',