<h1 align="center">
<br>
<br>
<img width="320" src="https://raw.githubusercontent.com/bluenote10/yachalk/master/media/logo.png" alt="Chalk">
<br>
<br>
<br>
</h1>
> Terminal string styling done right
This is a feature-complete clone of the awesome [Chalk](https://github.com/chalk/chalk) (JavaScript) library.
All **credits go to [Sindre Sorhus](https://github.com/sindresorhus)**.
[![PyPI version](https://badge.fury.io/py/yachalk.svg)](https://badge.fury.io/py/yachalk)
[![Build Status](https://github.com/bluenote10/yachalk/workflows/ci/badge.svg)](https://github.com/bluenote10/yachalk/actions?query=workflow%3Aci)
[![codecov](https://codecov.io/gh/bluenote10/yachalk/branch/master/graph/badge.svg?token=6I98R2661Z)](https://codecov.io/gh/bluenote10/yachalk)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![mypy](https://img.shields.io/badge/mypy-strict-blue)](http://mypy-lang.org/)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE)
<img src="https://raw.githubusercontent.com/bluenote10/yachalk/master/media/demo1.svg" width="900">
<br>
---
<br>
## Highlights
- Fluent, auto-complete-friendly API for maximum coding efficiency
- Ability to nest styles
- Proper handling of styling edge cases (same test cases as Chalk)
- Auto-detection of terminal color capabilities
- [256/Truecolor color support](#256-and-truecolor-color-support), with fallback to basic colors depending on capabilities
- Same conventions as Chalk to manually control color modes via `FORCE_COLOR`
- No dependencies
- Fully typed (mypy strict), no stubs required
## Install
```console
$ pip install yachalk
```
The only requirement is a modern Python (3.6+).
## Usage
```python
from yachalk import chalk
print(chalk.blue("Hello world!"))
```
Chalk comes with an easy to use composable API where you just chain and nest the styles you want.
```python
from yachalk import chalk
# Combine styled and normal strings
print(chalk.blue("Hello") + " World" + chalk.red("!"))
# Compose multiple styles using the chainable API
print(chalk.blue.bg_red.bold("Hello world!"))
# Use within f-strings
num_results = 12345
print(f"Found {chalk.bold(num_results)} results.")
# Pass in multiple arguments
print(chalk.blue("Hello", "World!"))
# Nest styles...
print(chalk.red(f"Hello {chalk.underline.bg_blue('world')}!"))
# Nest styles of the same type even (color, underline, background)
print(chalk.green(
"I am a green line " +
chalk.blue.underline.bold("with a blue substring") +
" that becomes green again!"
))
# Use RGB or HEX colors
print(chalk.rgb(123, 45, 67).underline("Underlined reddish color"))
print(chalk.hex("#DEADED").bold("Bold gray!"))
```
Easily define and re-use your own themes:
```python
from yachalk import chalk
error = chalk.bold.red
warning = chalk.hex("#FFA500")
print(error("Error!"))
print(warning("Warning!"))
```
## Prior art: Why yet another chalk clone?
The Python ecosystem has a large number libraries for terminal styling/coloring. However, after working with Chalk in JavaScript for a while, I always missed to have the same convenience in Python. Inspired by Chalk, I wanted to have a terminal styling library satisfying the following design criteria:
- **Automatic reset handling**: Many Python libraries require manual handling of ANSI reset codes. This is error prone, and a common source of coloring issues. It also means that these libraries cannot handle advanced edge cases like proper handling of newlines in all contexts, because that requires internal reset handling.
- **Single symbol import**: Some libraries require to import special symbols for foreground/background/modifiers/... depending on the desired styling. This is tedious in my opinion, because you have to adapt the imports all the time when you change the particular styling.
- **Auto-complete friendly**: I don't want to memorize a style/color API, I'd like to have full auto-complete support. Some existing Chalk clones seem to generate all style properties dynamically, which means that an IDE cannot support with auto-completion.
- **Support of nested styles**: Sometimes it is convenient to embed a style into an existing styled context. With Chalk this simply works. None of the libraries I tried have support of nested styles.
- **Support of edge cases**: Chalk has solutions for many edge cases like newline handling, or certain challenges in nested styles. The Python libraries I tried didn't support these. Yachalk is tested against the same test cases as Chalk, so it should support them all.
- **Not print focused**: Some libraries provide an API with a focus on offering modified `print` functions. I prefer the single responsibility principle: Styling should only do styling, and return a string. This still leaves the possibility to print the string, write it to a file, or pass it around freely.
- **True color support**: Today most terminal have true color support, so it makes sense to support it in the API. Many older Python libraries only support the basic 16 colors.
- **Capabilities auto detection / fallbacks**: Chalk is fully backwards compatible on dumber terminals, by approximating colors with what is available on a particular terminal. I haven't found this feature in existing Python libraries.
- **Zero dependencies**: Some libraries are based e.g. based on curses, which is a heavy dependency for something as simple as styling/coloring.
- **Fully typed**: I like optional typing, but often library type stubs come with bad types. Yachalk runs in strict mypy mode, which means that no stubs are needed and its type should be correct by design.
I started collecting existing libraries in a feature matrix, but since I keep finding more and more libraries, I've given up on filling it completely 😉. Nonetheless, feel free to open an issue if it contains an error or misses an important solution.
![comparison](https://raw.githubusercontent.com/bluenote10/yachalk/master/media/comparison.png)
Links to related projects:
- [termcolor](https://pypi.org/project/termcolor/)
- [colored](https://gitlab.com/dslackw/colored)
- [ansicolors](https://pypi.org/project/ansicolors/)
- [sty](https://github.com/feluxe/sty)
- [blessings](https://github.com/erikrose/blessings)
- [rich](https://github.com/willmcgugan/rich)
- [style (clr)](https://github.com/lmittmann/style)
- [pychalk](https://github.com/anthonyalmarza/chalk)
- [simple_chalk](https://pypi.org/project/simple-chalk/)
## API
In general there is no need to remember the API, because it is written in a way that it fully auto-completes in common IDEs:
![auto_complete](https://raw.githubusercontent.com/bluenote10/yachalk/master/media/auto_complete.gif)
**`chalk.<style>[.<style>...](string, [string...], sep=" ")`**
Example: `chalk.red.bold.underline("Hello", "world")`
Chain [styles](#styles) and call the last one as a method with a string argument. Order doesn't matter, and later styles take precedent in case of a conflict. This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
Multiple arguments will be separated by a space, but the separator can also be passed in as keyword argument `sep="..."`.
**`chalk.set_color_mode(mode: ColorMode)`**
Set the color mode manually. `ColorMode` is an enum with the value:
- `ColorMode.AllOff`
- `ColorMode.Basic16` (basic 16-color ANSI colors)
- `ColorMode.Extended256` (256-color ANSI color mode)
- `ColorMode.FullTrueColor` (full true color support)
See [color mode control](#color-mode-control) for more details.
**`chalk.disable_all_ansi()`**
Shorthand for `chalk.set_color_mode(ColorMode.AllOff)`.
**`chalk.enable_basic_colors()`**
Shorthand for `chalk.set_color_mode(ColorMode.Basic16)`.
**`chalk.enable_extended_colors()`**
Shorthand for `chalk.set_color_mode(ColorMode.Extended256)`.
**`chalk.enable_full_colors()`**
Shorthand for `chalk.set_color_mode(ColorMode.FullTrueColor)`.
**`chalk.get_color_mode() -> ColorMode`**
Return current color mode.
## Styles
### Modifiers
- `reset` - Resets the current color chain.
- `bold` - Make text bold.
- `dim` - Emitting only a small amount of light.
- `italic` - Make text italic. *(Not widely supported)*
- `underline` - Make text underline. *(Not widely supported)*
- `inverse`- Invert background and foreground colors.
- `hidden` - Prints the text, but makes it invisible.
- `strikethrough` - Puts a horizontal line through the center of the text. *(Not widely supported)*
- `visible`- Prints the text only when Chalk has a color level > 0. Can be useful for things that are purely cosmetic.
### Colors
- `black`
- `red`
- `green`
- `yellow`
- `blue`
- `magenta`
- `cyan`
- `white`
- `black_bright` (alias: `gray`, `grey`)
- `red_bright`
- `green_bright`
- `yellow_bright`
- `blue_bright`
- `magenta_bright`
- `cyan_bright`
- `white_bright`
### Background colors
- `bg_black`
- `bg_red`
- `bg_green`
- `bg_yellow`
- `bg_blue`
- `bg_magenta`
- `bg_cyan`
- `bg_white`
- `bg_black_bright` (alias: `bg_gray`, `bg_grey`)
- `bg_red_bright`
- `bg_green_bright`
- `bg_yellow_bright`
- `bg_blue_bright`
- `bg_magenta_bright`
- `bg_cyan_bright`
- `bg_white_bright`
## 256 and Truecolor color support
Chalk supports 256 colors and [Truecolor](https://gist.github.com/XVilka/8346728) (16 million colors) on supported terminal apps.
Colors are downsampled from 16 million RGB values to an ANSI color format that is supported by the terminal emulator (or by setting a specific `ColorMode` manually). For example, Chalk configured to run at level `ColorMode.Basic16` will downsample an RGB value of #FF0000 (red) to 31 (ANSI escape for red).
Examples:
- `chalk.rgb(15, 100, 204)("Hello!")`
- `chalk.hex("#DEADED").underline("Hello, world!")`
Background versions of these models are prefixed with `bg_`:
- `chalk.bg_rgb(15, 100, 204)("Hello!")`
- `chalk.bg_hex("#DEADED").underline("Hello, world!")`
## Color mode control
The imported symbol `chalk` is a singleton that is initialized with the color mode resulting from the auto-detection. This means that if you run on a terminal that has e.g. only basic 16 colors support, you can still use the full RGB/HEX API, but the resulting colors would be approximated by the available colors. If the terminal doesn't support any ANSI escape codes, the resulting strings would be completely free of any ANSI codes.
If you would like to take manual control of the color mode, you have three options.
**1. Use environment variables**
Chalk has introduced the convention to use the `FORCE_COLOR` environment variable as an override in the auto-detection. The semantics are:
- `FORCE_COLOR=0` enforces `ColorMode.AllOff`.
- `FORCE_COLOR=1` enforces `ColorMode.Basic16`.
- `FORCE_COLOR=2` enforces `ColorMode.Extended256`.
- `FORCE_COLOR=3` enforces `ColorMode.FullTrueColor`.
This can be a convenient solution in CI/cloud-based contexts.
**2. Set the color mode manually on the `chalk` instance**
If you don't care about auto-detection, you might as well set your desired color mode unconditionally.
The `chalk` singleton supports setting the color mode via `chalk.disable_all_ansi`, `chalk.enable_..._colors`, or `chalk.set_color_mode`.
A reasonable place to configure the singleton is e.g. at the beginning of a `main` function, similar to where logging is configured.
**3. Use your own `chalk` instance**
For advanced use cases that e.g. require to dynamically switch the color mode in a multi-threaded context, you can opt-out of the convenience of using a singleton, and use a custom `chalk` instances where desired. In general `chalk` is just an instance of `ChalkFactory`, which takes the color mode as input in its constructor.
```python
from yachalk import ChalkFactory
def some_function():
# create your own chalk instance with explicit mode control
chalk = ChalkFactory(ColorMode.FullTrueColor)
# ...
colored_messages.append(chalk.red("An error occurred"))
```
Or if you'd like to use your own mode-detection logic, you could create the `chalk` singleton yourself in one of your modules
```python
# e.g. in my_chalk.py
from yachalk import ChalkFactory
def custom_color_mode_detection() -> ColorMode:
# ...
return ColorMode.Basic16
chalk = ChalkFactory(custom_color_mode_detection())
```
and replace usages of `from yachalk import chalk` with `from my_chalk import chalk`.
Raw data
{
"_id": null,
"home_page": "https://github.com/bluenote10/yachalk",
"name": "yachalk",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "terminal, color, styling, ansi",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/f4/37/cbfa9a25573c925be932a7878102a262800648a1cf2a07e3e86f076f240d/yachalk-0.1.6.tar.gz",
"platform": null,
"description": "<h1 align=\"center\">\n\t<br>\n\t<br>\n\t<img width=\"320\" src=\"https://raw.githubusercontent.com/bluenote10/yachalk/master/media/logo.png\" alt=\"Chalk\">\n\t<br>\n\t<br>\n\t<br>\n</h1>\n\n> Terminal string styling done right\n\nThis is a feature-complete clone of the awesome [Chalk](https://github.com/chalk/chalk) (JavaScript) library.\n\nAll **credits go to [Sindre Sorhus](https://github.com/sindresorhus)**.\n\n[![PyPI version](https://badge.fury.io/py/yachalk.svg)](https://badge.fury.io/py/yachalk)\n[![Build Status](https://github.com/bluenote10/yachalk/workflows/ci/badge.svg)](https://github.com/bluenote10/yachalk/actions?query=workflow%3Aci)\n[![codecov](https://codecov.io/gh/bluenote10/yachalk/branch/master/graph/badge.svg?token=6I98R2661Z)](https://codecov.io/gh/bluenote10/yachalk)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![mypy](https://img.shields.io/badge/mypy-strict-blue)](http://mypy-lang.org/)\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE)\n\n\n<img src=\"https://raw.githubusercontent.com/bluenote10/yachalk/master/media/demo1.svg\" width=\"900\">\n\n<br>\n\n---\n\n<br>\n\n## Highlights\n\n- Fluent, auto-complete-friendly API for maximum coding efficiency\n- Ability to nest styles\n- Proper handling of styling edge cases (same test cases as Chalk)\n- Auto-detection of terminal color capabilities\n- [256/Truecolor color support](#256-and-truecolor-color-support), with fallback to basic colors depending on capabilities\n- Same conventions as Chalk to manually control color modes via `FORCE_COLOR`\n- No dependencies\n- Fully typed (mypy strict), no stubs required\n\n\n## Install\n\n```console\n$ pip install yachalk\n```\n\nThe only requirement is a modern Python (3.6+).\n\n## Usage\n\n```python\nfrom yachalk import chalk\n\nprint(chalk.blue(\"Hello world!\"))\n```\n\nChalk comes with an easy to use composable API where you just chain and nest the styles you want.\n\n```python\nfrom yachalk import chalk\n\n# Combine styled and normal strings\nprint(chalk.blue(\"Hello\") + \" World\" + chalk.red(\"!\"))\n\n# Compose multiple styles using the chainable API\nprint(chalk.blue.bg_red.bold(\"Hello world!\"))\n\n# Use within f-strings\nnum_results = 12345\nprint(f\"Found {chalk.bold(num_results)} results.\")\n\n# Pass in multiple arguments\nprint(chalk.blue(\"Hello\", \"World!\"))\n\n# Nest styles...\nprint(chalk.red(f\"Hello {chalk.underline.bg_blue('world')}!\"))\n\n# Nest styles of the same type even (color, underline, background)\nprint(chalk.green(\n \"I am a green line \" +\n chalk.blue.underline.bold(\"with a blue substring\") +\n \" that becomes green again!\"\n))\n\n# Use RGB or HEX colors\nprint(chalk.rgb(123, 45, 67).underline(\"Underlined reddish color\"))\nprint(chalk.hex(\"#DEADED\").bold(\"Bold gray!\"))\n```\n\nEasily define and re-use your own themes:\n\n```python\nfrom yachalk import chalk\n\nerror = chalk.bold.red\nwarning = chalk.hex(\"#FFA500\")\n\nprint(error(\"Error!\"))\nprint(warning(\"Warning!\"))\n```\n\n\n## Prior art: Why yet another chalk clone?\n\nThe Python ecosystem has a large number libraries for terminal styling/coloring. However, after working with Chalk in JavaScript for a while, I always missed to have the same convenience in Python. Inspired by Chalk, I wanted to have a terminal styling library satisfying the following design criteria:\n\n- **Automatic reset handling**: Many Python libraries require manual handling of ANSI reset codes. This is error prone, and a common source of coloring issues. It also means that these libraries cannot handle advanced edge cases like proper handling of newlines in all contexts, because that requires internal reset handling.\n- **Single symbol import**: Some libraries require to import special symbols for foreground/background/modifiers/... depending on the desired styling. This is tedious in my opinion, because you have to adapt the imports all the time when you change the particular styling.\n- **Auto-complete friendly**: I don't want to memorize a style/color API, I'd like to have full auto-complete support. Some existing Chalk clones seem to generate all style properties dynamically, which means that an IDE cannot support with auto-completion.\n- **Support of nested styles**: Sometimes it is convenient to embed a style into an existing styled context. With Chalk this simply works. None of the libraries I tried have support of nested styles.\n- **Support of edge cases**: Chalk has solutions for many edge cases like newline handling, or certain challenges in nested styles. The Python libraries I tried didn't support these. Yachalk is tested against the same test cases as Chalk, so it should support them all.\n- **Not print focused**: Some libraries provide an API with a focus on offering modified `print` functions. I prefer the single responsibility principle: Styling should only do styling, and return a string. This still leaves the possibility to print the string, write it to a file, or pass it around freely.\n- **True color support**: Today most terminal have true color support, so it makes sense to support it in the API. Many older Python libraries only support the basic 16 colors.\n- **Capabilities auto detection / fallbacks**: Chalk is fully backwards compatible on dumber terminals, by approximating colors with what is available on a particular terminal. I haven't found this feature in existing Python libraries.\n- **Zero dependencies**: Some libraries are based e.g. based on curses, which is a heavy dependency for something as simple as styling/coloring.\n- **Fully typed**: I like optional typing, but often library type stubs come with bad types. Yachalk runs in strict mypy mode, which means that no stubs are needed and its type should be correct by design.\n\nI started collecting existing libraries in a feature matrix, but since I keep finding more and more libraries, I've given up on filling it completely \ud83d\ude09. Nonetheless, feel free to open an issue if it contains an error or misses an important solution.\n\n![comparison](https://raw.githubusercontent.com/bluenote10/yachalk/master/media/comparison.png)\n\nLinks to related projects:\n- [termcolor](https://pypi.org/project/termcolor/)\n- [colored](https://gitlab.com/dslackw/colored)\n- [ansicolors](https://pypi.org/project/ansicolors/)\n- [sty](https://github.com/feluxe/sty)\n- [blessings](https://github.com/erikrose/blessings)\n- [rich](https://github.com/willmcgugan/rich)\n- [style (clr)](https://github.com/lmittmann/style)\n- [pychalk](https://github.com/anthonyalmarza/chalk)\n- [simple_chalk](https://pypi.org/project/simple-chalk/)\n\n\n## API\n\nIn general there is no need to remember the API, because it is written in a way that it fully auto-completes in common IDEs:\n\n![auto_complete](https://raw.githubusercontent.com/bluenote10/yachalk/master/media/auto_complete.gif)\n\n**`chalk.<style>[.<style>...](string, [string...], sep=\" \")`**\n\nExample: `chalk.red.bold.underline(\"Hello\", \"world\")`\n\nChain [styles](#styles) and call the last one as a method with a string argument. Order doesn't matter, and later styles take precedent in case of a conflict. This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.\n\nMultiple arguments will be separated by a space, but the separator can also be passed in as keyword argument `sep=\"...\"`.\n\n\n**`chalk.set_color_mode(mode: ColorMode)`**\n\nSet the color mode manually. `ColorMode` is an enum with the value:\n\n- `ColorMode.AllOff`\n- `ColorMode.Basic16` (basic 16-color ANSI colors)\n- `ColorMode.Extended256` (256-color ANSI color mode)\n- `ColorMode.FullTrueColor` (full true color support)\n\nSee [color mode control](#color-mode-control) for more details.\n\n**`chalk.disable_all_ansi()`**\n\nShorthand for `chalk.set_color_mode(ColorMode.AllOff)`.\n\n**`chalk.enable_basic_colors()`**\n\nShorthand for `chalk.set_color_mode(ColorMode.Basic16)`.\n\n**`chalk.enable_extended_colors()`**\n\nShorthand for `chalk.set_color_mode(ColorMode.Extended256)`.\n\n**`chalk.enable_full_colors()`**\n\nShorthand for `chalk.set_color_mode(ColorMode.FullTrueColor)`.\n\n**`chalk.get_color_mode() -> ColorMode`**\n\nReturn current color mode.\n\n\n## Styles\n\n### Modifiers\n\n- `reset` - Resets the current color chain.\n- `bold` - Make text bold.\n- `dim` - Emitting only a small amount of light.\n- `italic` - Make text italic. *(Not widely supported)*\n- `underline` - Make text underline. *(Not widely supported)*\n- `inverse`- Invert background and foreground colors.\n- `hidden` - Prints the text, but makes it invisible.\n- `strikethrough` - Puts a horizontal line through the center of the text. *(Not widely supported)*\n- `visible`- Prints the text only when Chalk has a color level > 0. Can be useful for things that are purely cosmetic.\n\n### Colors\n\n- `black`\n- `red`\n- `green`\n- `yellow`\n- `blue`\n- `magenta`\n- `cyan`\n- `white`\n- `black_bright` (alias: `gray`, `grey`)\n- `red_bright`\n- `green_bright`\n- `yellow_bright`\n- `blue_bright`\n- `magenta_bright`\n- `cyan_bright`\n- `white_bright`\n\n### Background colors\n\n- `bg_black`\n- `bg_red`\n- `bg_green`\n- `bg_yellow`\n- `bg_blue`\n- `bg_magenta`\n- `bg_cyan`\n- `bg_white`\n- `bg_black_bright` (alias: `bg_gray`, `bg_grey`)\n- `bg_red_bright`\n- `bg_green_bright`\n- `bg_yellow_bright`\n- `bg_blue_bright`\n- `bg_magenta_bright`\n- `bg_cyan_bright`\n- `bg_white_bright`\n\n\n## 256 and Truecolor color support\n\nChalk supports 256 colors and [Truecolor](https://gist.github.com/XVilka/8346728) (16 million colors) on supported terminal apps.\n\nColors are downsampled from 16 million RGB values to an ANSI color format that is supported by the terminal emulator (or by setting a specific `ColorMode` manually). For example, Chalk configured to run at level `ColorMode.Basic16` will downsample an RGB value of #FF0000 (red) to 31 (ANSI escape for red).\n\nExamples:\n\n- `chalk.rgb(15, 100, 204)(\"Hello!\")`\n- `chalk.hex(\"#DEADED\").underline(\"Hello, world!\")`\n\nBackground versions of these models are prefixed with `bg_`:\n\n- `chalk.bg_rgb(15, 100, 204)(\"Hello!\")`\n- `chalk.bg_hex(\"#DEADED\").underline(\"Hello, world!\")`\n\n\n## Color mode control\n\nThe imported symbol `chalk` is a singleton that is initialized with the color mode resulting from the auto-detection. This means that if you run on a terminal that has e.g. only basic 16 colors support, you can still use the full RGB/HEX API, but the resulting colors would be approximated by the available colors. If the terminal doesn't support any ANSI escape codes, the resulting strings would be completely free of any ANSI codes.\n\nIf you would like to take manual control of the color mode, you have three options.\n\n**1. Use environment variables**\n\nChalk has introduced the convention to use the `FORCE_COLOR` environment variable as an override in the auto-detection. The semantics are:\n\n- `FORCE_COLOR=0` enforces `ColorMode.AllOff`.\n- `FORCE_COLOR=1` enforces `ColorMode.Basic16`.\n- `FORCE_COLOR=2` enforces `ColorMode.Extended256`.\n- `FORCE_COLOR=3` enforces `ColorMode.FullTrueColor`.\n\nThis can be a convenient solution in CI/cloud-based contexts.\n\n\n**2. Set the color mode manually on the `chalk` instance**\n\nIf you don't care about auto-detection, you might as well set your desired color mode unconditionally.\n\nThe `chalk` singleton supports setting the color mode via `chalk.disable_all_ansi`, `chalk.enable_..._colors`, or `chalk.set_color_mode`.\n\nA reasonable place to configure the singleton is e.g. at the beginning of a `main` function, similar to where logging is configured.\n\n\n**3. Use your own `chalk` instance**\n\nFor advanced use cases that e.g. require to dynamically switch the color mode in a multi-threaded context, you can opt-out of the convenience of using a singleton, and use a custom `chalk` instances where desired. In general `chalk` is just an instance of `ChalkFactory`, which takes the color mode as input in its constructor.\n\n\n```python\nfrom yachalk import ChalkFactory\n\ndef some_function():\n # create your own chalk instance with explicit mode control\n chalk = ChalkFactory(ColorMode.FullTrueColor)\n\n # ...\n\n colored_messages.append(chalk.red(\"An error occurred\"))\n```\n\nOr if you'd like to use your own mode-detection logic, you could create the `chalk` singleton yourself in one of your modules\n\n```python\n# e.g. in my_chalk.py\nfrom yachalk import ChalkFactory\n\ndef custom_color_mode_detection() -> ColorMode:\n # ...\n return ColorMode.Basic16\n\nchalk = ChalkFactory(custom_color_mode_detection())\n```\n\nand replace usages of `from yachalk import chalk` with `from my_chalk import chalk`.\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "\ud83d\udd8d\ufe0f Terminal string styling done right",
"version": "0.1.6",
"project_urls": {
"Homepage": "https://github.com/bluenote10/yachalk"
},
"split_keywords": [
"terminal",
" color",
" styling",
" ansi"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "46ece71b3dcd37ed289e3a9d9986b31e22acf3c1328e42c2d3b61b603c362975",
"md5": "af07fa609eb390ee154b946bec2e8e38",
"sha256": "de80c1cd28fc3f7719345d3eecff88c9e18100d65bedf3b66b88c227aac95e54"
},
"downloads": -1,
"filename": "yachalk-0.1.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "af07fa609eb390ee154b946bec2e8e38",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 13850,
"upload_time": "2024-07-10T22:07:38",
"upload_time_iso_8601": "2024-07-10T22:07:38.451770Z",
"url": "https://files.pythonhosted.org/packages/46/ec/e71b3dcd37ed289e3a9d9986b31e22acf3c1328e42c2d3b61b603c362975/yachalk-0.1.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f437cbfa9a25573c925be932a7878102a262800648a1cf2a07e3e86f076f240d",
"md5": "b6bfe1e611c66f08672ad7abd88d037b",
"sha256": "ee917e41c127a2302526aa169c6032f1505fab5a1045bd7a0c320b0194e8d992"
},
"downloads": -1,
"filename": "yachalk-0.1.6.tar.gz",
"has_sig": false,
"md5_digest": "b6bfe1e611c66f08672ad7abd88d037b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 17964,
"upload_time": "2024-07-10T22:07:40",
"upload_time_iso_8601": "2024-07-10T22:07:40.017425Z",
"url": "https://files.pythonhosted.org/packages/f4/37/cbfa9a25573c925be932a7878102a262800648a1cf2a07e3e86f076f240d/yachalk-0.1.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-10 22:07:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "bluenote10",
"github_project": "yachalk",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "yachalk"
}