{"id":15066793,"url":"https://github.com/midautumnmoon/reinbow","last_synced_at":"2025-04-10T13:53:08.311Z","repository":{"id":255445482,"uuid":"852180441","full_name":"MidAutumnMoon/Reinbow","owner":"MidAutumnMoon","description":"Ruby gem for colorizing text in terminal","archived":false,"fork":false,"pushed_at":"2024-11-10T03:56:50.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T12:39:17.621Z","etag":null,"topics":["cli","ruby"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/reinbow","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MidAutumnMoon.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":"2024-09-04T11:16:11.000Z","updated_at":"2024-11-10T23:36:18.000Z","dependencies_parsed_at":"2024-09-17T08:05:10.261Z","dependency_job_id":"bc728459-fd9d-450d-8c9b-fb0d3fa17e9f","html_url":"https://github.com/MidAutumnMoon/Reinbow","commit_stats":null,"previous_names":["midautumnmoon/reinbow"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MidAutumnMoon%2FReinbow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MidAutumnMoon%2FReinbow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MidAutumnMoon%2FReinbow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MidAutumnMoon%2FReinbow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MidAutumnMoon","download_url":"https://codeload.github.com/MidAutumnMoon/Reinbow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248228966,"owners_count":21068790,"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":["cli","ruby"],"created_at":"2024-09-25T01:12:08.685Z","updated_at":"2025-04-10T13:53:08.289Z","avatar_url":"https://github.com/MidAutumnMoon.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Reinbow\n\n![Gem Version](https://img.shields.io/gem/v/reinbow?style=for-the-badge\u0026label=gem%20version)\n\nReinbow is a Ruby gem for colorizing printed text on terminal.\n\nIt was original a fork of the great gem [ku1ik/rainbow](https://github.com/ku1ik/rainbow), but the old codebase took way too much efforts to overhaul, so instead this project was built from ground up.\n\nThat means this project has **no relationship** with the original `rainbow` beyond inspiration, **does not** contain codes from it, and **is not** compatible with it either.\n\n```ruby\nrequire \"reinbow\"\n\nusing Reinbow\n\nputs \"Blue cat\".blue + \" \" \\\n    + \"jumps over\".on_yellow + \" \" \\\n    + \"big\".bold + \" \" \\\n    + \"lazy meatball\".rgb( \"#f9e02e\" )\n```\n\n![screenshot of output of above code](./assets/readme.png)\n\n\n## Installation\n\nUsing Gemfile:\n\n```ruby\ngem 'reinbow'\n```\n\nUsing gem CLI:\n\n```ruby\ngem install reinbow\n```\n\n\n## Usage\n\nThe intended way to use `reinbow` is by using [*refinement*](https://docs.ruby-lang.org/en/master/Refinement.html) and calling *coloring methods* on String instances. But there's also a method for constructing the underlying `Reinbow::Painter` instances manually.\n\nBy default, coloring are enabled or disabled based on [*Standard for ANSI Colors in Terminals*](https://bixense.com/clicolors/), but methods are provided to toggle it manually.\n\n### Refinement\n\nSimply do:\n\n```ruby\n# 1) import the gem\nrequire \"reinbow\"\n\nmodule DesiredModule\n    # 2) \"using\" the Reinbow refinement in some module\n    using Reinbow\n\n    # 3) all string instances in this scope\n    # will have coloring methods\n    def colored = @message.blue\nend\n```\n\nSuch way `reinbow` doesn't pollute the precious method namespace.\n\n### API\n\nReinbow by default defines several methods to colorize or style strings, which have their names matching the [*SGR*](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR) counterparts.\n\nFull list of methods for applying terminal effects:\n\n* `#reset`\n* `#bold`\n* `#dim`\n* `#italic`\n* `#underline`\n* `#blink` *a lot of terminals ignore this for accessability reasons*\n* `#invert`\n* `#hide`\n* `#strike`\n* `#double_underline`\n* `#overline`\n\nDemo:\n\n```ruby\nputs \"strike bold and underline\".strike.bold.underline\n```\n\n![screenshot of above code](./assets/strike-bold-underline.png)\n\nFull list of methods for coloring foreground and background, with the background ones having `on_` prefix. Note that their *bright* variants are **not yet** supported.\n\n* `#black`\n* `#red`\n* `#green`\n* `#yellow`\n* `#blue`\n* `#magenta`\n* `#cyan`\n* `#white`\n* `#default`\n* `#on_black`\n* `#on_red`\n* `#on_green`\n* `#on_yellow`\n* `#on_blue`\n* `#on_magenta`\n* `#on_cyan`\n* `#on_white`\n* `#on_default`\n\nDemo:\n\n```ruby\nputs \"red on white\".red.on_white\n```\n![screenshot of above code](./assets/red-on-white.png)\n\n\nThe API also supports coloring with RGB values, and has a shorthand for using HEX string. Reinbow also comes with a full list of [*X11 Color Names*](https://en.wikipedia.org/wiki/X11_color_names). The detailed usage of both of them can be found in the *Examples* section below:\n\n* `#rgb( Reinbow::Rgb | String )`\n* `#on_rgb( Reinbow::Rgb | String )`\n\nDemo:\n\n```ruby\nputs \"great readability\" \\\n    .rgb( X11_COLORS[:lawngreen] ) \\\n    .on_rgb( \"#faf0e6\" )\n```\n![screenshot of above code](./assets/great-readability.png)\n\n\nAll coloring methods return `self` so that all method calls are chainable.\n\n```ruby\nputs \"well, your terminal, your land\" \\\n    .rgb( X11_COLORS[:coral] ).on_magenta \\\n    .strike.italic.underline.bold\n```\n![screenshot of above code](./assets/what.png)\n\n\nThere's also a method for turning reinbow functionality on and off. But note, unlike `rainbow`, there's **no global switch** for toggling it:\n\n* `#reinbow!( boolean )`\n\nAnd also a method for querying the on-off status:\n\n* `#reinbow?`\n\n\n### `Reinbow::Painter` Class\n\n`T.B.D.`\n\n\n## Examples\n\n### RGB Colors and X11 Color Names\n\n`Reinbow::Rgb` is a Data class for holding RGB values. It has following class methods:\n\n* `::new( red: 0..255, green: 0..255, blue: 0..255 )`\n* `::[]( 0..255, 0..255, 0..255 )`\n* `::hex( String )`\n\nWhere `::[]` is a shorthand for the keyword based constructor, and `::hex` is for making `Rgb` instance from plain string HEX, which is case-insensitive and also supports 3-letter HEX.\n\nExample:\n\n```ruby\nRgb.new( red: 1, green: 133, blue: 0 )\n# or\nRgb[1, 133, 0]\n# or\nRgb.hex( \"#0b8500\" )\n\n# 3-letter HEX\nRgb.hex( \"#abc\" ) # =\u003e \u003c... red=170, green=187, blue=204\u003e\n```\n\n`Reinbow::X11_COLORS` is a predefined hash of [*X11 Colors Names*](https://en.wikipedia.org/wiki/X11_color_names) to their corresponding RGB values. The X11 colors are not provided as coloring methods because there are whopping 130+ of them, which will pollute the instance methods.\n\nExample:\n\n```ruby\nX11 = Reinbow::X11_COLORS\n\nputs \"crimson line\".rgb( X11[:crimson] ).underline\n```\n\n![screenshot of above code](./assets/crimson-line.png)\n\n\n## License\n\n[BSD-3-Clause](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidautumnmoon%2Freinbow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmidautumnmoon%2Freinbow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidautumnmoon%2Freinbow/lists"}