iro


Nameiro JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryEasy and powerful Colorizer for Python!
upload_time2024-09-25 05:33:41
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2021 nagataaaas Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords cli color colorize colorizer console library terminal tool
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            IRO
===

Easy and powerful Colorizer for Python!

Powered by [Yamato Nagata](https://twitter.com/514YJ)

[GitHub](https://github.com/nagataaaas/Iro)

The depth represents the block and style in the block affects elements within that block.

![output](https://github.com/nagataaaas/Iro/blob/main/assets/capture1.png?raw=true)

<details><summary>Code</summary>

```python
from iro import Iro, FGColor, BGColor, Style, ColorRGB, Color256

from colorsys import hls_to_rgb

success = Iro((FGColor.GREEN, "[  SUCCESS ]"))
success_rendered = success.str  # You can get rendered string by .str attribute
error = Iro((ColorRGB(255, 255, 255), BGColor.RED, Style.DOUBLY_UNDERLINE, "[   ERROR  ]"))
warning = Iro((FGColor.YELLOW, Color256(255, bg=True), "[  WARNING ]"))
deprecated = Iro((Color256(7), Color256(239, True), Style.STRIKE, "[DEPRECATED]"))

print(success_rendered, 'Something is done successfully.\n')
print(error, 'Something is wrong.\n')
print(warning, 'Something is not good.\n')
print(deprecated, 'This feature is deprecated.\n')

print(Iro([
    FGColor.RED, "Of course, You can nest styles.",
    [
        Style.ITALIC,
        "This is RED and ITALIC."
    ],
    [
        FGColor.BLUE,
        "This is BLUE, BG_BRIGHT_BLACK and UNDERLINED.",
        BGColor.BRIGHT_BLACK,  # Style will be collected before rendering non-style elements
        Style.UNDERLINE,
        [
            Style.RESET,
            "Back to normal.\nWith new line."
        ]
    ],
    "Finally back to only RED!"
],
    sep=Iro(Style.RESET, " ")))

for h in range(256):
    print(Iro([ColorRGB(*map(lambda x: x * 255, hls_to_rgb(h / 256, 0.7, 1)), bg=True), ' ']), end='')

print(Iro([
    "normal", Style.BOLD, "bold", Style.DIM, "bold-dim", Style.OFF_BOLD, "dim", Style.OFF_DIM, Style.BOLD, "bold",
    FGColor.RED, "red-bold", Style.RESET, "normal"
], collect_styles_first=False, sep=Iro(Style.RESET, " ")))
```

</details>

# Installation

```    
$ pip install iro
```

# Documentation

## `Iro(*values: Any, disable_rgb: bool = True, sep: str | Iro = "", collect_styles_first: bool = True)`

| Parameter              | Type           | Description                                                                                                                                                                                         |
|------------------------|----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `values`               | `Any`          | values that will be rendered. `Iro`, `IroElement`, `str`, `int`, `float`, `list`, `tuple`, `dict`, etc.                                                                                             |
| `disable_rgb`          | `bool`         | if `True`, `ColorRGB` will be converted to similar color of `Color256`. This is for supporting some consoles that does not support `ColorRGB`.                                                      |
| `sep`                  | `str` or `Iro` | separator between elements. If `str` is given, it will be rendered as it is. If `Iro` is given, it will be rendered like it's part of the `values`. This will be rendered between non-style values. |
| `collect_styles_first` | `bool`         | if `True`, all styles in the nest depth will be collected before rendering non-style elements. If `False`, styles will be rendered as they are found.                                               |

`Iro().text` or `Iro().str` to fetch result.

> [!NOTE]
> Each time you try to get `Iro().text`, `Iro().str` or `str(Iro())`, it will be rendered again.\
> So if you want to use it multiple times, storing the result in a variable is recommended.
>
> However, if you want to render the `Iro` instance inside the other `Iro` instance (as an item of `values` or `sep`),
> passing the `str` generated with `Iro().text` can cause a problem.
> ![output](https://github.com/nagataaaas/Iro/blob/main/assets/capture2.png?raw=true)
> <details><summary>Code</summary>
>
> ```python
> from iro import Iro, FGColor
> 
> blue_and = Iro(FGColor.BLUE, " and ")
> blue_and_str = blue_and.str
> print(Iro(FGColor.RED, "red", blue_and, "red"))
> print(Iro(FGColor.RED, "red", "red", sep=blue_and))
> print(Iro(FGColor.RED, "red", blue_and_str, "red"))
> print(Iro(FGColor.RED, "red", "red", sep=blue_and_str))
> ```
> </details>
>
> This is because of 2 reasons.\
> 1st, `Iro` instance can detect other `Iro` instance to be rendered as part of it, and render only style diff before
> and after the recursive rendering.\
> And 2nd, `Iro` instance will reset all styles at the end of rendering if it's the root `Iro` instance.\
> For these reasons, if you pass `str` generated with `Iro().text`, `Iro` can no longer understand the style applied to
> the current cursor position, and will cause a problem.

### `Iro().text -> str`

Get rendered string.

### `Iro().str -> str`

Get rendered string.

## `Style`

Enum of defined `Style`.

| Style              | Description                                                                                                                      |
|--------------------|----------------------------------------------------------------------------------------------------------------------------------|
| `RESET`            | Reset all styles. including color and background color.                                                                          |
| `NORMAL`           | Alias of `RESET`.                                                                                                                |
| `BOLD`             | Bold or increased intensity.                                                                                                     |
| `DIM`              | Faint, decreased intensity, or dim. in some terminals, this may be implemented as a light font weight and this overrides `BOLD`. |
| `ITALIC`           | Italic. Not widely supported. Sometimes treated as inverse.                                                                      |
| `UNDERLINE`        | Underline.                                                                                                                       |
| `SLOW_BLINK`       | Slow Blink.                                                                                                                      |
| `RAPID_BLINK`      | Rapid Blink. Not widely supported.                                                                                               |
| `INVERT`           | Invert foreground and background colors.                                                                                         |
| `HIDE`             | Hide text. Not widely supported.                                                                                                 |
| `STRIKE`           | Strikethrough.                                                                                                                   |
| `OVERLINE`         | Overline. Not widely supported.                                                                                                  |
| `GOTHIC`           | Gothic. Rarely supported.                                                                                                        |
| `DOUBLY_UNDERLINE` | Double underline. Rarely supported.                                                                                              |

and `OFF_*` styles to disable each style.

| Style                  | Description                             |
|------------------------|-----------------------------------------|
| `OFF_BOLD`             | Disable `BOLD`.                         |
| `OFF_DIM`              | Disable `DIM`.                          |
| `OFF_ITALIC`           | Disable `ITALIC`.                       |
| `OFF_UNDERLINE`        | Disable `UNDERLINE`.                    |
| `OFF_INVERT`           | Disable `INVERT`.                       |
| `OFF_HIDE`             | Disable `HIDE`.                         |
| `OFF_STRIKE`           | Disable `STRIKE`.                       |
| `OFF_OVERLINE`         | Disable `OVERLINE`.                     |
| `OFF_GOTHIC`           | Disable `GOTHIC`.                       |
| `OFF_DOUBLY_UNDERLINE` | Disable `DOUBLY_UNDERLINE`.             |
| `OFF_FONT`             | Reset font to default.                  |
| `OFF_INTENSITY`        | Disable `BOLD` and `DIM`.               |
| `OFF_BLINK`            | Disable `SLOW_BLINK` and `RAPID_BLINK`. |
| `OFF_FG_COLOR`         | Reset foreground color.                 |
| `OFF_BG_COLOR`         | Reset background color.                 |

## `FGColor`, `BGColor`

Enum of 3-bit and 4-bit color.

`FGColor` is for foreground color, and `BGColor` is for background color.
Both `FGColor` and `BGColor` have the same color Enum values.

These Colors are supported in most terminals.
In terms of portability, it is recommended to use `FGColor` and `BGColor` instead of `ColorRGB` and `Color256`.

| normal    | bright           |
|-----------|------------------|
| `BLACK`   | `BRIGHT_BLACK`   |
| `RED`     | `BRIGHT_RED`     |
| `GREEN`   | `BRIGHT_GREEN`   |
| `YELLOW`  | `BRIGHT_YELLOW`  |
| `BLUE`    | `BRIGHT_BLUE`    |
| `MAGENTA` | `BRIGHT_MAGENTA` |
| `CYAN`    | `BRIGHT_CYAN`    |
| `WHITE`   | `BRIGHT_WHITE`   |

> [!TIP]
> Actual color may vary depending on the terminal.
> here's an example of how it looks in the terminal. (Capture from `Windows Terminal`)
>
> ![capture](https://github.com/nagataaaas/Iro/blob/main/assets/capture3.png?raw=true)
> <details><summary>Code</summary>
>
> ```python
> fg_normals = [color for color in FGColor if not color.name.startswith("BRIGHT_")]
> fg_brights = [color for color in FGColor if color.name.startswith("BRIGHT_")]
> print(Iro('FG Normal',
>           Iro(
>               ColorRGB(100, 100, 100, bg=True),
>               [[color, color.name] for color in fg_normals],
>               sep=" ",
>           ),
>           'FG Bright',
>           Iro(
>               ColorRGB(50, 50, 50, bg=True),
>               [[color, color.name[7:]] for color in fg_brights],
>               sep=" ",
>           ),
>           sep="\n", collect_styles_first=False))
> print('-'*80)
> bg_normals = [color for color in BGColor if not color.name.startswith("BRIGHT_")]
> bg_brights = [color for color in BGColor if color.name.startswith("BRIGHT_")]
> print(Iro('BG Normal',
>           Iro(
>               ColorRGB(100, 100, 100),
>               [[color, color.name] for color in bg_normals],
>               sep=" ",
>           ),
>           'BG Bright',
>           Iro(
>               ColorRGB(50, 50, 50),
>               [[color, color.name[7:]] for color in bg_brights],
>               sep=" ",
>           ),
>           sep="\n", collect_styles_first=False))
> ```
> </details>

## `Color256(number: int, bg: bool = False)`

- number: number of pre-defined 8-bit color. `0 <= number <= 255`
- bg: if `True`, This color will be applied to background.

> [!TIP]
> Color number is defined as below.
>
> ![color256](https://github.com/nagataaaas/Iro/blob/main/assets/256.png?raw=true)
> image
> from [https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit)

## `ColorRGB(r: int, g: int, b: int, bg: bool = False)`

| Parameter | Type             | Description                                          |
|-----------|------------------|------------------------------------------------------|
| `r`       | `int` or `float` | value of Red. `0 <= number <= 255`                   |
| `g`       | `int` or `float` | value of Green. `0 <= number <= 255`                 |
| `b`       | `int` or `float` | value of Blue. `0 <= number <= 255`                  |
| `bg`      | `bool`           | if `True`, This color will be applied to background. |

### `ColorRGB.from_color_code(color_code: str, bg: bool = False) -> ColorRGB`

| Parameter    | Type   | Description                                          |
|--------------|--------|------------------------------------------------------|
| `color_code` | `str`  | color code. `#?[0-9a-fA-F]{6}`                       |
| `bg`         | `bool` | if `True`, This color will be applied to background. |

## `Font(font_number: int)`

| Parameter     | Type  | Description                                      |
|---------------|-------|--------------------------------------------------|
| `font_number` | `int` | number of font. `0` is default font. up to `10`. |

# Q&A

### Q: My `ColorRGB` and `Color256` is not working!

The problem is most likely caused by the console not supporting it. Try another console or consider using `FGColor`
and `BGColor`.

### Q: My `ColorRGB` is not the color that I specified!

If `disable_rgb` is `True`, `Iro` will convert every `ColorRGB` to similar `Color256`. Make sure `disable_rgb` is set
to `False`.

### Q: Coloring, Styling and Fonts are not working!

Not all styles are supported by all consoles. Try another console.

### Q: Weird string like `・[0m・[0m・[5m・[48;2;168;102;255m ・[0m・[0m・[5m` are showing up and not working at all!

Your console is not supporting ANSI escape sequences. Try another console. Or, you can try `colorama`.\
insert this code below in your Script

```python
from colorama import init

init()
```

### Q: How effective is optimization?

ok, Let me show some codes and screenshot.

```python
from iro import Iro, FGColor, Style

values = [
    FGColor.RED, "[RED]",
    [
        Style.UNDERLINE, "[RED/UNDERLINE]",
        [
            Style.BOLD, FGColor.GREEN, "[GREEN/UNDERLINE/BOLD]",
            [
                Style.INVERT, "[GREEN/UNDERLINE/BOLD/INVERT]",
                [
                    Style.OFF_BOLD, "[GREEN/UNDERLINE/INVERT]"
                ]
            ],
            "[GREEN/UNDERLINE/BOLD]"
        ],
        "[RED/UNDERLINE]"
    ]
]
print(Iro(values))
```

output is below

![output](https://github.com/nagataaaas/Iro/blob/main/assets/capture4.png?raw=true)

Now, let's see how optimization works

```python
print(repr(Iro(values).text))
# '\x1b[31m[RED]\x1b[4m[RED/UNDERLINE]\x1b[1m\x1b[32m[GREEN/UNDERLINE/BOLD]\x1b[7m[GREEN/UNDERLINE/BOLD/INVERT]\x1b[22m[GREEN/UNDERLINE/INVERT]\x1b[1m\x1b[27m[GREEN/UNDERLINE/BOLD]\x1b[22m\x1b[31m[RED/UNDERLINE]\x1b[0m'
```

Let's see how the ANSI escape sequences are optimized.

```text
\x1b[31m   # FG_RED
[RED]      # (TEXT)
    \x1b[4m          = UNDERLINE
    [RED/UNDERLINE]  = (TEXT)
        \x1b[1m                 % BOLD
        \x1b[32m                % FG_GREEN
        [GREEN/UNDERLINE/BOLD]  % (TEXT)
            \x1b[7m                       # INVERT
            [GREEN/UNDERLINE/BOLD/INVERT] # (TEXT)
                \x1b[22m                     = OFF_BOLD
                [GREEN/UNDERLINE/INVERT]     = (TEXT)
                \x1b[1m                      = BOLD
            \x1b[27m                      # OFF_INVERT
        [GREEN/UNDERLINE/BOLD]  % (TEXT)
        \x1b[22m                % OFF_BOLD
    \x1b[31m         = FG_RED
    [RED/UNDERLINE]  = (TEXT)
\x1b[0m    # RESET
```

As you can see, the `Iro` instance will optimize the ANSI escape sequences to reduce the number of characters to be
rendered.

### Q: Do I need to create a new `Iro` instance or list every time I want to change the style?

In default, `Iro` will collect all styles in the nest depth before rendering non-style elements.\
This behavior prohibits the style from being changed in the middle of the same nest depth.

However, you can disable this behavior by setting `collect_styles_first` to `False`.

![output](https://github.com/nagataaaas/Iro/blob/main/assets/capture4.png?raw=true)

```python
from iro import Iro, FGColor, Style

values_nested = (
    "Hello! I'm ",
    (
        FGColor.RED,
        Style.DOUBLY_UNDERLINE,
        "Iro!",
    ),
    " Nice to meet you!",
)

values_flatten = ("Hello! I'm ", FGColor.RED, Style.DOUBLY_UNDERLINE, "Iro!", Style.RESET, " Nice to meet you!")

print(Iro(values_nested))
print(Iro(values_flatten))
print(Iro(values_flatten, collect_styles_first=False))
```
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "iro",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "cli, color, colorize, colorizer, console, library, terminal, tool",
    "author": null,
    "author_email": "Yamato Nagata <nagata@nagata.pro>",
    "download_url": "https://files.pythonhosted.org/packages/06/ce/38e1160c09ea3f0921cc0d00366a4cde4ac0c33f8d0d7be437a706358dcb/iro-1.0.0.tar.gz",
    "platform": null,
    "description": "IRO\n===\n\nEasy and powerful Colorizer for Python!\n\nPowered by [Yamato Nagata](https://twitter.com/514YJ)\n\n[GitHub](https://github.com/nagataaaas/Iro)\n\nThe depth represents the block and style in the block affects elements within that block.\n\n![output](https://github.com/nagataaaas/Iro/blob/main/assets/capture1.png?raw=true)\n\n<details><summary>Code</summary>\n\n```python\nfrom iro import Iro, FGColor, BGColor, Style, ColorRGB, Color256\n\nfrom colorsys import hls_to_rgb\n\nsuccess = Iro((FGColor.GREEN, \"[  SUCCESS ]\"))\nsuccess_rendered = success.str  # You can get rendered string by .str attribute\nerror = Iro((ColorRGB(255, 255, 255), BGColor.RED, Style.DOUBLY_UNDERLINE, \"[   ERROR  ]\"))\nwarning = Iro((FGColor.YELLOW, Color256(255, bg=True), \"[  WARNING ]\"))\ndeprecated = Iro((Color256(7), Color256(239, True), Style.STRIKE, \"[DEPRECATED]\"))\n\nprint(success_rendered, 'Something is done successfully.\\n')\nprint(error, 'Something is wrong.\\n')\nprint(warning, 'Something is not good.\\n')\nprint(deprecated, 'This feature is deprecated.\\n')\n\nprint(Iro([\n    FGColor.RED, \"Of course, You can nest styles.\",\n    [\n        Style.ITALIC,\n        \"This is RED and ITALIC.\"\n    ],\n    [\n        FGColor.BLUE,\n        \"This is BLUE, BG_BRIGHT_BLACK and UNDERLINED.\",\n        BGColor.BRIGHT_BLACK,  # Style will be collected before rendering non-style elements\n        Style.UNDERLINE,\n        [\n            Style.RESET,\n            \"Back to normal.\\nWith new line.\"\n        ]\n    ],\n    \"Finally back to only RED!\"\n],\n    sep=Iro(Style.RESET, \" \")))\n\nfor h in range(256):\n    print(Iro([ColorRGB(*map(lambda x: x * 255, hls_to_rgb(h / 256, 0.7, 1)), bg=True), ' ']), end='')\n\nprint(Iro([\n    \"normal\", Style.BOLD, \"bold\", Style.DIM, \"bold-dim\", Style.OFF_BOLD, \"dim\", Style.OFF_DIM, Style.BOLD, \"bold\",\n    FGColor.RED, \"red-bold\", Style.RESET, \"normal\"\n], collect_styles_first=False, sep=Iro(Style.RESET, \" \")))\n```\n\n</details>\n\n# Installation\n\n```    \n$ pip install iro\n```\n\n# Documentation\n\n## `Iro(*values: Any, disable_rgb: bool = True, sep: str | Iro = \"\", collect_styles_first: bool = True)`\n\n| Parameter              | Type           | Description                                                                                                                                                                                         |\n|------------------------|----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `values`               | `Any`          | values that will be rendered. `Iro`, `IroElement`, `str`, `int`, `float`, `list`, `tuple`, `dict`, etc.                                                                                             |\n| `disable_rgb`          | `bool`         | if `True`, `ColorRGB` will be converted to similar color of `Color256`. This is for supporting some consoles that does not support `ColorRGB`.                                                      |\n| `sep`                  | `str` or `Iro` | separator between elements. If `str` is given, it will be rendered as it is. If `Iro` is given, it will be rendered like it's part of the `values`. This will be rendered between non-style values. |\n| `collect_styles_first` | `bool`         | if `True`, all styles in the nest depth will be collected before rendering non-style elements. If `False`, styles will be rendered as they are found.                                               |\n\n`Iro().text` or `Iro().str` to fetch result.\n\n> [!NOTE]\n> Each time you try to get `Iro().text`, `Iro().str` or `str(Iro())`, it will be rendered again.\\\n> So if you want to use it multiple times, storing the result in a variable is recommended.\n>\n> However, if you want to render the `Iro` instance inside the other `Iro` instance (as an item of `values` or `sep`),\n> passing the `str` generated with `Iro().text` can cause a problem.\n> ![output](https://github.com/nagataaaas/Iro/blob/main/assets/capture2.png?raw=true)\n> <details><summary>Code</summary>\n>\n> ```python\n> from iro import Iro, FGColor\n> \n> blue_and = Iro(FGColor.BLUE, \" and \")\n> blue_and_str = blue_and.str\n> print(Iro(FGColor.RED, \"red\", blue_and, \"red\"))\n> print(Iro(FGColor.RED, \"red\", \"red\", sep=blue_and))\n> print(Iro(FGColor.RED, \"red\", blue_and_str, \"red\"))\n> print(Iro(FGColor.RED, \"red\", \"red\", sep=blue_and_str))\n> ```\n> </details>\n>\n> This is because of 2 reasons.\\\n> 1st, `Iro` instance can detect other `Iro` instance to be rendered as part of it, and render only style diff before\n> and after the recursive rendering.\\\n> And 2nd, `Iro` instance will reset all styles at the end of rendering if it's the root `Iro` instance.\\\n> For these reasons, if you pass `str` generated with `Iro().text`, `Iro` can no longer understand the style applied to\n> the current cursor position, and will cause a problem.\n\n### `Iro().text -> str`\n\nGet rendered string.\n\n### `Iro().str -> str`\n\nGet rendered string.\n\n## `Style`\n\nEnum of defined `Style`.\n\n| Style              | Description                                                                                                                      |\n|--------------------|----------------------------------------------------------------------------------------------------------------------------------|\n| `RESET`            | Reset all styles. including color and background color.                                                                          |\n| `NORMAL`           | Alias of `RESET`.                                                                                                                |\n| `BOLD`             | Bold or increased intensity.                                                                                                     |\n| `DIM`              | Faint, decreased intensity, or dim. in some terminals, this may be implemented as a light font weight and this overrides `BOLD`. |\n| `ITALIC`           | Italic. Not widely supported. Sometimes treated as inverse.                                                                      |\n| `UNDERLINE`        | Underline.                                                                                                                       |\n| `SLOW_BLINK`       | Slow Blink.                                                                                                                      |\n| `RAPID_BLINK`      | Rapid Blink. Not widely supported.                                                                                               |\n| `INVERT`           | Invert foreground and background colors.                                                                                         |\n| `HIDE`             | Hide text. Not widely supported.                                                                                                 |\n| `STRIKE`           | Strikethrough.                                                                                                                   |\n| `OVERLINE`         | Overline. Not widely supported.                                                                                                  |\n| `GOTHIC`           | Gothic. Rarely supported.                                                                                                        |\n| `DOUBLY_UNDERLINE` | Double underline. Rarely supported.                                                                                              |\n\nand `OFF_*` styles to disable each style.\n\n| Style                  | Description                             |\n|------------------------|-----------------------------------------|\n| `OFF_BOLD`             | Disable `BOLD`.                         |\n| `OFF_DIM`              | Disable `DIM`.                          |\n| `OFF_ITALIC`           | Disable `ITALIC`.                       |\n| `OFF_UNDERLINE`        | Disable `UNDERLINE`.                    |\n| `OFF_INVERT`           | Disable `INVERT`.                       |\n| `OFF_HIDE`             | Disable `HIDE`.                         |\n| `OFF_STRIKE`           | Disable `STRIKE`.                       |\n| `OFF_OVERLINE`         | Disable `OVERLINE`.                     |\n| `OFF_GOTHIC`           | Disable `GOTHIC`.                       |\n| `OFF_DOUBLY_UNDERLINE` | Disable `DOUBLY_UNDERLINE`.             |\n| `OFF_FONT`             | Reset font to default.                  |\n| `OFF_INTENSITY`        | Disable `BOLD` and `DIM`.               |\n| `OFF_BLINK`            | Disable `SLOW_BLINK` and `RAPID_BLINK`. |\n| `OFF_FG_COLOR`         | Reset foreground color.                 |\n| `OFF_BG_COLOR`         | Reset background color.                 |\n\n## `FGColor`, `BGColor`\n\nEnum of 3-bit and 4-bit color.\n\n`FGColor` is for foreground color, and `BGColor` is for background color.\nBoth `FGColor` and `BGColor` have the same color Enum values.\n\nThese Colors are supported in most terminals.\nIn terms of portability, it is recommended to use `FGColor` and `BGColor` instead of `ColorRGB` and `Color256`.\n\n| normal    | bright           |\n|-----------|------------------|\n| `BLACK`   | `BRIGHT_BLACK`   |\n| `RED`     | `BRIGHT_RED`     |\n| `GREEN`   | `BRIGHT_GREEN`   |\n| `YELLOW`  | `BRIGHT_YELLOW`  |\n| `BLUE`    | `BRIGHT_BLUE`    |\n| `MAGENTA` | `BRIGHT_MAGENTA` |\n| `CYAN`    | `BRIGHT_CYAN`    |\n| `WHITE`   | `BRIGHT_WHITE`   |\n\n> [!TIP]\n> Actual color may vary depending on the terminal.\n> here's an example of how it looks in the terminal. (Capture from `Windows Terminal`)\n>\n> ![capture](https://github.com/nagataaaas/Iro/blob/main/assets/capture3.png?raw=true)\n> <details><summary>Code</summary>\n>\n> ```python\n> fg_normals = [color for color in FGColor if not color.name.startswith(\"BRIGHT_\")]\n> fg_brights = [color for color in FGColor if color.name.startswith(\"BRIGHT_\")]\n> print(Iro('FG Normal',\n>           Iro(\n>               ColorRGB(100, 100, 100, bg=True),\n>               [[color, color.name] for color in fg_normals],\n>               sep=\" \",\n>           ),\n>           'FG Bright',\n>           Iro(\n>               ColorRGB(50, 50, 50, bg=True),\n>               [[color, color.name[7:]] for color in fg_brights],\n>               sep=\" \",\n>           ),\n>           sep=\"\\n\", collect_styles_first=False))\n> print('-'*80)\n> bg_normals = [color for color in BGColor if not color.name.startswith(\"BRIGHT_\")]\n> bg_brights = [color for color in BGColor if color.name.startswith(\"BRIGHT_\")]\n> print(Iro('BG Normal',\n>           Iro(\n>               ColorRGB(100, 100, 100),\n>               [[color, color.name] for color in bg_normals],\n>               sep=\" \",\n>           ),\n>           'BG Bright',\n>           Iro(\n>               ColorRGB(50, 50, 50),\n>               [[color, color.name[7:]] for color in bg_brights],\n>               sep=\" \",\n>           ),\n>           sep=\"\\n\", collect_styles_first=False))\n> ```\n> </details>\n\n## `Color256(number: int, bg: bool = False)`\n\n- number: number of pre-defined 8-bit color. `0 <= number <= 255`\n- bg: if `True`, This color will be applied to background.\n\n> [!TIP]\n> Color number is defined as below.\n>\n> ![color256](https://github.com/nagataaaas/Iro/blob/main/assets/256.png?raw=true)\n> image\n> from [https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit)\n\n## `ColorRGB(r: int, g: int, b: int, bg: bool = False)`\n\n| Parameter | Type             | Description                                          |\n|-----------|------------------|------------------------------------------------------|\n| `r`       | `int` or `float` | value of Red. `0 <= number <= 255`                   |\n| `g`       | `int` or `float` | value of Green. `0 <= number <= 255`                 |\n| `b`       | `int` or `float` | value of Blue. `0 <= number <= 255`                  |\n| `bg`      | `bool`           | if `True`, This color will be applied to background. |\n\n### `ColorRGB.from_color_code(color_code: str, bg: bool = False) -> ColorRGB`\n\n| Parameter    | Type   | Description                                          |\n|--------------|--------|------------------------------------------------------|\n| `color_code` | `str`  | color code. `#?[0-9a-fA-F]{6}`                       |\n| `bg`         | `bool` | if `True`, This color will be applied to background. |\n\n## `Font(font_number: int)`\n\n| Parameter     | Type  | Description                                      |\n|---------------|-------|--------------------------------------------------|\n| `font_number` | `int` | number of font. `0` is default font. up to `10`. |\n\n# Q&A\n\n### Q: My `ColorRGB` and `Color256` is not working!\n\nThe problem is most likely caused by the console not supporting it. Try another console or consider using `FGColor`\nand `BGColor`.\n\n### Q: My `ColorRGB` is not the color that I specified!\n\nIf `disable_rgb` is `True`, `Iro` will convert every `ColorRGB` to similar `Color256`. Make sure `disable_rgb` is set\nto `False`.\n\n### Q: Coloring, Styling and Fonts are not working!\n\nNot all styles are supported by all consoles. Try another console.\n\n### Q: Weird string like `\uff65[0m\uff65[0m\uff65[5m\uff65[48;2;168;102;255m \uff65[0m\uff65[0m\uff65[5m` are showing up and not working at all!\n\nYour console is not supporting ANSI escape sequences. Try another console. Or, you can try `colorama`.\\\ninsert this code below in your Script\n\n```python\nfrom colorama import init\n\ninit()\n```\n\n### Q: How effective is optimization?\n\nok, Let me show some codes and screenshot.\n\n```python\nfrom iro import Iro, FGColor, Style\n\nvalues = [\n    FGColor.RED, \"[RED]\",\n    [\n        Style.UNDERLINE, \"[RED/UNDERLINE]\",\n        [\n            Style.BOLD, FGColor.GREEN, \"[GREEN/UNDERLINE/BOLD]\",\n            [\n                Style.INVERT, \"[GREEN/UNDERLINE/BOLD/INVERT]\",\n                [\n                    Style.OFF_BOLD, \"[GREEN/UNDERLINE/INVERT]\"\n                ]\n            ],\n            \"[GREEN/UNDERLINE/BOLD]\"\n        ],\n        \"[RED/UNDERLINE]\"\n    ]\n]\nprint(Iro(values))\n```\n\noutput is below\n\n![output](https://github.com/nagataaaas/Iro/blob/main/assets/capture4.png?raw=true)\n\nNow, let's see how optimization works\n\n```python\nprint(repr(Iro(values).text))\n# '\\x1b[31m[RED]\\x1b[4m[RED/UNDERLINE]\\x1b[1m\\x1b[32m[GREEN/UNDERLINE/BOLD]\\x1b[7m[GREEN/UNDERLINE/BOLD/INVERT]\\x1b[22m[GREEN/UNDERLINE/INVERT]\\x1b[1m\\x1b[27m[GREEN/UNDERLINE/BOLD]\\x1b[22m\\x1b[31m[RED/UNDERLINE]\\x1b[0m'\n```\n\nLet's see how the ANSI escape sequences are optimized.\n\n```text\n\\x1b[31m   # FG_RED\n[RED]      # (TEXT)\n    \\x1b[4m          = UNDERLINE\n    [RED/UNDERLINE]  = (TEXT)\n        \\x1b[1m                 % BOLD\n        \\x1b[32m                % FG_GREEN\n        [GREEN/UNDERLINE/BOLD]  % (TEXT)\n            \\x1b[7m                       # INVERT\n            [GREEN/UNDERLINE/BOLD/INVERT] # (TEXT)\n                \\x1b[22m                     = OFF_BOLD\n                [GREEN/UNDERLINE/INVERT]     = (TEXT)\n                \\x1b[1m                      = BOLD\n            \\x1b[27m                      # OFF_INVERT\n        [GREEN/UNDERLINE/BOLD]  % (TEXT)\n        \\x1b[22m                % OFF_BOLD\n    \\x1b[31m         = FG_RED\n    [RED/UNDERLINE]  = (TEXT)\n\\x1b[0m    # RESET\n```\n\nAs you can see, the `Iro` instance will optimize the ANSI escape sequences to reduce the number of characters to be\nrendered.\n\n### Q: Do I need to create a new `Iro` instance or list every time I want to change the style?\n\nIn default, `Iro` will collect all styles in the nest depth before rendering non-style elements.\\\nThis behavior prohibits the style from being changed in the middle of the same nest depth.\n\nHowever, you can disable this behavior by setting `collect_styles_first` to `False`.\n\n![output](https://github.com/nagataaaas/Iro/blob/main/assets/capture4.png?raw=true)\n\n```python\nfrom iro import Iro, FGColor, Style\n\nvalues_nested = (\n    \"Hello! I'm \",\n    (\n        FGColor.RED,\n        Style.DOUBLY_UNDERLINE,\n        \"Iro!\",\n    ),\n    \" Nice to meet you!\",\n)\n\nvalues_flatten = (\"Hello! I'm \", FGColor.RED, Style.DOUBLY_UNDERLINE, \"Iro!\", Style.RESET, \" Nice to meet you!\")\n\nprint(Iro(values_nested))\nprint(Iro(values_flatten))\nprint(Iro(values_flatten, collect_styles_first=False))\n```",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2021 nagataaaas  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Easy and powerful Colorizer for Python!",
    "version": "1.0.0",
    "project_urls": null,
    "split_keywords": [
        "cli",
        " color",
        " colorize",
        " colorizer",
        " console",
        " library",
        " terminal",
        " tool"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "23d7b605110c90fdca0c5f8efc26b08f17c08087c56a4e1acb45aaf71146f705",
                "md5": "d419b4e53e1d7f31e7bf350817695397",
                "sha256": "8e4df91a9d63b32fd2b691c1c14bc7ccb3617e27f710376f778c9be505372306"
            },
            "downloads": -1,
            "filename": "iro-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d419b4e53e1d7f31e7bf350817695397",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 13268,
            "upload_time": "2024-09-25T05:33:35",
            "upload_time_iso_8601": "2024-09-25T05:33:35.434863Z",
            "url": "https://files.pythonhosted.org/packages/23/d7/b605110c90fdca0c5f8efc26b08f17c08087c56a4e1acb45aaf71146f705/iro-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "06ce38e1160c09ea3f0921cc0d00366a4cde4ac0c33f8d0d7be437a706358dcb",
                "md5": "3480561222f4a169724a574039351ba9",
                "sha256": "7e83729b257c5fabcfe36455ac044dc2fdf372e23f7ea97e9527f33448215f6c"
            },
            "downloads": -1,
            "filename": "iro-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3480561222f4a169724a574039351ba9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 185384,
            "upload_time": "2024-09-25T05:33:41",
            "upload_time_iso_8601": "2024-09-25T05:33:41.630284Z",
            "url": "https://files.pythonhosted.org/packages/06/ce/38e1160c09ea3f0921cc0d00366a4cde4ac0c33f8d0d7be437a706358dcb/iro-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-25 05:33:41",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "iro"
}
        
Elapsed time: 0.56025s