stylecolor


Namestylecolor JSON
Version 1.0.4 PyPI version JSON
download
home_pageNone
SummaryThe simplest package to apply style and color in terminal
upload_time2024-11-20 12:17:25
maintainerNone
docs_urlNone
authorNone
requires_python>=3.2
licenseNone
keywords style color ansi shell terminal text colorama termcolor
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Stylecolor - 1.0.0

## Stylecolor
`stylecolor` is the simplest package for coloring and/or styling text in the terminal.  
`stylecolor` requires no other modules and is very lightweight and efficient.  

## Installation
No prerequisites are needed, only stylecolor.
```bash
pip install stylecolor
```

## Description
`stylecolor` uses [ANSI escape codes](https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797) to work. It is therefore compatible with all other libraries that use ANSI codes.

Some terminals do not support ANSI escape codes, so you can disable styling with `deactivate()`. In this case, you will still be able to use the functions, but the various styles will no longer be applied.  
Use `reactivate()` to reactivate the styling.

I recommend importing `stylecolor` as `sc` or `st`.\
Additionally, if you are debugging, I suggest importing the `rprint()` function like this: `from stylecolor import rprint()`

More, source code is available on [Stylecolor's](https://github.com/CloClo0/stylecolor) GitHub page


## Coloring
8 colors are available natively: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, and `white`.  
For each color, there are functions (e.g. `stylecolor.red()`), as well as constants (e.g. `stylecolor.RED`).  
For other colors, use [`stylecolor.rgb()`](#custom-colors) or [`stylecolor.hexa()`](#custom-colors).

### Simple Colors

```python
import stylecolor as sc

print(sc.red('red text'))
print(sc.green_text('green text'))
print(sc.blue('blue text'))
# ...
# AND/OR
print(sc.RED + 'constant red text' + sc.RESET)
print(sc.GREEN + 'constant green text' + sc.RESET)
print(sc.BLUE + 'constant blue text' + sc.RESET)
# ...
```
**output**\
<img src="https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/simple_colors.png" width="180"/>

### Light Colors
You can add the prefix `l` in front of the color to make it a `light` version.

````python
import stylecolor as sc
print(sc.lred('light red'))
print(sc.lgreen('light green'))
print(sc.lblue('light blue'))
# ...
# AND/OR
print(sc.LRED + 'constant red text' + sc.RESET)
print(sc.LGREEN + 'constant green text' + sc.RESET)
print(sc.LBLUE + 'constant blue text' + sc.RESET)
# ...
````
**output**\
<img src="https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/light_colors.png" width=180/>

### Background Colors
You can add the prefix `b` in front of each color to set it as a background color.

```python
import stylecolor as sc
print(sc.bred('red background'))
print(sc.bgreen('green background'))
print(sc.bblue('blue background'))
# ...
# AND/OR
print(sc.BRED + 'constant red background' + sc.RESET)
print(sc.BGREEN + 'constant green background' + sc.RESET)
print(sc.BBLUE + 'constant blue background' + sc.RESET)
# ...
```

**output**\
<img src='https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/background_colors.png' width=250>

>**NOTE**\
> You can also add `b` in front of the `light` colors.
> 
> ```python
> import stylecolor as sc
> print(sc.blred('light red background'))
> print(sc.blgreen('light green background'))
> print(sc.blblue('light blue background'))
> # ...
> #AND/OR"
> print(sc.BLRED + 'constant light red background' + sc.RESET)
> print(sc.BLGREEN + 'constant light green background' + sc.RESET)
> print(sc.BLBLUE + 'constant light blue background' + sc.RESET)
> # ...
> ```
> 
> **output**\
> <img src="https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/light_background_colors.png" width='250' />

### Custom Colors
The `rgb()` and `hexa()` functions allow you to apply custom colors.

```python
import stylecolor as sc
print(sc.rgb('personalised rgb color', '(background)', r=250, g=150, b=0))
print(sc.rgb('personalised tuple rgb color', '(background)', rgb=(250, 150, 0)))
print(sc.hexa('personalised hexadecimal color', '(background)', hexa='#fA9600'))
print(sc.hexa('personalised background hexadecimal color', "without '#'", hexa='Fa9600'))
``` 

**output**\
<img src='https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/custom_colors.png' width=450>

### Custom Background Colors
The `brgb()` and `bhexa()` functions allow you to apply custom background colors.

````python
import stylecolor as sc
print(sc.brgb('personalised rgb color', '(background)', r=250, g=150, b=0))
print(sc.brgb('personalised tuple rgb color', '(background)', rgb=(250, 150, 0)))
print(sc.bhexa('personalised hexadecimal color', '(background)', hexa='#fA9600'))
print(sc.bhexa('personalised background hexadecimal color', "without '#'", hexa='Fa9600'))
````

**output**\
<img src='https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/custom_background_color.png' width=450>

### Reset Colors
The functions `stylecolor.rcolor()` or `stylecolor.RCOLOR` and `stylecolor.rbackground()` or `stylecolor.RBACKGROUND` respectively remove the text color and the background color.

````python
import stylecolor as sc
# color
green_text = sc.green('green text')
print(green_text)
print(sc.rcolor(green_text))
# background color
bgreen_text = sc.bgreen('background green text')
print(bgreen_text)
print(sc.rbackground(bgreen_text))
````
**output**\
<img src="https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/reset_colors.png" width=180>

## Built-in Styles

### Apply Styles
In addition to colors, many styles are available: `bold`, `dim`, `italic`, `underline`, `blinking`, `reverse`, `hidden`, and `strikethrough`.  
Just like with colors, styles are accessible via functions (e.g. `stylecolor.bold()`) or constants (e.g. `stylecolor.BOLD`).

```python
import stylecolor as sc
print(sc.bold('bold text'))
print(sc.italic('italic text'))
print(sc.underline('underline text'))
# ...
# AND/OR
print(sc.BOLD, 'constant bold text', sc.RESET, sep='')
print(sc.ITALIC, 'constant italic text', sc.RESET, sep='')
print(sc.UNDERLINE, 'constant underline text', sc.RESET, sep='')
# ...
``` 

**output**\
<img src="https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/apply_styles.png" width=200>

### Reset Styles
You can add the prefix `r` in front of each style to cancel it (including with constants).

````python
import stylecolor as sc
bold = sc.bold('bold text')
print(bold)
print(sc.rbold(bold))

underline = sc.underline('underline text')
print(underline)
print(sc.runderline(underline))
# ...
````

**output**\
<img src="https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/reset_styles.png" width=150>

## Other Styles
It is possible, using the functions `stylecolor.style()` and `stylecolor.styles()`, to apply one or more styles to text.  
You can use textual styles like `red`, `bred`, `underline`, or directly use ANSI codes like `31`, `41`, `4`, for example.

````python
import stylecolor as sc
def func():
    pass
print(sc.style('text1', func, 'other text', style='blue'))
print(sc.styles('unique object', 'white', 'bblack', 'underline'))
````

**output**\
<img src="https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/other_styles.png" width=500>

## Composability

Most functions and constants are composable with each other.

```python
import stylecolor as sc
print(sc.blue(sc.underline('blue underline text'), 'blue text only'), 'normal text')
print(sc.styles('blue underline text', 'blue', 'underline', 'italic'))
# fonctions with constants
print(sc.green(sc.UNDERLINE, 'combined green underline text', sc.RUNDERLINE, ' green text only', sep=''),
      'normal text')
````

**output** \
<img src='https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/composability.png' width=500>

> **NOTE**\
> Foreground colors are not composable with each other, same for background.
>
>````python
>import stylecolor as sc
>print(sc.blue(sc.green('colored text in blue and green which appears blue')))
>print(sc.bblue(sc.bgreen('background colored text in blue and green which appears blue')))
>```` 
>
>**output**
><img src="https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/non_composability.png" width=500>
## Debug Functions

The functions `raw()` and `rprint()` allow you to get the raw version of a styled text.

````python
import stylecolor as sc
colored = sc.blue("raw blue text")
raw = sc.raw(colored) # return raw string
print(raw)
sc.rprint(colored)  # directly print raw result
````
**output**\
<img src="https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/debug_functions.png" width=250>

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "stylecolor",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.2",
    "maintainer_email": null,
    "keywords": "style, color, ANSI, shell, terminal, text, colorama, termcolor",
    "author": null,
    "author_email": "Clovis P <clovisp.pypi@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/b1/b8/39335d93890efd2dc0cdbfbfbd023a9f2dad7abde382559811b28fddbff5/stylecolor-1.0.4.tar.gz",
    "platform": null,
    "description": "# Stylecolor - 1.0.0\r\n\r\n## Stylecolor\r\n`stylecolor` is the simplest package for coloring and/or styling text in the terminal.  \r\n`stylecolor` requires no other modules and is very lightweight and efficient.  \r\n\r\n## Installation\r\nNo prerequisites are needed, only stylecolor.\r\n```bash\r\npip install stylecolor\r\n```\r\n\r\n## Description\r\n`stylecolor` uses [ANSI escape codes](https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797) to work. It is therefore compatible with all other libraries that use ANSI codes.\r\n\r\nSome terminals do not support ANSI escape codes, so you can disable styling with `deactivate()`. In this case, you will still be able to use the functions, but the various styles will no longer be applied.  \r\nUse `reactivate()` to reactivate the styling.\r\n\r\nI recommend importing `stylecolor` as `sc` or `st`.\\\r\nAdditionally, if you are debugging, I suggest importing the `rprint()` function like this: `from stylecolor import rprint()`\r\n\r\nMore, source code is available on [Stylecolor's](https://github.com/CloClo0/stylecolor) GitHub page\r\n\r\n\r\n## Coloring\r\n8 colors are available natively: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, and `white`.  \r\nFor each color, there are functions (e.g. `stylecolor.red()`), as well as constants (e.g. `stylecolor.RED`).  \r\nFor other colors, use [`stylecolor.rgb()`](#custom-colors) or [`stylecolor.hexa()`](#custom-colors).\r\n\r\n### Simple Colors\r\n\r\n```python\r\nimport stylecolor as sc\r\n\r\nprint(sc.red('red text'))\r\nprint(sc.green_text('green text'))\r\nprint(sc.blue('blue text'))\r\n# ...\r\n# AND/OR\r\nprint(sc.RED + 'constant red text' + sc.RESET)\r\nprint(sc.GREEN + 'constant green text' + sc.RESET)\r\nprint(sc.BLUE + 'constant blue text' + sc.RESET)\r\n# ...\r\n```\r\n**output**\\\r\n<img src=\"https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/simple_colors.png\" width=\"180\"/>\r\n\r\n### Light Colors\r\nYou can add the prefix `l` in front of the color to make it a `light` version.\r\n\r\n````python\r\nimport stylecolor as sc\r\nprint(sc.lred('light red'))\r\nprint(sc.lgreen('light green'))\r\nprint(sc.lblue('light blue'))\r\n# ...\r\n# AND/OR\r\nprint(sc.LRED + 'constant red text' + sc.RESET)\r\nprint(sc.LGREEN + 'constant green text' + sc.RESET)\r\nprint(sc.LBLUE + 'constant blue text' + sc.RESET)\r\n# ...\r\n````\r\n**output**\\\r\n<img src=\"https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/light_colors.png\" width=180/>\r\n\r\n### Background Colors\r\nYou can add the prefix `b` in front of each color to set it as a background color.\r\n\r\n```python\r\nimport stylecolor as sc\r\nprint(sc.bred('red background'))\r\nprint(sc.bgreen('green background'))\r\nprint(sc.bblue('blue background'))\r\n# ...\r\n# AND/OR\r\nprint(sc.BRED + 'constant red background' + sc.RESET)\r\nprint(sc.BGREEN + 'constant green background' + sc.RESET)\r\nprint(sc.BBLUE + 'constant blue background' + sc.RESET)\r\n# ...\r\n```\r\n\r\n**output**\\\r\n<img src='https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/background_colors.png' width=250>\r\n\r\n>**NOTE**\\\r\n> You can also add `b` in front of the `light` colors.\r\n> \r\n> ```python\r\n> import stylecolor as sc\r\n> print(sc.blred('light red background'))\r\n> print(sc.blgreen('light green background'))\r\n> print(sc.blblue('light blue background'))\r\n> # ...\r\n> #AND/OR\"\r\n> print(sc.BLRED + 'constant light red background' + sc.RESET)\r\n> print(sc.BLGREEN + 'constant light green background' + sc.RESET)\r\n> print(sc.BLBLUE + 'constant light blue background' + sc.RESET)\r\n> # ...\r\n> ```\r\n> \r\n> **output**\\\r\n> <img src=\"https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/light_background_colors.png\" width='250' />\r\n\r\n### Custom Colors\r\nThe `rgb()` and `hexa()` functions allow you to apply custom colors.\r\n\r\n```python\r\nimport stylecolor as sc\r\nprint(sc.rgb('personalised rgb color', '(background)', r=250, g=150, b=0))\r\nprint(sc.rgb('personalised tuple rgb color', '(background)', rgb=(250, 150, 0)))\r\nprint(sc.hexa('personalised hexadecimal color', '(background)', hexa='#fA9600'))\r\nprint(sc.hexa('personalised background hexadecimal color', \"without '#'\", hexa='Fa9600'))\r\n``` \r\n\r\n**output**\\\r\n<img src='https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/custom_colors.png' width=450>\r\n\r\n### Custom Background Colors\r\nThe `brgb()` and `bhexa()` functions allow you to apply custom background colors.\r\n\r\n````python\r\nimport stylecolor as sc\r\nprint(sc.brgb('personalised rgb color', '(background)', r=250, g=150, b=0))\r\nprint(sc.brgb('personalised tuple rgb color', '(background)', rgb=(250, 150, 0)))\r\nprint(sc.bhexa('personalised hexadecimal color', '(background)', hexa='#fA9600'))\r\nprint(sc.bhexa('personalised background hexadecimal color', \"without '#'\", hexa='Fa9600'))\r\n````\r\n\r\n**output**\\\r\n<img src='https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/custom_background_color.png' width=450>\r\n\r\n### Reset Colors\r\nThe functions `stylecolor.rcolor()` or `stylecolor.RCOLOR` and `stylecolor.rbackground()` or `stylecolor.RBACKGROUND` respectively remove the text color and the background color.\r\n\r\n````python\r\nimport stylecolor as sc\r\n# color\r\ngreen_text = sc.green('green text')\r\nprint(green_text)\r\nprint(sc.rcolor(green_text))\r\n# background color\r\nbgreen_text = sc.bgreen('background green text')\r\nprint(bgreen_text)\r\nprint(sc.rbackground(bgreen_text))\r\n````\r\n**output**\\\r\n<img src=\"https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/reset_colors.png\" width=180>\r\n\r\n## Built-in Styles\r\n\r\n### Apply Styles\r\nIn addition to colors, many styles are available: `bold`, `dim`, `italic`, `underline`, `blinking`, `reverse`, `hidden`, and `strikethrough`.  \r\nJust like with colors, styles are accessible via functions (e.g. `stylecolor.bold()`) or constants (e.g. `stylecolor.BOLD`).\r\n\r\n```python\r\nimport stylecolor as sc\r\nprint(sc.bold('bold text'))\r\nprint(sc.italic('italic text'))\r\nprint(sc.underline('underline text'))\r\n# ...\r\n# AND/OR\r\nprint(sc.BOLD, 'constant bold text', sc.RESET, sep='')\r\nprint(sc.ITALIC, 'constant italic text', sc.RESET, sep='')\r\nprint(sc.UNDERLINE, 'constant underline text', sc.RESET, sep='')\r\n# ...\r\n``` \r\n\r\n**output**\\\r\n<img src=\"https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/apply_styles.png\" width=200>\r\n\r\n### Reset Styles\r\nYou can add the prefix `r` in front of each style to cancel it (including with constants).\r\n\r\n````python\r\nimport stylecolor as sc\r\nbold = sc.bold('bold text')\r\nprint(bold)\r\nprint(sc.rbold(bold))\r\n\r\nunderline = sc.underline('underline text')\r\nprint(underline)\r\nprint(sc.runderline(underline))\r\n# ...\r\n````\r\n\r\n**output**\\\r\n<img src=\"https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/reset_styles.png\" width=150>\r\n\r\n## Other Styles\r\nIt is possible, using the functions `stylecolor.style()` and `stylecolor.styles()`, to apply one or more styles to text.  \r\nYou can use textual styles like `red`, `bred`, `underline`, or directly use ANSI codes like `31`, `41`, `4`, for example.\r\n\r\n````python\r\nimport stylecolor as sc\r\ndef func():\r\n    pass\r\nprint(sc.style('text1', func, 'other text', style='blue'))\r\nprint(sc.styles('unique object', 'white', 'bblack', 'underline'))\r\n````\r\n\r\n**output**\\\r\n<img src=\"https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/other_styles.png\" width=500>\r\n\r\n## Composability\r\n\r\nMost functions and constants are composable with each other.\r\n\r\n```python\r\nimport stylecolor as sc\r\nprint(sc.blue(sc.underline('blue underline text'), 'blue text only'), 'normal text')\r\nprint(sc.styles('blue underline text', 'blue', 'underline', 'italic'))\r\n# fonctions with constants\r\nprint(sc.green(sc.UNDERLINE, 'combined green underline text', sc.RUNDERLINE, ' green text only', sep=''),\r\n      'normal text')\r\n````\r\n\r\n**output** \\\r\n<img src='https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/composability.png' width=500>\r\n\r\n> **NOTE**\\\r\n> Foreground colors are not composable with each other, same for background.\r\n>\r\n>````python\r\n>import stylecolor as sc\r\n>print(sc.blue(sc.green('colored text in blue and green which appears blue')))\r\n>print(sc.bblue(sc.bgreen('background colored text in blue and green which appears blue')))\r\n>```` \r\n>\r\n>**output**\r\n><img src=\"https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/non_composability.png\" width=500>\r\n## Debug Functions\r\n\r\nThe functions `raw()` and `rprint()` allow you to get the raw version of a styled text.\r\n\r\n````python\r\nimport stylecolor as sc\r\ncolored = sc.blue(\"raw blue text\")\r\nraw = sc.raw(colored) # return raw string\r\nprint(raw)\r\nsc.rprint(colored)  # directly print raw result\r\n````\r\n**output**\\\r\n<img src=\"https://raw.githubusercontent.com/CloClo0/stylecolor/main/images/debug_functions.png\" width=250>\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "The simplest package to apply style and color in terminal",
    "version": "1.0.4",
    "project_urls": {
        "Homepage": "https://github.com/CloClo0/stylecolor"
    },
    "split_keywords": [
        "style",
        " color",
        " ansi",
        " shell",
        " terminal",
        " text",
        " colorama",
        " termcolor"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9cb8b832852cfba0aa3cc2e1ba36b857f2555853371973491ba8ab969d31dc15",
                "md5": "584330a3f5bef6f378c2ba8b18f62055",
                "sha256": "96b733415cbf61458d86bbf5e3512ee939d4d2cd054a35d53c4d4de29d88ee55"
            },
            "downloads": -1,
            "filename": "stylecolor-1.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "584330a3f5bef6f378c2ba8b18f62055",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.2",
            "size": 9654,
            "upload_time": "2024-11-20T12:17:24",
            "upload_time_iso_8601": "2024-11-20T12:17:24.681940Z",
            "url": "https://files.pythonhosted.org/packages/9c/b8/b832852cfba0aa3cc2e1ba36b857f2555853371973491ba8ab969d31dc15/stylecolor-1.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b1b839335d93890efd2dc0cdbfbfbd023a9f2dad7abde382559811b28fddbff5",
                "md5": "7d0ed9ecdf936ab8d7df6d63f3ba9a7e",
                "sha256": "3e57d19032c7b3e189911266b6e636a518a49cfad1ead5e056ce461b2747aee4"
            },
            "downloads": -1,
            "filename": "stylecolor-1.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "7d0ed9ecdf936ab8d7df6d63f3ba9a7e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.2",
            "size": 10919,
            "upload_time": "2024-11-20T12:17:25",
            "upload_time_iso_8601": "2024-11-20T12:17:25.740561Z",
            "url": "https://files.pythonhosted.org/packages/b1/b8/39335d93890efd2dc0cdbfbfbd023a9f2dad7abde382559811b28fddbff5/stylecolor-1.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-20 12:17:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "CloClo0",
    "github_project": "stylecolor",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "stylecolor"
}
        
Elapsed time: 0.41340s