{"id":13463156,"url":"https://github.com/ku1ik/rainbow","last_synced_at":"2025-05-15T00:09:35.447Z","repository":{"id":446989,"uuid":"69648","full_name":"ku1ik/rainbow","owner":"ku1ik","description":"Ruby gem for colorizing printed text on ANSI terminals","archived":false,"fork":false,"pushed_at":"2025-01-14T08:37:14.000Z","size":204,"stargazers_count":820,"open_issues_count":9,"forks_count":70,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-09T20:02:09.942Z","etag":null,"topics":["colorization","gem","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/ku1ik.png","metadata":{"files":{"readme":"README.markdown","changelog":"Changelog.md","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":"2008-10-30T09:34:00.000Z","updated_at":"2025-04-09T19:02:42.000Z","dependencies_parsed_at":"2024-06-13T12:52:23.996Z","dependency_job_id":null,"html_url":"https://github.com/ku1ik/rainbow","commit_stats":{"total_commits":251,"total_committers":46,"mean_commits":5.456521739130435,"dds":0.6693227091633467,"last_synced_commit":"629cde5a18375b615ba175bad29a1953f336c5ee"},"previous_names":["ku1ik/rainbow","sickill/rainbow"],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ku1ik%2Frainbow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ku1ik%2Frainbow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ku1ik%2Frainbow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ku1ik%2Frainbow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ku1ik","download_url":"https://codeload.github.com/ku1ik/rainbow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248564869,"owners_count":21125412,"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":["colorization","gem","ruby"],"created_at":"2024-07-31T13:00:47.064Z","updated_at":"2025-04-12T11:49:30.673Z","avatar_url":"https://github.com/ku1ik.png","language":"Ruby","funding_links":[],"categories":["Developer Tools","Ruby"],"sub_categories":["Terminal Coloring"],"readme":"# Rainbow\n\n[![Gem Version](https://badge.fury.io/rb/rainbow.svg)](https://rubygems.org/gems/rainbow)\n[![CI](https://github.com/sickill/rainbow/actions/workflows/ci.yml/badge.svg)](https://github.com/sickill/rainbow/actions/workflows/ci.yml)\n[![Code Climate](https://codeclimate.com/github/sickill/rainbow.svg)](https://codeclimate.com/github/sickill/rainbow)\n[![Coverage Status](https://coveralls.io/repos/sickill/rainbow/badge.svg)](https://coveralls.io/r/sickill/rainbow)\n\nRainbow is a ruby gem for colorizing printed text on ANSI terminals.\n\nIt provides a string presenter object, which adds several methods to your\nstrings for wrapping them in [ANSI escape\ncodes](http://en.wikipedia.org/wiki/ANSI_escape_code). These codes when printed\nin a terminal change text attributes like text color, background color,\nintensity etc.\n\n## Usage\n\nTo make your string colored wrap it with `Rainbow()` presenter and call\n`.color(\u003ccolor name\u003e)` on it.\n\n### Example\n\n```ruby\nrequire 'rainbow'\n\nputs Rainbow(\"this is red\").red + \" and \" + Rainbow(\"this on yellow bg\").bg(:yellow) + \" and \" + Rainbow(\"even bright underlined!\").underline.bright\n\n# =\u003e \"\\e[31mthis is red\\e[0m and \\e[43mthis on yellow bg\\e[0m and \\e[4m\\e[1meven bright underlined!\\e[0m\"\n```\n\n![Screenshot of the previous code in a terminal](https://user-images.githubusercontent.com/132/132943811-93747cc5-bdaf-43a2-a1a4-a1f18e805eba.png)\n\nOr, [watch this video example](https://asciinema.org/a/J928KpHoUQ0sl54ulOSOLE71E?rows=20\u0026speed=2.5)\n\n### Rainbow presenter API\n\nRainbow presenter adds the following methods to presented string:\n\n* `color(c)` (with `foreground`, and `fg` aliases)\n* `background(c)` (with `bg` alias)\n* `bright`\n* `underline`\n* `blink`\n* `inverse`\n* `hide`\n* `faint` (not well supported by terminal emulators)\n* `italic` (not well supported by terminal emulators)\n* `cross_out`, `strike`\n\nText color can also be changed by calling a method named by a color:\n\n* `black`\n* `red`\n* `green`\n* `yellow`\n* `blue`\n* `magenta`\n* `cyan`\n* `white`\n* `aqua`\n* `silver`\n* `aliceblue`\n* `indianred`\n\nAll of the methods return `self` (the presenter object) so you can chain method\ncalls:\n\n```ruby\nRainbow(\"hola!\").blue.bright.underline\n```\n\nThe `Rainbow` module also provides an `uncolor` method for stripping away any\nexisting color or formatting. This may be handy for determining the visual\nlength of strings.\n\n```ruby\ntext = Rainbow(\"this is green!\").green\n# =\u003e \"\\e[32mthis is green!\\e[0m\"\n\nRainbow.uncolor(text)\n# =\u003e \"this is green!\"\n```\n\n### Refinement\n\nIf you want to use the Refinements version, you can:\n\n```ruby\nrequire 'rainbow/refinement'\nusing Rainbow\nputs \"Hi!\".green\n```\n\nHere's an IRB session example:\n\n```\n\u003e\u003e 'Hello, World!'.blue.bright.underline\nNoMethodError: undefined method `blue' for \"Hello, World!\":String\n    (ripl):1:in `\u003cmain\u003e'\n\u003e\u003e using Rainbow\n=\u003e main\n\u003e\u003e 'Hello, World!'.blue.bright.underline\n=\u003e \"\\e[34m\\e[1m\\e[4mHello, World!\\e[0m\"\n```\n\n### Color specification\n\nBoth `color` and `background` accept color specified in any\nof the following ways:\n\n* ANSI color number (where 0 is black, 1 is red, 2 is green and so on):\n  `Rainbow(\"hello\").color(1)`\n\n* [ANSI color](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) name or [X11 color](https://en.wikipedia.org/wiki/X11_color_names) name as a symbol:\n  `Rainbow(\"hello\").color(:yellow)`.\n  This can be simplified to `Rainbow(\"hello\").yellow`  \n  \n  See [Color list](#user-content-color-list) for all available color names.  \n  Note that ANSI colors can be changed in accordance with terminal setting.  \n  But X11 color is just a syntax sugar for RGB triplet. So you always see what you specified.\n\n* RGB triplet as separate values in the range 0-255:\n  `Rainbow(\"hello\").color(115, 23, 98)`\n\n* RGB triplet as a hex string:\n  `Rainbow(\"hello\").color(\"FFC482\")` or `Rainbow(\"hello\").color(\"#FFC482\")`\n\nWhen you specify a color with a RGB triplet rainbow finds the nearest match\nfrom 256 colors palette. Note that it requires a 256-colors capable terminal to\ndisplay correctly.\n\n#### Example: Choose a random color\n\nYou can pick a random color with Rainbow, it's a one-liner:\n\n```ruby\ncolors = Range.new(0,7).to_a\n\"whoop dee doop\".chars.map { |char| Rainbow(char).color(colors.sample) }.join\n# =\u003e \"\\e[36mw\\e[0m\\e[37mh\\e[0m\\e[34mo\\e[0m\\e[34mo\\e[0m\\e[37mp\\e[0m\\e[34m \\e[0m\\e[36md\\e[0m\\e[33me\\e[0m\\e[34me\\e[0m\\e[37m \\e[0m\\e[32md\\e[0m\\e[35mo\\e[0m\\e[33mo\\e[0m\\e[36mp\\e[0m\"\n\ncolors = [:aliceblue, :antiquewhite, :aqua, :aquamarine, :azure, :beige, :bisque, :blanchedalmond, :blueviolet]\n\"whoop dee doop\".chars.map { |char| Rainbow(char).color(colors.sample) }.join\n# =\u003e \"\\e[38;5;135mw\\e[0m\\e[38;5;230mh\\e[0m\\e[38;5;231mo\\e[0m\\e[38;5;135mo\\e[0m\\e[38;5;231mp\\e[0m\\e[38;5;231m \\e[0m\\e[38;5;122md\\e[0m\\e[38;5;231me\\e[0m\\e[38;5;231me\\e[0m\\e[38;5;230m \\e[0m\\e[38;5;122md\\e[0m\\e[38;5;51mo\\e[0m\\e[38;5;51mo\\e[0m\\e[38;5;51mp\\e[0m\"\n```\n\n### Configuration\n\nRainbow can be enabled/disabled globally by setting:\n\n```ruby\nRainbow.enabled = true/false\n```\n\nWhen disabled all the methods return an unmodified string\n(`Rainbow(\"hello\").red == \"hello\"`).\n\nIt's enabled by default, unless STDOUT/STDERR is not a TTY or a terminal is\ndumb.\n\n### Advanced usage\n\n`Rainbow()` and `Rainbow.enabled` operate on the global Rainbow wrapper\ninstance. If you would like to selectively enable/disable coloring in separate\nparts of your application you can get a new Rainbow wrapper instance for each\nof them and control the state of coloring during the runtime.\n\n```ruby\nrainbow_one = Rainbow.new\nrainbow_two = Rainbow.new\n\nrainbow_one.enabled = false\n\nRainbow(\"hello\").red          # =\u003e \"\\e[31mhello\\e[0m\" (\"hello\" if not on TTY)\nrainbow_one.wrap(\"hello\").red # =\u003e \"hello\"\nrainbow_two.wrap(\"hello\").red # =\u003e \"\\e[31mhello\\e[0m\" (\"hello\" if not on TTY)\n```\n\nBy default each new instance inherits enabled/disabled state from the global\n`Rainbow.enabled`.\n\nThis feature comes handy for example when you have multiple output formatters\nin your application and some of them print to a terminal but others write to a\nfile. Normally rainbow would detect that STDIN/STDERR is a TTY and would\ncolorize all the strings, even the ones that go through file writing\nformatters. You can easily solve that by disabling coloring for the Rainbow\ninstances that are used by formatters with file output.\n\n## Installation\n\nAdd it to your Gemfile:\n\n```ruby\ngem 'rainbow'\n```\n\nOr just install it via rubygems:\n\n```ruby\ngem install rainbow\n```\n\n## Color list\n\n### ANSI colors\n\n`black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`\n\n### X11 colors\n\n`aliceblue`, `antiquewhite`, `aqua`, `aquamarine`, `azure`, `beige`, `bisque`,\n`blanchedalmond`, `blueviolet`, `brown`, `burlywood`, `cadetblue`, `chartreuse`,\n`chocolate`, `coral`, `cornflower`, `cornsilk`, `crimson`, `darkblue`,\n`darkcyan`, `darkgoldenrod`, `darkgray`, `darkgreen`, `darkkhaki`,\n`darkmagenta`, `darkolivegreen`, `darkorange`, `darkorchid`, `darkred`,\n`darksalmon`, `darkseagreen`, `darkslateblue`, `darkslategray`, `darkturquoise`,\n`darkviolet`, `deeppink`, `deepskyblue`, `dimgray`, `dodgerblue`, `firebrick`,\n`floralwhite`, `forestgreen`, `fuchsia`, `gainsboro`, `ghostwhite`, `gold`,\n`goldenrod`, `gray`, `greenyellow`, `honeydew`, `hotpink`, `indianred`,\n`indigo`, `ivory`, `khaki`, `lavender`, `lavenderblush`, `lawngreen`,\n`lemonchiffon`, `lightblue`, `lightcoral`, `lightcyan`, `lightgoldenrod`,\n`lightgray`, `lightgreen`, `lightpink`, `lightsalmon`, `lightseagreen`,\n`lightskyblue`, `lightslategray`, `lightsteelblue`, `lightyellow`, `lime`,\n`limegreen`, `linen`, `maroon`, `mediumaquamarine`, `mediumblue`,\n`mediumorchid`, `mediumpurple`, `mediumseagreen`, `mediumslateblue`,\n`mediumspringgreen`, `mediumturquoise`, `mediumvioletred`, `midnightblue`,\n`mintcream`, `mistyrose`, `moccasin`, `navajowhite`, `navyblue`, `oldlace`,\n`olive`, `olivedrab`, `orange`, `orangered`, `orchid`, `palegoldenrod`,\n`palegreen`, `paleturquoise`, `palevioletred`, `papayawhip`, `peachpuff`,\n`peru`, `pink`, `plum`, `powderblue`, `purple`, `rebeccapurple`, `rosybrown`,\n`royalblue`, `saddlebrown`, `salmon`, `sandybrown`, `seagreen`, `seashell`,\n`sienna`, `silver`, `skyblue`, `slateblue`, `slategray`, `snow`, `springgreen`,\n`steelblue`, `tan`, `teal`, `thistle`, `tomato`, `turquoise`, `violet`,\n`webgray`, `webgreen`, `webmaroon`, `webpurple`, `wheat`, `whitesmoke`,\n`yellowgreen`\n\n## Authors\n\n- [Marcin Kulik](http://ku1ik.com/)\n- [Olle Jonsson](https://github.com/olleolleolle)\n- [and many contributors](https://github.com/sickill/rainbow/graphs/contributors)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fku1ik%2Frainbow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fku1ik%2Frainbow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fku1ik%2Frainbow/lists"}