{"id":15713788,"url":"https://github.com/watzon/cor","last_synced_at":"2025-05-12T23:20:29.538Z","repository":{"id":91428181,"uuid":"194178081","full_name":"watzon/cor","owner":"watzon","description":"Make working with colors in Crystal fun!","archived":false,"fork":false,"pushed_at":"2020-05-27T22:24:45.000Z","size":57,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T04:32:48.231Z","etag":null,"topics":["ansi","ascii","colorize","colors","crystal","crystal-lang","crystal-language","terminal"],"latest_commit_sha":null,"homepage":"https://watzon.github.io/cor/","language":"Crystal","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/watzon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2019-06-28T00:00:23.000Z","updated_at":"2023-06-21T22:20:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"0a132622-23cd-4a53-8732-79258d2f6205","html_url":"https://github.com/watzon/cor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watzon%2Fcor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watzon%2Fcor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watzon%2Fcor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watzon%2Fcor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/watzon","download_url":"https://codeload.github.com/watzon/cor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253837901,"owners_count":21972060,"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":["ansi","ascii","colorize","colors","crystal","crystal-lang","crystal-language","terminal"],"created_at":"2024-10-03T21:33:29.804Z","updated_at":"2025-05-12T23:20:29.515Z","avatar_url":"https://github.com/watzon.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cor\n\nCor (which means color in Portuguese) is a library for more easily\nworking with colors in Crystal. You can think of it as a more\npowerful version of `Colorize`. Cor allows you to very\neasily convert RGB(A) values to hex and back again for\nuse in CSS and HTML. It also provides a set of\nchainable methods for creting colorful strings\nfor the terminal using truecolor.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     cor:\n       github: watzon/cor\n   ```\n\n2. Run `shards install`\n\n## Usage\n\n### Creating a color\n\n```crystal\nrequire \"cor\"\n\nred = Cor.new(255, 0, 0)\n# or you can do\nred = Cor.new(\"FF0000\")\n# or you can also do\nred = Cor.color(:red)\n```\n\nYou can also include an alpha value\n\n```crystal\nmid_red = Cor.new(255, 0, 0, 0.5)\n```\n\n### Getting a hex string\n\n```crystal\nblue = Cor.color(:blue)\nputs blue.hex_string\n# =\u003e 0000ff\n```\n\n`#hex_string` also provides a couple of formatting options\n\n```crystal\nputs blue.hex_string(prefix: true)\n# =\u003e #0000ff\n\nputs blue.hex_string(alpha: true)\n# =\u003e 0000ffff\n\nputs blue.hex_string(upcase: true)\n# =\u003e 0000FF\n```\n\n### Retting a RGB string\n\n```crystal\nmagenta = Cor.color(:magenta)\n\nputs magenta.rgb_string\n# =\u003e rgb(255, 0, 255)\n\nputs magenta.rgb_string(alpha: true)\n# =\u003e rgb(255, 0, 255, 1)\n```\n\n### Math with colors\n\nThe `Cor` class includes the basic math methods as well\nwhich means if, for whatever reason, you want to add,\nsubtract, multiply, or divide colors, you can.\n\n```crystal\nputs Cor.color(:magenta) - Cor.color(:blue)\n# =\u003e #\u003cCor:0x7f5892e2df60 @alpha=255, @blue=255, @green=0, @red=0\u003e\n```\n\n### 24 bit truecolor strings\n\nMost modern terminals have support for [True color](https://www.wikiwand.com/en/Color_depth)\nwhich allows you to add color to your terminal output. Crystal\nalready has support for color output via the `Colorize`\nmodule in the standard library, but Cor takes things\na step further by allowing you to not only colorize\nyour output, but also bold, italicize, underline,\noverline, blink, etc.\n\nCor also provides a `String` patch that gives the `String` class\nchainable truecolor methods.\n\n```crystal\nrequire \"cor\"\nrequire \"cor/string\"\n\nputs \"This is awesome!\".fore(:blue).back(:white)\n\nputs \"Bold me!\".bold\nputs \"Italic me!\".italic\nputs \"Strike me!\".strike\nputs \"Blink me like it's 1999!\".blink\nputs \"Faint me!\".faint\nputs \"Underline me!\".underline\nputs \"Overline me!\".overline\n```\n\n## Development\n\nTODO: Write development instructions here\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/watzon/cor/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Chris Watson](https://github.com/watzon) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatzon%2Fcor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwatzon%2Fcor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatzon%2Fcor/lists"}