{"id":15297497,"url":"https://github.com/welbornprod/colr","last_synced_at":"2025-04-13T22:36:16.173Z","repository":{"id":36703316,"uuid":"41009853","full_name":"welbornprod/colr","owner":"welbornprod","description":"Easy terminal colors, with chainable methods.","archived":false,"fork":false,"pushed_at":"2023-08-01T01:11:58.000Z","size":2229,"stargazers_count":36,"open_issues_count":2,"forks_count":7,"subscribers_count":4,"default_branch":"dev","last_synced_at":"2025-03-27T12:52:33.309Z","etag":null,"topics":["256-colors","ansi-colors","ansi-escape-codes","chainable-methods","color","colr","escape-codes","gradient","library","python-3","terminal","true-color"],"latest_commit_sha":null,"homepage":"http://pypi.python.org/pypi/Colr/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/welbornprod.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.txt","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-19T02:55:13.000Z","updated_at":"2024-10-10T10:19:19.000Z","dependencies_parsed_at":"2024-06-19T00:20:25.314Z","dependency_job_id":"293d39b7-9127-494f-a84c-009fee6eca1c","html_url":"https://github.com/welbornprod/colr","commit_stats":{"total_commits":287,"total_committers":4,"mean_commits":71.75,"dds":"0.013937282229965153","last_synced_commit":"72913aca7fcb19bf1a7f1c34dd820e40459143a4"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welbornprod%2Fcolr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welbornprod%2Fcolr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welbornprod%2Fcolr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welbornprod%2Fcolr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/welbornprod","download_url":"https://codeload.github.com/welbornprod/colr/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248792205,"owners_count":21162331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["256-colors","ansi-colors","ansi-escape-codes","chainable-methods","color","colr","escape-codes","gradient","library","python-3","terminal","true-color"],"created_at":"2024-09-30T19:17:51.228Z","updated_at":"2025-04-13T22:36:16.120Z","avatar_url":"https://github.com/welbornprod.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Colr\n\nA python module for using terminal colors. It contains a simple\n`color` function that accepts style and color names, and outputs a string\nwith escape codes, but also has all colors and styles as chainable methods\non the `Colr` object.\n\nSee also: [ColrC](https://github.com/welbornprod/colrc) (Colr for C)\n\n_______________________________________________________________________________\n\n## Dependencies:\n\n### System\n\n* **Python 3.5+** -\n    This library uses `yield from` and the `typing` module.\n    [Python 2 support is not planned.](#python-2)\n\n### Modules\n\nThere are no dependencies required for importing this library, however:\n\n* [Docopt](https://github.com/docopt/docopt) -\n    Only required for the command line tools ([colr](#colr-tool) and [colr-run](#colr-run))\n    and the [colr.docopt wrapper](#colrdocopt), not the library itself.\n\n## Installation:\n\nColr is listed on [PyPi](https://pypi.python.org/pypi/Colr),\nand can be installed using [pip](https://pip.pypa.io/en/stable/installing/):\n\n```\npip install colr\n```\n\nOr you can clone the repo on [GitHub](https://github.com/welbornprod/colr)\nand install it from the command line:\n\n```\ngit clone https://github.com/welbornprod/colr.git\ncd colr\npython3 setup.py install\n```\n\n_______________________________________________________________________________\n\n\n## Examples:\n\n### Simple:\n\n```python\nfrom colr import color\nprint(color('Hello world.', fore='red', style='bright'))\n```\n\n### Chainable:\n```python\nfrom colr import Colr as C\nprint(\n    C()\n    .bright().red('Hello ')\n    .normal().blue('World')\n)\n\n# Background colors start with 'bg', and AttributeError will be raised on\n# invalid method names.\nprint(C('Hello ', fore='red').bgwhite().blue('World'))\n\n```\n\n## Examples (256 Colors):\n\n### Simple:\n\n```python\nfrom colr import color\n# Invalid color names/numbers raise a ValueError.\nprint(color('Hello world', fore=125, back=80))\n```\n\n### Chainable:\n\n```python\nfrom colr import Colr as C\n# Foreground colors start with 'f_'\n# Background colors start with 'b_'\nprint(C().f_125().b_80('Hello World'))\n```\n\n## Examples (True Color):\n\n### Simple:\n\n```python\nfrom colr import color\nprint(color('Hello there.', fore=(255, 0, 0), back=(0, 0, 0)))\n```\n\n### Chainable:\n\n```python\nfrom colr import Colr as C\n# Foreground colors are set with the `rgb()` method.\n# Background colors are set with the `b_rgb()` method.\n# Text for the chained methods should be chained after or during\n# the call to the methods.\nprint(C().b_rgb(0, 0, 0).rgb(255, 0, 0, 'Hello there.'))\n```\n\n## Examples (Hex):\n\n### Simple:\n\n```python\nfrom colr import color\n# When not using the Colr.hex method, the closest matching extended code\n# is used. For true color, just use:\n#     fore=hex2rgb('ff0000')\n# or\n#     Colr.hex('ff0000', rgb_mode=True)\nprint(color('Hello there.', fore='ff0000', back='000'))\n```\n\n### Chainable:\n\n```python\nfrom colr import Colr as C\n# Foreground colors are set with the `hex()` method.\n# Background colors are set with the `b_hex()` method.\n# Text for the chained methods should be chained after or during\n# the call to the methods.\nprint(C().b_hex('#000').hex('ff0000', 'Hello there.'))\n\n# With rgb_mode set, these are the same:\nprint(C().hex('ff0000', 'test', rgb_mode=True))\nprint(C().rgb(255, 0, 0, 'test'))\n```\n\n_______________________________________________________________________________\n\n\n## Documentation:\n\nDocumentation for the `colr` API can be found in the GitHub repo\n([github.com/welbornprod/colr](https://github.com/welbornprod/colr)):\n\nModule/Object | Description\n------------------------------------- | --------------------------------------\n[colr.Colr](https://github.com/welbornprod/colr/blob/dev/docs/colr.Colr.md) | Methods for the `Colr` object, to colorize text.\n[colr.Control](https://github.com/welbornprod/colr/blob/dev/docs/colr.controls.md) | Functions, classes, and methods for the `Control` object, to control the cursor/screen.\ncolr.ColrControl | `Colr` and `Control` merged into one class. See `colr.Colr` and `colr.Control`.\n[colr.progress](https://github.com/welbornprod/colr/blob/dev/docs/colr.progress.md) | Progress updates, bars, or spinners.\n[colr.trans](https://github.com/welbornprod/colr/blob/dev/docs/colr.trans.md) | Color code translation/detection.\n\n_______________________________________________________________________________\n\n## Colr Tool:\n\nThe `colr` package can be used as a command line tool. An entry point script\nnamed `colr` is created when installed with pip. Otherwise it can be executed\nusing the `python -m colr` method.\n```bash\ncolr --help\n```\n\nBasic usage involves passing text, or piping stdin data and setting the colors\nby position or flag.\n\n```bash\n# These all do the same thing:\ncolr \"Test\" \"red\" \"white\" \"bright\"\ncolr \"Test\" -f \"red\" -b \"white\" -s \"bright\"\nprintf \"Test\" | colr -f \"red\" -b \"white\" -s \"bright\"\n```\n\nUsing the positional arguments is faster for just setting fore colors, but\nthe flag method is needed for stdin data, or for picking just the background\ncolor or style:\n\n```bash\ncolr \"Test\" -s \"bright\"\n```\n\nExtended and True colors are supported:\n```bash\ncolr \"Test\" 124 255\ncolr \"Test\" \"255, 0, 0\" \"255, 255, 255\"\n# Use true color (rgb) escape codes to generate a gradient, and then\n# center it in the terminal (0 means use terminal width).\ncolr \"Test\" -G \"255,0,0\" -G \"0,0,255\" -c 0\n```\n\nIt will do fore, back, style, gradients, rainbows, justification,\nand translation.\nIt can strip codes from text (as an argument or stdin), or explain the\ncodes found in the text.\n\n[lolcat](https://github.com/busyloop/lolcat) emulation:\n```bash\nfortune | colr --rainbow\n```\n\nThe colr tool does not read files, but it's not a problem:\n```bash\ncat myfile.txt | colr --gradient red\n```\n\nAlso see [ccat](https://github.com/welbornprod/ccat).\n\n\n## Colr-run:\n\nA small command-runner is included, called `colr-run`. This\nprogram will run another program, printing an animated message instead of the\nnormal output.\n\nIt is used to turn \"noisy\" commands into a nice single-line animation.\n\n### Basic Example:\n\nTo run a program with the default settings, `--` is still required:\n```bash\ncolr-run -- bash -c 'x=0; while ((x\u003c1000000)); do let x+=1; done'\n```\n\nAny stderr output from the program will ruin the animation, which may be fine\nif you are only looking for errors.\n\nYou can silence stderr output with `-e` if you don't need it:\n```bash\ncolr-run -e -- some-long-running-command\n```\n\nThe exit status of `colr-run` is the exit status of the command being\nexecuted. For `colr-run` errors, the exit status is `1` for basic errors,\nand `2` for cancelled commands.\n\n## Colr.docopt:\n\nColr provides a wrapper for docopt that will automatically colorize usage\nstrings. If you provide it a script name it will add a little more color by\ncolorizing the script name too.\n```python\nfrom colr import docopt\nargd = docopt(USAGE, script='mycommand')\n```\n\n_______________________________________________________________________________\n\n## Contributing:\n\nAs always contributions are welcome here. If you think you can improve something,\nor have a good idea for a feature, please file an\n[issue](https://github.com/welbornprod/colr/issues/new) or a\n[pull request](https://github.com/welbornprod/colr/compare).\n\n_______________________________________________________________________________\n\n## Notes:\n\n### Reasons\n\nIn the past, I used a simple `color()` function because I'm not fond of the\nstring concatenation style that other libraries use. The 'clor' javascript\nlibrary uses method chaining because that style suits javascript, but I wanted\nto make it available to Python also, at least as an option.\n\n### Reset Codes\n\nThe reset code is appended only if some kind of text was given, and\ncolr/style args were used. The only values that are considered 'no text'\nvalues are `None` and `''` (empty string). `str(val)` is called on all other\nvalues, so `Colr(0, 'red')` and `Colr(False, 'blue')` will work, and the reset\ncode will be appended.\n\nThis makes it possible to build background colors and styles, but\nalso have separate styles for separate pieces of text.\n\n### Python 2\n\nI don't really have the desire to back-port this to Python 2.\nIt wouldn't need too many changes, but I like the Python 3 features\n(`yield from`, `str/bytes`).\n\n### Windows\n\nWindows 10 finally has support for ANSI escape codes.\nColr can now be used on Windows 10+ by calling `SetConsoleMode`.\nOlder Windows versions are not supported and haven't been tested. If you are\nusing Colr for a tool that needs to support older Windows versions, you will\nneed to detect the current Windows version and call `colr.disable()` for those\nthat aren't supported. Otherwise you will have \"junk\" characters printed to\nthe screen.\n\n### Misc.\nThis library may be a little too flexible:\n\n```python\nfrom colr import Colr as C\n\n\nwarnmsg = lambda s: C('warning', 'red').join('[', ']')(' ').green(s)\nprint(warnmsg('The roof is on fire again.'))\n```\n\n![The possibilities are endless.](https://i.imgur.com/DAErdih.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwelbornprod%2Fcolr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwelbornprod%2Fcolr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwelbornprod%2Fcolr/lists"}