colurful


Namecolurful JSON
Version 1.5.4 PyPI version JSON
download
home_pagehttp://github.com/
SummaryTerminal string styling done right, in Python.
upload_time2023-02-10 12:41:03
maintainerTimo
docs_urlNone
authorTimo Furrer
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # colurful


Terminal string styling done right, in Python :tada:

## Here's a tease



```python
import colurful as cf

# create a colored string using clever method translation
print(cf.bold_white('Hello World'))
# create a colored string using `str.format()`
print('{c.bold}{c.lightCoral_on_white}Hello World{c.reset}'.format(c=cf))

# nest colors
print(cf.red('red {0} red'.format(cf.white('white'))))
print(cf.red('red' + cf.white(' white ', nested=True) + 'red'))

# combine styles with strings
print(cf.bold & cf.red | 'Hello World')

# use true colors
cf.use_true_colors()

# extend default color palette
cf.update_palette({'mint': '#c5e8c8'})
print(cf.mint_on_snow('Wow, this is actually mint'))

# choose a predefined style
cf.use_style('solarized')
# print the official solarized colors
print(cf.yellow('yellow'), cf.orange('orange'),
    cf.red('red'), cf.magenta('magenta'),
    cf.violet('violet'), cf.blue('blue'),
    cf.cyan('cyan'), cf.green('green'))

# directly print with colors
cf.print('{c.bold_blue}Hello World{c.reset}')

# choose specific color mode for one block
with cf.with_8_ansi_colors() as c:
    print(c.bold_green('colurful is awesome!'))

# create and choose your own color palette
MY_COMPANY_PALETTE = {
    'companyOrange': '#f4b942',
    'companyBaige': '#e8dcc5'
}
with cf.with_palette(MY_COMPANY_PALETTE) as c:
    print(c.companyOrange_on_companyBaige('Thanks for choosing our product!'))

# use f-string (only Python >= 3.6)
print(f'{cf.bold}Hello World')

# support for chinese
print(cf.red('你好'))
```

## Key Features

