Skip to content

Commit

Permalink
Merge pull request #4 from JordanWelsman/develop
Browse files Browse the repository at this point in the history
WIP: v0.2.0: The Color Update
  • Loading branch information
JordanWelsman authored Jan 12, 2023
2 parents 06d9d61 + dd05ef8 commit 18cfcad
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 7 deletions.
10 changes: 10 additions & 0 deletions jutl/formatting/__init__.py
Original file line number Diff line number Diff line change
@@ -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__
62 changes: 62 additions & 0 deletions jutl/formatting/color.py
Original file line number Diff line number Diff line change
@@ -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")
42 changes: 42 additions & 0 deletions jutl/formatting/text.py
Original file line number Diff line number Diff line change
@@ -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'
}

24 changes: 24 additions & 0 deletions jutl/formatting/utils.py
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 8 additions & 3 deletions jutl/utilities/__init__.py
Original file line number Diff line number Diff line change
@@ -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
# 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__
5 changes: 4 additions & 1 deletion jutl/utilities/hello_world.py → jutl/utilities/utils.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +23,7 @@
'pipelining/*',
'sorters/*',
'timers/*',
'utilities'
'utilities/*'
]

# Run setup function
Expand All @@ -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',
Expand Down

0 comments on commit 18cfcad

Please sign in to comment.