Skip to content

Commit

Permalink
background methods rename. fix names on tests. package rename.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason committed Jun 28, 2022
1 parent 6a9c57d commit 0616add
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 92 deletions.
56 changes: 25 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# colorize
# colorful
__Color terminal text with ANSI Styles and Colors.__

## Install
Expand All @@ -11,7 +11,7 @@ python setup.py test
## Import

```
from colorize import Color
from colorful import Color
...
```

Expand All @@ -31,19 +31,13 @@ print(c) #output
print(Color("This is some text").green()) # Create and output in one line.
```

### Simple Example 3 (8-bit Color)

```
print(Color("This is some text").color8(32)) # Create and output 8-bit color in one line.
```

---

### Chain Example 1

```
c = Color("This is a chain example")
c.bold().green().bgmagenta() #green text, magenta background
c.bold().green().on\_magenta() #green text, magenta background
print(c) #output
```

Expand Down Expand Up @@ -87,14 +81,14 @@ print(combo)

### Bright FG Colors

- brblack()
- brred()
- brgreen()
- bryellow()
- brblue()
- brmagenta()
- brcyan()
- brwhite()
- bright\_black()
- bright\_red()
- bright\_green()
- bright\_yellow()
- bright\_blue()
- bright\_magenta()
- bright\_cyan()
- bright\_white()

### Styles

Expand All @@ -110,32 +104,32 @@ print(combo)

### BG Colors

- bgblack()
- bgred()
- bggreen()
- bgyellow()
- bgblue()
- bgmagenta()
- bgcyan()
- bgwhite()
- on\_black()
- on\_red()
- on\_green()
- on\_yellow()
- on\_blue()
- on\_magenta()
- on\_cyan()
- on\_white()

---

### 8-Bit Colors
### Extended Colors

#### (1-7 = Standard, 8-15 = Bright, 16-231 = 216 Palette, 232-255 = Grayscale)

- color8(_0-255_)
- bg8(_0-255_)
- extended(_0-255_)
- on\_extendted(_0-255_)

---


### 24-Bit Colors
### RGB Colors

#### (__NOT SUPPORTED IN SOME TERMINALS__)

- color24(_r_, _g_, _b_)
- bg24(_r_, _g_, _b_)
- rgb(_r_, _g_, _b_)
- on\_rgb(_r_, _g_, _b_)


51 changes: 25 additions & 26 deletions colorize/__init__.py → colorful/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
# bg = \33[ + 4 + COLOR NUMBER + m

__author__ = "Jason Rebuck"
__copyright__ = "2021"
__version__ = "0.19"
__copyright__ = "2021-2022"
__version__ = "0.20"

class Color:
"""Output Text With Color And Style"""
Expand All @@ -33,7 +33,7 @@ class Color:
"italic" : 3,
"underline" : 4,
"blink" : 5,
#"rapid" : 6, #rapid blink. not usually supported
"rapid" : 6, #rapid blink. not usually supported
"invert" : 7,
"hide" : 8, #hides output
"strike" : 9, #not usually supported
Expand Down Expand Up @@ -74,22 +74,22 @@ def _style(self, style=""):
#16-231 = 216 colors
#232-255 = grayscale

def color8(self, color=0):
"""Wrap with 8-bit color (0-255)"""
def extended(self, color=0):
"""Wrap with extended color (0-255)"""
return self._wrap("38;5;", color)

def bg8(self, color=0):
"""Wrap with 8-bit bg color (0-255)"""
def on_extended(self, color=0):
"""Wrap with extended bg color (0-255)"""
return self._wrap("48;5;", color)

# 24-bit colors
# R,G,B
# NOT SUPPORTED IN SOME TERMINALS
def color24(self, r=0, g=0, b=0):
def rgb(self, r=0, g=0, b=0):
"""Wrap with 24-bit color (r,g,b)"""
return self._wrap("38;2;", f"{r};{g};{b}")

def bg24(self, r=0, g=0, b=0):
def on_rgb(self, r=0, g=0, b=0):
"""Wrap with 24-bit bg color (r,g,b)"""
return self._wrap("48;2;", f"{r};{g};{b}")

Expand Down Expand Up @@ -127,68 +127,68 @@ def white(self):
return self._color("white")

# Shortcut Bright Colors
def brblack(self):
def bright_black(self):
"""Color Bright Black"""
return self._bright("black")

def brred(self):
def bright_red(self):
"""Color Bright Red"""
return self._bright("red")

def brgreen(self):
def bright_green(self):
"""Color Bright Green"""
return self._bright("green")

def bryellow(self):
def bright_yellow(self):
"""Color Bright Yellow"""
return self._bright("yellow")

def brblue(self):
def bright_blue(self):
"""Color Bright Blue"""
return self._bright("blue")

def brmagenta(self):
def bright_magenta(self):
"""Color Bright Magenta"""
return self._bright("magenta")

def brcyan(self):
def bright_cyan(self):
"""Color Bright Cyan"""
return self._bright("cyan")

def brwhite(self):
def bright_white(self):
"""Color Bright White"""
return self._bright("white")

# Shortcut Background
def bgblack(self):
def on_black(self):
"""Background Black"""
return self._bg("black")

def bgred(self):
def on_red(self):
"""Background Red"""
return self._bg("red")

def bggreen(self):
def on_green(self):
"""Background Green"""
return self._bg("green")

def bgyellow(self):
def on_yellow(self):
"""Background Yellow"""
return self._bg("yellow")

def bgblue(self):
def on_blue(self):
"""Background Blue"""
return self._bg("blue")

def bgmagenta(self):
def on_magenta(self):
"""Background Magenta"""
return self._bg("magenta")

def bgcyan(self):
def on_cyan(self):
"""Background Cyan"""
return self._bg("cyan")

def bgwhite(self):
def on_white(self):
"""Background White"""
return self._bg("white")

Expand Down Expand Up @@ -227,7 +227,6 @@ def hide(self):

def strike(self):
"""Style Strike"""
#NOT USUALLY SUPPORTED!
return self._style("strike")

# Output
Expand Down
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import os
from setuptools import setup
import colorize
import colorful

def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
name = "Colorizer",
version = colorize.__version__,
author = colorize.__author__,
description = (colorize.__doc__),
name = "Colorful",
version = colorful.__version__,
author = colorful.__author__,
description = (colorful.__doc__),
keywords = "Color, ANSI",
url = "https://github.com/jaschon/colorize",
packages=['colorize', 'tests'],
url = "https://github.com/jaschon/colorful",
packages=['colorful'],
long_description=read('README.md'),
test_suite="tests",
)
50 changes: 25 additions & 25 deletions tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import sys
import unittest
from colorize import Color
from colorful import Color

class TestColor(unittest.TestCase):
"""Test Base Color"""
Expand Down Expand Up @@ -32,29 +32,29 @@ class TestBright(TestColor):
"""Test Bright Color"""

tests = (
("brblack", "\33[90mthis is a test\33[0m"),
("brred", "\33[91mthis is a test\33[0m"),
("brgreen", "\33[92mthis is a test\33[0m"),
("bryellow", "\33[93mthis is a test\33[0m"),
("brblue", "\33[94mthis is a test\33[0m"),
("brmagenta", "\33[95mthis is a test\33[0m"),
("brcyan", "\33[96mthis is a test\33[0m"),
("brwhite", "\33[97mthis is a test\33[0m"),
("bright_black", "\33[90mthis is a test\33[0m"),
("bright_red", "\33[91mthis is a test\33[0m"),
("bright_green", "\33[92mthis is a test\33[0m"),
("bright_yellow", "\33[93mthis is a test\33[0m"),
("bright_blue", "\33[94mthis is a test\33[0m"),
("bright_magenta", "\33[95mthis is a test\33[0m"),
("bright_cyan", "\33[96mthis is a test\33[0m"),
("bright_white", "\33[97mthis is a test\33[0m"),
)


class TestBackground(TestColor):
"""Test Background Color"""

tests = (
("bgblack", "\33[40mthis is a test\33[0m"),
("bgred", "\33[41mthis is a test\33[0m"),
("bggreen", "\33[42mthis is a test\33[0m"),
("bgyellow", "\33[43mthis is a test\33[0m"),
("bgblue", "\33[44mthis is a test\33[0m"),
("bgmagenta", "\33[45mthis is a test\33[0m"),
("bgcyan", "\33[46mthis is a test\33[0m"),
("bgwhite", "\33[47mthis is a test\33[0m"),
("on_black", "\33[40mthis is a test\33[0m"),
("on_red", "\33[41mthis is a test\33[0m"),
("on_green", "\33[42mthis is a test\33[0m"),
("on_yellow", "\33[43mthis is a test\33[0m"),
("on_blue", "\33[44mthis is a test\33[0m"),
("on_magenta", "\33[45mthis is a test\33[0m"),
("on_cyan", "\33[46mthis is a test\33[0m"),
("on_white", "\33[47mthis is a test\33[0m"),
)

class TestStyle(TestColor):
Expand Down Expand Up @@ -110,14 +110,14 @@ class TestChainBackground(TestChainColor):
"""Test Chain Background with Bold"""

tests = (
("bgblack", "\33[40m\33[1mthis is a test\33[0m\33[0m"),
("bgred", "\33[41m\33[1mthis is a test\33[0m\33[0m"),
("bggreen", "\33[42m\33[1mthis is a test\33[0m\33[0m"),
("bgyellow", "\33[43m\33[1mthis is a test\33[0m\33[0m"),
("bgblue", "\33[44m\33[1mthis is a test\33[0m\33[0m"),
("bgmagenta", "\33[45m\33[1mthis is a test\33[0m\33[0m"),
("bgcyan", "\33[46m\33[1mthis is a test\33[0m\33[0m"),
("bgwhite", "\33[47m\33[1mthis is a test\33[0m\33[0m"),
("on_black", "\33[40m\33[1mthis is a test\33[0m\33[0m"),
("on_red", "\33[41m\33[1mthis is a test\33[0m\33[0m"),
("on_green", "\33[42m\33[1mthis is a test\33[0m\33[0m"),
("on_yellow", "\33[43m\33[1mthis is a test\33[0m\33[0m"),
("on_blue", "\33[44m\33[1mthis is a test\33[0m\33[0m"),
("on_magenta", "\33[45m\33[1mthis is a test\33[0m\33[0m"),
("on_cyan", "\33[46m\33[1mthis is a test\33[0m\33[0m"),
("on_white", "\33[47m\33[1mthis is a test\33[0m\33[0m"),
)

class TestAdd(unittest.TestCase):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Test Color Output"""

import unittest
from colorize import Color
from colorful import Color

class TestOutputColor(unittest.TestCase):
"""Test Output Base Color"""
Expand Down Expand Up @@ -74,7 +74,7 @@ class TestOutputBGWrapper(TestOutputColor):
title = "BG Wrapper"
check = Color.COLORS
method = ""
method_add = "bg"
method_add = "on_"


class TestOutputBright(TestOutputColor):
Expand All @@ -91,7 +91,7 @@ class TestOutputBrightWrapper(TestOutputColor):
title = "Bright Wrapper"
check = Color.COLORS
method = ""
method_add = "br"
method_add = "bright_"

class TestOutputAdd(TestOutputColor):
"""Test Output Class Adding"""
Expand Down

0 comments on commit 0616add

Please sign in to comment.