* expressive and consistent API ([docs](#style-a-string))
* support for different color modes (8 ANSI, 256 ANSI, true colors) ([docs](#color-modes))
* support for predefined awesome styles (solarized, ...) ([docs](#styles))
* support for custom color palettes ([docs](#color-palette))
* support nesting styles ([docs](#nesting-styles))
* support for different platforms (using colorama on Windows)
* context managers for clean color mode, color palette or style switch ([docs](#temporarily-change-colurful-settings))
* support `len()` on colored strings ([docs](#correctly-support-the-len-protocol))
* support color names from [X11 rgb.txt](https://en.wikipedia.org/wiki/X11_color_names) ([docs](#1-style-a-string-with-a-method-call-colurfulmodifiers_fgcolor_on_bgcolorstr-nestedfalse))
* no dependencies

## Usage

**colurful** supports all major Python versions: *3.5*, *3.6* and *3.7*, *3.8*, *3.9*, *3.10*, *3.11*. <br>
We recommend to use the latest version released on [PyPI](https://pypi.python.org/pypi/colurful):

```bash
pip install colurful
```

**colurful** does not require any special setup in order to be used:

```python
import colurful as cf

print(cf.italic_coral_on_beige('Hello World'))
print(cf.italic & cf.coral_on_beige | 'Hello World')
print('{c.italic_coral_on_beige}Hello World{c.reset}'.format(c=cf))
```

Note: the entire documentation assumes `colurful` to be imported as `cf`.

See the [Style a string](https://github.com/timofurrr/colurful#style-a-string) section for more information!

### Color modes

These days terminals not only support the ancient 8 ANSI colors but often they support up to 16 Million colors with *[true color](https://en.wikipedia.org/wiki/Color_depth#True_color_.2824-bit.29)*. And if they don't support *true color* they might support the *[256 ANSI color palette](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors)* at least.

**colurful** supports the following color modes:

* no colors / disable (``cf.NO_COLORS``)
* 8 colors -> 8 ANSI colors (``cf.ANSI_8_COLORS``)
* 256 colors -> 256 ANSI color palette (8bit ``cf.ANSI_256_COLORS``)
* 16'777'215 colors -> true color (24bit, ``cf.TRUE_COLORS``)

By default *colurful* tries to auto detect the best supported color mode by your terminal. Consult [`cf.terminal`](https://github.com/timurrer/colurful/blob/master/colurful/terminal.py) for more details.

However, sometimes it makes sense to specify what color mode should be used.<br>
**colurful** provides multiple ways to do so:

#### (1) specify color mode globally via Python API

```python
cf.disable()
cf.use_8_ansi_colors()
cf.use_256_ansi_colors()
cf.use_true_colors()
```

If you change the color mode during runtime it takes affect immediately and globally.

#### (2) enforce color mode globally via environment variable

```bash
colurfulL_DISABLE=1 python eggs.py  # this process will not use ANY coloring
colurful_FORCE_8_COLORS=1 python eggs.py  # this process will use 8 ANSI colors by default
colurful_FORCE_256_COLORS=1 python eggs.py  # this process will use 256 ANSI colors by default
colurful_FORCE_TRUE_COLORS=1 python eggs.py  # this process will use true colors by default
```

#### (3) specify color mode locally via Python API (contextmanager)

```python
with cf.with_8_ansi_colors() as c:
    print(c.italic_coral_on_beige('Hello world'))

with cf.with_256_ansi_colors() as c:
    print(c.italic_coral_on_beige('Hello world'))

with cf.with_true_colors() as c:
    print(c.italic_coral_on_beige('Hello world'))
```

### colurful palette

**colurful**'s Python API is based on *color names* like in `cf.bold_white_on_black('Hello')`. During runtime these *color names* are translated into proper [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code) sequences supported by the *color mode* in use. However, all *color names* are registered in a **color palette** which is basically a mapping between the *color names* and it's corresponding RGB value. Very much like this:

```python
color_palette_example = {
    'black': '#000000',
    'white': '#FFFFFF',
}
```

*Note: Depending on the color mode which is used the RGB value will be reduced to fit in the value domain of the color mode.*

The default color palette is the [X11 rgb.txt](https://en.wikipedia.org/wiki/X11_color_names) palette - it's shipped with *colurful*, thus, you don't have to provide your own.
*colurful* ships with a second built-in [color palette called *colornames*](https://codepen.io/meodai/full/VMpNdQ/).
Those colors are from the curated list of the [color-names](https://github.com/meodai/color-names) repository.
You can use those via the `cf.setup()` method, like this:


```python
cf.setup(colorpalette=cf.COLORNAMES_COLORS)
```

If you wish to have another color palette from a file as your default color palette you can set the `colurful_DEFAULT_COLOR_PALETTE` environment variable to this file:

```bash
colurful_DEFAULT_COLOR_PALETTE=/usr/share/X11/rgb.txt python spam.py
```

The file either has to be a txt file like the X11 rgb.txt or a JSON file:

```json
[
    {"name": "18th Century Green", "hex":"#a59344"},
    {"name": "1975 Earth Red", "hex":"#7a463a"}
]
```

#### Custom color palette
**colurful** supports to update or replace the default color palette with custom colors. The colors have to be specified as RGB hex or channel values:

```python
# corporate identity colors
ci_colors = {
    'mint': '#c5e8c8',  # RGB hex value
    'darkRed': '#c11b55',  # RGB hex value
    'lightBlue': (15, 138, 191)  # RGB channel triplet
}

# replace the default palette with my custom one
cf.use_palette(ci_colors)
# update the default palette with my custom one
cf.update_palette(ci_colors)

# we can use these colors
print(cf.italic_mint_on_darkRed('My company'))
```

### Styles

**colurful** supports some famous color palettes using what's called *styles* in colurful:

```python
cf.use_style('solarized')

# print the official solarized colors
print(cf.yellow('yellow'), cf.orange('orange'),
    cf.red('red'), cf.magenta('magenta'),
    cf.violet('violet'), cf.blue('blue'),
    cf.cyan('cyan'), cf.green('green'))
```

The following styles are already supported:

<details open>
 <summary>solarized - <a href="http://ethanschoonover.com/solarized">Website</a></summary>
 <br>
 <img src="https://github.com/timofurrer/colurful/blob/master/examples/solarized_base_colors.png" alt="solarized colors">
</details>
<details open>
 <summary>monokai</summary>
 <br>
 <img src="https://github.com/timofurrer/colurful/blob/master/examples/monokai_base_colors.png" alt="monokai colors">
</details>
<br>

*Note: if you know some awesome color palettes which could be a new style in colurful, please contribute it!*

### Style a string

**colurful** provides multiple ways to use style a string. Most useful and expressive is probably the *method syntax* where you specify the modifiers and colors in the method name itself and pass the string as argument to this method. However, you can use all the following methods to achive similars things:

#### (1) Style a string with a method call `cf.[<modifiers...>]_[<fgColor>]_[on_<bgColor>](str, nested=False)`

```python
print(cf.red('I am red'))
print(cf.italic_yellow('I am italic and yellow'))
print(cf.black_on_white('I am black on white'))
```

The method syntax can be one of:

* `cf.<modifier>`
* `cf.<modifier1>_<modifier2>`
* `cf.<fg_color>`
* `cf.on_<bg_color>`
* `cf.<modifiers>_<fg_color>`
* `cf.<modifiers>_<bg_color>`
* `cf.<fg_colors>_on_<bg_color>`
* `cf.<modifiers>_<fg_color>_on_<bg_color>`

*Note that multiple `<modifier>`s can be specified at once.*

Available modifiers are:

* reset (explicitely reset all styles before the passed argument)
* bold
* dimmed (not widely supported)
* italic
* underlined
* blinkslow
* blinkrapid
* inversed (not widely supported)
* concealed (not widely supported)
* struckthrough

The available colors depend on the [color palette](#color-palette) you are using. By default all [X11 rgb.txt colors](https://en.wikipedia.org/wiki/X11_color_names) are available.

The type of the return value of such a *style method* is `colurful.colurfulString`. It correctly supports all `str()` methods including [`len()`](#correctly-support-the-len-protocol).

As you can see from the syntax in the section name, **colurful** supports nesting styles. See [Nesting styles](#nesting-styles).

#### (2) Style a string with `&` and `|`

**colurful** implements the `__or__` and `__and__` protocol to combine styles and pipe strings into them:

```python
print(cf.bold & cf.red | 'Hello World')
print(cf.bold_red_on_black | 'Hello World')
print(cf.bold | cf.red_on_black('Hello World')
```

*Note: the piping `|` has the same effect as doing a method call to the style.<br>
So you could do `(cf.bold & cf.red)('Hello World')`*

#### (3) Style a string with `cf.format(string, *args, **kwargs)`

```python
print(cf.format('{c.red}I am {what}{c.close_fg_color}', what='red'))
# alternatively to ``c.close_fg_color`` you can reset every style with ``c.reset``
print(cf.format('{c.red}I am red{c.reset}'))

print(cf.format('{c.italic_yellow}I am italic and yellow{c.no_italic}{c.close_fg_color}'))
print(cf.format('{c.black_on_white}I am black on white{c.close_fg_color}{c.close_bg_color}'))
```

**colurful** will replace the `{c.<style>}` with the correspnding style. It's **not** necessary to pass a colurful object for `c` to `format()` - colurful will handle that. Every other format argument (`{<name>}`) has to be pass to the `cf.format()` call as *args* or *kwarg*.

Note: The same syntax, modifiers and colors for the style in `{c.<style>}` can be used as for [(1) Style a string with a method call](#1-style-a-string-with-a-method-call).

#### (4) Style and print a string with `cf.print(*strings, sep=' ', end='\n', file=sys.stdout, flush=False)`

```python
cf.print('{c.italic_yellow}I am italic and yellow{c.no_italic}{c.close_fg_color}')
cf.print('{c.red}I am red{c.reset}', end='', file=open('log.txt', 'a+'))
```

The `cf.print()` method accepts the same arguments as the Python 3.X [built-in print()](https://docs.python.org/3/library/functions.html#print) function.

#### (5) Style a string with [`str.format()`](https://docs.python.org/3.6/library/stdtypes.html#str.format)

```python
print('{c.red}I am red{c.close_fg_color}'.format(c=cf))
# alternatively to ``c.close_fg_color`` you can reset every style with ``c.reset``
print('{c.red}I am red{c.reset}'.format(c=cf))

print('{c.italic_yellow}I am italic and yellow{c.no_italic}{c.close_fg_color}'.format(
    c=cf))
print('{c.black_on_white}I am black on white{c.close_fg_color}{c.close_bg_color}'.format(
    c=cf))
```

Note: The same syntax, modifiers and colors for the style in `{c.<style>}` can be used as for [(1) Style a string with a method call](#1-style-a-string-with-a-method-call).

#### Nesting styles

**colurful** supports to nest styles with it's [method call syntax](#1-style-a-string-with-a-method-call) when setting the parameter `nested` to `True`.
If you are using `str.format()` like in the first example below you don't even need the `nested=True` flag!

The following examples show the behavior:

```python
print(cf.red('red {0} red'.format(cf.white('white'))))
print(cf.red('red' + cf.white(' white ', nested=True) + 'red'))

# if using ``nested=True`` but you don't actually nest
# it's absolutely fine and will work as expected.
print(cf.red('red', nested=True) + ' default color')
```

#### Correctly support the [`len()` protocol](https://docs.python.org/3/library/functions.html#len)

**colurful** correctly supports the `len()` protocol (`__len__`) on the styled strings. As mentioned above, when you style a string a `colurful.colurfulString` object is returned. This object returns the length (when calling `len()`) as it would be for the *unstyled string* to integrate styled strings seemlessly into your application.

```python
>>> s = 'Hello World'
>>> len(s)
11
>>> len(cf.yellow(s))
11
>>> assert len(s) == len(cf.yellow(s))
```

### Temporarily change colurful settings

**colurful** provides a hand full of convenient context managers to change the colurful settings temporarily:

#### (1) change color mode

Use 8 ANSI colors:

```python
with cf.with_8_ansi_colors() as c:
    print(c.red('I am red'))
```

Use 256 ANSI colors:

```python
with cf.with_256_ansi_colors() as c:
    print(c.red('I am red'))
```

Use true colors:

```python
with cf.with_true_colors() as c:
    print(c.red('I am red'))
```

#### (2) change color palette

```python
# replace the entire color palette
with cf.with_palette(my_palette) as c:
    print(c.customRed('I am custom red'))

# update the color palette
with cf.with_updated_palette(my_palette) as c:
    print(c.customRed('I am custom red'))
```

#### (3) change style

```python
with cf.with_style('solarized') as c:
    print(c.red('I am solarized red'))
```

***

*<p align="center">This project is published under [MIT](LICENSE).<br>A [Timo Furrer](https://tuxtimo.me) project.<br>- :tada: -</p>*

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/",
    "name": "colurful",
    "maintainer": "Timo",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "xtimo@gmail.com",
    "keywords": "",
    "author": "Timo Furrer",
    "author_email": "xtimo@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/5e/c4/3f050944f8a2223fc11fc4ed28ebf91b2a411246ef205f1e2285005f824f/colurful-1.5.4.tar.gz",
    "platform": null,
    "description": "# colurful\r\n\r\n\r\nTerminal string styling done right, in Python :tada:\r\n\r\n## Here's a tease\r\n\r\n\r\n\r\n```python\r\nimport colurful as cf\r\n\r\n# create a colored string using clever method translation\r\nprint(cf.bold_white('Hello World'))\r\n# create a colored string using `str.format()`\r\nprint('{c.bold}{c.lightCoral_on_white}Hello World{c.reset}'.format(c=cf))\r\n\r\n# nest colors\r\nprint(cf.red('red {0} red'.format(cf.white('white'))))\r\nprint(cf.red('red' + cf.white(' white ', nested=True) + 'red'))\r\n\r\n# combine styles with strings\r\nprint(cf.bold & cf.red | 'Hello World')\r\n\r\n# use true colors\r\ncf.use_true_colors()\r\n\r\n# extend default color palette\r\ncf.update_palette({'mint': '#c5e8c8'})\r\nprint(cf.mint_on_snow('Wow, this is actually mint'))\r\n\r\n# choose a predefined style\r\ncf.use_style('solarized')\r\n# print the official solarized colors\r\nprint(cf.yellow('yellow'), cf.orange('orange'),\r\n    cf.red('red'), cf.magenta('magenta'),\r\n    cf.violet('violet'), cf.blue('blue'),\r\n    cf.cyan('cyan'), cf.green('green'))\r\n\r\n# directly print with colors\r\ncf.print('{c.bold_blue}Hello World{c.reset}')\r\n\r\n# choose specific color mode for one block\r\nwith cf.with_8_ansi_colors() as c:\r\n    print(c.bold_green('colurful is awesome!'))\r\n\r\n# create and choose your own color palette\r\nMY_COMPANY_PALETTE = {\r\n    'companyOrange': '#f4b942',\r\n    'companyBaige': '#e8dcc5'\r\n}\r\nwith cf.with_palette(MY_COMPANY_PALETTE) as c:\r\n    print(c.companyOrange_on_companyBaige('Thanks for choosing our product!'))\r\n\r\n# use f-string (only Python >= 3.6)\r\nprint(f'{cf.bold}Hello World')\r\n\r\n# support for chinese\r\nprint(cf.red('\u4f60\u597d'))\r\n```\r\n\r\n## Key Features\r\n\r\n* expressive and consistent API ([docs](#style-a-string))\r\n* support for different color modes (8 ANSI, 256 ANSI, true colors) ([docs](#color-modes))\r\n* support for predefined awesome styles (solarized, ...) ([docs](#styles))\r\n* support for custom color palettes ([docs](#color-palette))\r\n* support nesting styles ([docs](#nesting-styles))\r\n* support for different platforms (using colorama on Windows)\r\n* context managers for clean color mode, color palette or style switch ([docs](#temporarily-change-colurful-settings))\r\n* support `len()` on colored strings ([docs](#correctly-support-the-len-protocol))\r\n* support color names from [X11 rgb.txt](https://en.wikipedia.org/wiki/X11_color_names) ([docs](#1-style-a-string-with-a-method-call-colurfulmodifiers_fgcolor_on_bgcolorstr-nestedfalse))\r\n* no dependencies\r\n\r\n## Usage\r\n\r\n**colurful** supports all major Python versions: *3.5*, *3.6* and *3.7*, *3.8*, *3.9*, *3.10*, *3.11*. <br>\r\nWe recommend to use the latest version released on [PyPI](https://pypi.python.org/pypi/colurful):\r\n\r\n```bash\r\npip install colurful\r\n```\r\n\r\n**colurful** does not require any special setup in order to be used:\r\n\r\n```python\r\nimport colurful as cf\r\n\r\nprint(cf.italic_coral_on_beige('Hello World'))\r\nprint(cf.italic & cf.coral_on_beige | 'Hello World')\r\nprint('{c.italic_coral_on_beige}Hello World{c.reset}'.format(c=cf))\r\n```\r\n\r\nNote: the entire documentation assumes `colurful` to be imported as `cf`.\r\n\r\nSee the [Style a string](https://github.com/timofurrr/colurful#style-a-string) section for more information!\r\n\r\n### Color modes\r\n\r\nThese days terminals not only support the ancient 8 ANSI colors but often they support up to 16 Million colors with *[true color](https://en.wikipedia.org/wiki/Color_depth#True_color_.2824-bit.29)*. And if they don't support *true color* they might support the *[256 ANSI color palette](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors)* at least.\r\n\r\n**colurful** supports the following color modes:\r\n\r\n* no colors / disable (``cf.NO_COLORS``)\r\n* 8 colors -> 8 ANSI colors (``cf.ANSI_8_COLORS``)\r\n* 256 colors -> 256 ANSI color palette (8bit ``cf.ANSI_256_COLORS``)\r\n* 16'777'215 colors -> true color (24bit, ``cf.TRUE_COLORS``)\r\n\r\nBy default *colurful* tries to auto detect the best supported color mode by your terminal. Consult [`cf.terminal`](https://github.com/timurrer/colurful/blob/master/colurful/terminal.py) for more details.\r\n\r\nHowever, sometimes it makes sense to specify what color mode should be used.<br>\r\n**colurful** provides multiple ways to do so:\r\n\r\n#### (1) specify color mode globally via Python API\r\n\r\n```python\r\ncf.disable()\r\ncf.use_8_ansi_colors()\r\ncf.use_256_ansi_colors()\r\ncf.use_true_colors()\r\n```\r\n\r\nIf you change the color mode during runtime it takes affect immediately and globally.\r\n\r\n#### (2) enforce color mode globally via environment variable\r\n\r\n```bash\r\ncolurfulL_DISABLE=1 python eggs.py  # this process will not use ANY coloring\r\ncolurful_FORCE_8_COLORS=1 python eggs.py  # this process will use 8 ANSI colors by default\r\ncolurful_FORCE_256_COLORS=1 python eggs.py  # this process will use 256 ANSI colors by default\r\ncolurful_FORCE_TRUE_COLORS=1 python eggs.py  # this process will use true colors by default\r\n```\r\n\r\n#### (3) specify color mode locally via Python API (contextmanager)\r\n\r\n```python\r\nwith cf.with_8_ansi_colors() as c:\r\n    print(c.italic_coral_on_beige('Hello world'))\r\n\r\nwith cf.with_256_ansi_colors() as c:\r\n    print(c.italic_coral_on_beige('Hello world'))\r\n\r\nwith cf.with_true_colors() as c:\r\n    print(c.italic_coral_on_beige('Hello world'))\r\n```\r\n\r\n### colurful palette\r\n\r\n**colurful**'s Python API is based on *color names* like in `cf.bold_white_on_black('Hello')`. During runtime these *color names* are translated into proper [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code) sequences supported by the *color mode* in use. However, all *color names* are registered in a **color palette** which is basically a mapping between the *color names* and it's corresponding RGB value. Very much like this:\r\n\r\n```python\r\ncolor_palette_example = {\r\n    'black': '#000000',\r\n    'white': '#FFFFFF',\r\n}\r\n```\r\n\r\n*Note: Depending on the color mode which is used the RGB value will be reduced to fit in the value domain of the color mode.*\r\n\r\nThe default color palette is the [X11 rgb.txt](https://en.wikipedia.org/wiki/X11_color_names) palette - it's shipped with *colurful*, thus, you don't have to provide your own.\r\n*colurful* ships with a second built-in [color palette called *colornames*](https://codepen.io/meodai/full/VMpNdQ/).\r\nThose colors are from the curated list of the [color-names](https://github.com/meodai/color-names) repository.\r\nYou can use those via the `cf.setup()` method, like this:\r\n\r\n\r\n```python\r\ncf.setup(colorpalette=cf.COLORNAMES_COLORS)\r\n```\r\n\r\nIf you wish to have another color palette from a file as your default color palette you can set the `colurful_DEFAULT_COLOR_PALETTE` environment variable to this file:\r\n\r\n```bash\r\ncolurful_DEFAULT_COLOR_PALETTE=/usr/share/X11/rgb.txt python spam.py\r\n```\r\n\r\nThe file either has to be a txt file like the X11 rgb.txt or a JSON file:\r\n\r\n```json\r\n[\r\n    {\"name\": \"18th Century Green\", \"hex\":\"#a59344\"},\r\n    {\"name\": \"1975 Earth Red\", \"hex\":\"#7a463a\"}\r\n]\r\n```\r\n\r\n#### Custom color palette\r\n**colurful** supports to update or replace the default color palette with custom colors. The colors have to be specified as RGB hex or channel values:\r\n\r\n```python\r\n# corporate identity colors\r\nci_colors = {\r\n    'mint': '#c5e8c8',  # RGB hex value\r\n    'darkRed': '#c11b55',  # RGB hex value\r\n    'lightBlue': (15, 138, 191)  # RGB channel triplet\r\n}\r\n\r\n# replace the default palette with my custom one\r\ncf.use_palette(ci_colors)\r\n# update the default palette with my custom one\r\ncf.update_palette(ci_colors)\r\n\r\n# we can use these colors\r\nprint(cf.italic_mint_on_darkRed('My company'))\r\n```\r\n\r\n### Styles\r\n\r\n**colurful** supports some famous color palettes using what's called *styles* in colurful:\r\n\r\n```python\r\ncf.use_style('solarized')\r\n\r\n# print the official solarized colors\r\nprint(cf.yellow('yellow'), cf.orange('orange'),\r\n    cf.red('red'), cf.magenta('magenta'),\r\n    cf.violet('violet'), cf.blue('blue'),\r\n    cf.cyan('cyan'), cf.green('green'))\r\n```\r\n\r\nThe following styles are already supported:\r\n\r\n<details open>\r\n <summary>solarized - <a href=\"http://ethanschoonover.com/solarized\">Website</a></summary>\r\n <br>\r\n <img src=\"https://github.com/timofurrer/colurful/blob/master/examples/solarized_base_colors.png\" alt=\"solarized colors\">\r\n</details>\r\n<details open>\r\n <summary>monokai</summary>\r\n <br>\r\n <img src=\"https://github.com/timofurrer/colurful/blob/master/examples/monokai_base_colors.png\" alt=\"monokai colors\">\r\n</details>\r\n<br>\r\n\r\n*Note: if you know some awesome color palettes which could be a new style in colurful, please contribute it!*\r\n\r\n### Style a string\r\n\r\n**colurful** provides multiple ways to use style a string. Most useful and expressive is probably the *method syntax* where you specify the modifiers and colors in the method name itself and pass the string as argument to this method. However, you can use all the following methods to achive similars things:\r\n\r\n#### (1) Style a string with a method call `cf.[<modifiers...>]_[<fgColor>]_[on_<bgColor>](str, nested=False)`\r\n\r\n```python\r\nprint(cf.red('I am red'))\r\nprint(cf.italic_yellow('I am italic and yellow'))\r\nprint(cf.black_on_white('I am black on white'))\r\n```\r\n\r\nThe method syntax can be one of:\r\n\r\n* `cf.<modifier>`\r\n* `cf.<modifier1>_<modifier2>`\r\n* `cf.<fg_color>`\r\n* `cf.on_<bg_color>`\r\n* `cf.<modifiers>_<fg_color>`\r\n* `cf.<modifiers>_<bg_color>`\r\n* `cf.<fg_colors>_on_<bg_color>`\r\n* `cf.<modifiers>_<fg_color>_on_<bg_color>`\r\n\r\n*Note that multiple `<modifier>`s can be specified at once.*\r\n\r\nAvailable modifiers are:\r\n\r\n* reset (explicitely reset all styles before the passed argument)\r\n* bold\r\n* dimmed (not widely supported)\r\n* italic\r\n* underlined\r\n* blinkslow\r\n* blinkrapid\r\n* inversed (not widely supported)\r\n* concealed (not widely supported)\r\n* struckthrough\r\n\r\nThe available colors depend on the [color palette](#color-palette) you are using. By default all [X11 rgb.txt colors](https://en.wikipedia.org/wiki/X11_color_names) are available.\r\n\r\nThe type of the return value of such a *style method* is `colurful.colurfulString`. It correctly supports all `str()` methods including [`len()`](#correctly-support-the-len-protocol).\r\n\r\nAs you can see from the syntax in the section name, **colurful** supports nesting styles. See [Nesting styles](#nesting-styles).\r\n\r\n#### (2) Style a string with `&` and `|`\r\n\r\n**colurful** implements the `__or__` and `__and__` protocol to combine styles and pipe strings into them:\r\n\r\n```python\r\nprint(cf.bold & cf.red | 'Hello World')\r\nprint(cf.bold_red_on_black | 'Hello World')\r\nprint(cf.bold | cf.red_on_black('Hello World')\r\n```\r\n\r\n*Note: the piping `|` has the same effect as doing a method call to the style.<br>\r\nSo you could do `(cf.bold & cf.red)('Hello World')`*\r\n\r\n#### (3) Style a string with `cf.format(string, *args, **kwargs)`\r\n\r\n```python\r\nprint(cf.format('{c.red}I am {what}{c.close_fg_color}', what='red'))\r\n# alternatively to ``c.close_fg_color`` you can reset every style with ``c.reset``\r\nprint(cf.format('{c.red}I am red{c.reset}'))\r\n\r\nprint(cf.format('{c.italic_yellow}I am italic and yellow{c.no_italic}{c.close_fg_color}'))\r\nprint(cf.format('{c.black_on_white}I am black on white{c.close_fg_color}{c.close_bg_color}'))\r\n```\r\n\r\n**colurful** will replace the `{c.<style>}` with the correspnding style. It's **not** necessary to pass a colurful object for `c` to `format()` - colurful will handle that. Every other format argument (`{<name>}`) has to be pass to the `cf.format()` call as *args* or *kwarg*.\r\n\r\nNote: The same syntax, modifiers and colors for the style in `{c.<style>}` can be used as for [(1) Style a string with a method call](#1-style-a-string-with-a-method-call).\r\n\r\n#### (4) Style and print a string with `cf.print(*strings, sep=' ', end='\\n', file=sys.stdout, flush=False)`\r\n\r\n```python\r\ncf.print('{c.italic_yellow}I am italic and yellow{c.no_italic}{c.close_fg_color}')\r\ncf.print('{c.red}I am red{c.reset}', end='', file=open('log.txt', 'a+'))\r\n```\r\n\r\nThe `cf.print()` method accepts the same arguments as the Python 3.X [built-in print()](https://docs.python.org/3/library/functions.html#print) function.\r\n\r\n#### (5) Style a string with [`str.format()`](https://docs.python.org/3.6/library/stdtypes.html#str.format)\r\n\r\n```python\r\nprint('{c.red}I am red{c.close_fg_color}'.format(c=cf))\r\n# alternatively to ``c.close_fg_color`` you can reset every style with ``c.reset``\r\nprint('{c.red}I am red{c.reset}'.format(c=cf))\r\n\r\nprint('{c.italic_yellow}I am italic and yellow{c.no_italic}{c.close_fg_color}'.format(\r\n    c=cf))\r\nprint('{c.black_on_white}I am black on white{c.close_fg_color}{c.close_bg_color}'.format(\r\n    c=cf))\r\n```\r\n\r\nNote: The same syntax, modifiers and colors for the style in `{c.<style>}` can be used as for [(1) Style a string with a method call](#1-style-a-string-with-a-method-call).\r\n\r\n#### Nesting styles\r\n\r\n**colurful** supports to nest styles with it's [method call syntax](#1-style-a-string-with-a-method-call) when setting the parameter `nested` to `True`.\r\nIf you are using `str.format()` like in the first example below you don't even need the `nested=True` flag!\r\n\r\nThe following examples show the behavior:\r\n\r\n```python\r\nprint(cf.red('red {0} red'.format(cf.white('white'))))\r\nprint(cf.red('red' + cf.white(' white ', nested=True) + 'red'))\r\n\r\n# if using ``nested=True`` but you don't actually nest\r\n# it's absolutely fine and will work as expected.\r\nprint(cf.red('red', nested=True) + ' default color')\r\n```\r\n\r\n#### Correctly support the [`len()` protocol](https://docs.python.org/3/library/functions.html#len)\r\n\r\n**colurful** correctly supports the `len()` protocol (`__len__`) on the styled strings. As mentioned above, when you style a string a `colurful.colurfulString` object is returned. This object returns the length (when calling `len()`) as it would be for the *unstyled string* to integrate styled strings seemlessly into your application.\r\n\r\n```python\r\n>>> s = 'Hello World'\r\n>>> len(s)\r\n11\r\n>>> len(cf.yellow(s))\r\n11\r\n>>> assert len(s) == len(cf.yellow(s))\r\n```\r\n\r\n### Temporarily change colurful settings\r\n\r\n**colurful** provides a hand full of convenient context managers to change the colurful settings temporarily:\r\n\r\n#### (1) change color mode\r\n\r\nUse 8 ANSI colors:\r\n\r\n```python\r\nwith cf.with_8_ansi_colors() as c:\r\n    print(c.red('I am red'))\r\n```\r\n\r\nUse 256 ANSI colors:\r\n\r\n```python\r\nwith cf.with_256_ansi_colors() as c:\r\n    print(c.red('I am red'))\r\n```\r\n\r\nUse true colors:\r\n\r\n```python\r\nwith cf.with_true_colors() as c:\r\n    print(c.red('I am red'))\r\n```\r\n\r\n#### (2) change color palette\r\n\r\n```python\r\n# replace the entire color palette\r\nwith cf.with_palette(my_palette) as c:\r\n    print(c.customRed('I am custom red'))\r\n\r\n# update the color palette\r\nwith cf.with_updated_palette(my_palette) as c:\r\n    print(c.customRed('I am custom red'))\r\n```\r\n\r\n#### (3) change style\r\n\r\n```python\r\nwith cf.with_style('solarized') as c:\r\n    print(c.red('I am solarized red'))\r\n```\r\n\r\n***\r\n\r\n*<p align=\"center\">This project is published under [MIT](LICENSE).<br>A [Timo Furrer](https://tuxtimo.me) project.<br>- :tada: -</p>*\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Terminal string styling done right, in Python.",
    "version": "1.5.4",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "234ec336591c2d87b9d3ecc0d9b8e190871443fe7fb2f488f29b845e3257e58f",
                "md5": "3b13cbc957991fa0452e19ef781071a8",
                "sha256": "a1610f20f31e1d1f9cc5f6c515bd80e09cbe300804b6b24d9b359954f0642387"
            },
            "downloads": -1,
            "filename": "colurful-1.5.4-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3b13cbc957991fa0452e19ef781071a8",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 202321,
            "upload_time": "2023-02-10T12:40:59",
            "upload_time_iso_8601": "2023-02-10T12:40:59.415795Z",
            "url": "https://files.pythonhosted.org/packages/23/4e/c336591c2d87b9d3ecc0d9b8e190871443fe7fb2f488f29b845e3257e58f/colurful-1.5.4-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5ec43f050944f8a2223fc11fc4ed28ebf91b2a411246ef205f1e2285005f824f",
                "md5": "11996db1b4a4fb3a4d9f90be1eff9bc9",
                "sha256": "31b3cfdc5e8b83cf5318d762730cab1bccd02f7fa07790b6b19914b212259b2b"
            },
            "downloads": -1,
            "filename": "colurful-1.5.4.tar.gz",
            "has_sig": false,
            "md5_digest": "11996db1b4a4fb3a4d9f90be1eff9bc9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 204087,
            "upload_time": "2023-02-10T12:41:03",
            "upload_time_iso_8601": "2023-02-10T12:41:03.339596Z",
            "url": "https://files.pythonhosted.org/packages/5e/c4/3f050944f8a2223fc11fc4ed28ebf91b2a411246ef205f1e2285005f824f/colurful-1.5.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-10 12:41:03",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "colurful"
}
        
Elapsed time: 0.04096s