{"id":13463159,"url":"https://github.com/janlelis/paint","last_synced_at":"2025-05-15T07:07:24.751Z","repository":{"id":42382957,"uuid":"1972489","full_name":"janlelis/paint","owner":"janlelis","description":"Ruby gem for ANSI terminal colors 🎨︎ VERY FAST","archived":false,"fork":false,"pushed_at":"2024-12-28T22:59:52.000Z","size":199,"stargazers_count":378,"open_issues_count":0,"forks_count":21,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-14T12:59:32.070Z","etag":null,"topics":["ansi","ansi-colors","escape-sequences","fast","rgb-colors","ruby","ruby-cli","terminal","true-color"],"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/janlelis.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null}},"created_at":"2011-06-29T13:41:28.000Z","updated_at":"2025-03-13T06:43:26.000Z","dependencies_parsed_at":"2024-01-12T16:17:04.518Z","dependency_job_id":"a08864aa-9094-4c22-9090-6f9519ca1541","html_url":"https://github.com/janlelis/paint","commit_stats":{"total_commits":148,"total_committers":15,"mean_commits":9.866666666666667,"dds":0.3445945945945946,"last_synced_commit":"d639a4d6bc4c8a01953664739aaab97c5bbb941c"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janlelis%2Fpaint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janlelis%2Fpaint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janlelis%2Fpaint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janlelis%2Fpaint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janlelis","download_url":"https://codeload.github.com/janlelis/paint/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254292042,"owners_count":22046426,"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","ansi-colors","escape-sequences","fast","rgb-colors","ruby","ruby-cli","terminal","true-color"],"created_at":"2024-07-31T13:00:47.100Z","updated_at":"2025-05-15T07:07:19.733Z","avatar_url":"https://github.com/janlelis.png","language":"Ruby","readme":"# Ruby Paint [\u003cimg src=\"https://badge.fury.io/rb/paint.svg\" /\u003e](https://badge.fury.io/rb/paint) [\u003cimg src=\"https://github.com/janlelis/paint/workflows/Test/badge.svg\" /\u003e](https://github.com/janlelis/paint/actions?query=workflow%3ATest)\n\nPaint creates terminal colors and effects for you. It combines the strengths of **term-ansicolor**, **rainbow**, and similar projects into a simple to use, however still flexible terminal colors gem with no core extensions by default.\n\n## Features\n\n* No string extensions (suitable for library development)\n* Simple API\n* Faster than other terminal color gems ([as of January 2024](https://gist.github.com/janlelis/91413b9295c81ee873dc))\n* Supports *true color* or 256 colors (for capable terminals)\n* Allows you to set any terminal effects\n* `Paint.mode`: Fall-back modes for terminals with less colors, supported modes:\n  * 0xFFFFFF (= 16777215) colors (*true color*)\n  * 256 colors (palette)\n  * 16 colors (only ANSI colors, combined with bright effect)\n  * 8 colors (only ANSI colors)\n  * 0 colors (no colors / deactivate)\n\n## Paint 2.0 | True Color Support\n\nStarting with **Paint 2.0**, *true color* mode is the new default mode, since most major terminals now support 24bit colors. If it happens to not work in your setup:\n\n- Manually set `Paint.mode = 256` at the beginning of your code\n- Please [open a new issue](https://github.com/janlelis/paint/issues/new) so we can figure out how to blacklist the terminal used\n\n## Setup\n\nAdd to `Gemfile`:\n\n```ruby\ngem 'paint'\n```\n\nand run `bundle install`.\n\nIn Ruby do:\n\n```ruby\nrequire 'paint'\n```\n\n## Usage\n\nThe only method you need is: `Paint.[]`\n\nThe first argument given to `Paint.[]` is the string to colorize (if the object is not a string, `to_s` will be called on it). The other arguments describe how to modify/colorize the string. Let's learn by example:\n\n```ruby\nPaint['Ruby', :red]           # Sets ANSI color red\nPaint['Ruby', :red, :bright]  # Also applies bright/bold effect\nPaint['Ruby', :bright, :red]  # Does the same as above\nPaint['Ruby', :red, :bright, :underline] # Effects can often be combined\nPaint['Ruby', :red, :blue]    # The second color you define is for background\nPaint['Ruby', nil, :blue]     # Pass a nil before a color to ignore foreground and only set background color\nPaint['Ruby', [100, 255, 5]]  # You can define RGB colors. Depending on your terminal, this will create\n                              # a \"true color\" or map to 256/16/8 colors.\nPaint['Ruby', \"gold\", \"snow\"] # Paint supports rgb.txt color names, note that the arguments are strings\n                              # (:yellow != \"yellow\")!\nPaint['Ruby', \"#123456\"]      # HTML like definitions are possible\nPaint['Ruby', \"fff\"]          # Another HTML hex definition\nPaint['Ruby', :inverse]       # Swaps fore- and background\nPaint['Ruby', :italic, :encircle, :rapid_blink, :overline] # Probably not supported effects\nPaint['Ruby']                 # Don't pass any argument and the string will not be changed\n```\n\nWhen you pass multiple colors, the first one is taken as foreground color and the second one defines the background color, every following color will be ignored. To only change the background color, you have to pass a `nil` first. Effects can be passed in any order.\n\n[You can find more examples in the specs.](https://github.com/janlelis/paint/blob/master/spec/paint_spec.rb)\n\n[List of rgb.txt colors.](https://en.wikipedia.org/wiki/X11_color_names#Color_name_chart)\n\n## Windows Support\n\nFor ANSI support in Windows OS, you can use [ansicon](https://github.com/adoxa/ansicon) or [ConEmu](https://conemu.github.io/) or [WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10).\n\n## `Paint.mode`\n\nYou can choose between five ways to use `Paint.[]` by setting `Paint.mode` to one of the following:\n\n* **0xFFFFFF**: Use 16777215 *true colors*\n* **256**:      Use the 256 colors palette\n* **16**:       Use the eight ANSI colors (combined with bright effect)\n* **8**:        Use the eight ANSI colors\n* **0**:        Don't colorize at all\n\nPaint tries to automatically detect the proper value your terminal is capable of, please [open an issue](https://github.com/janlelis/paint/issues/new) if `Paint.detect_mode` yields a wrong value for you.\n\n`Paint.detect_mode` will return 0 if the [NO_COLOR environment variable is set](https://github.com/jcs/no_color/).\n\n## More Details About Terminal Colors and Effects\n\n\u003cimg src=\"https://pbs.twimg.com/media/ENyLvgVXUAgeDTn.jpg\" /\u003e\n\nTerminal colors/effects get created by [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code). These are strings that look like this: `\\e[X;X;X;X;X]m` where X are integers with some meaning. For example, `0` means *reset*, `31` means *red foreground* and `41` stands for red background. When you tell **Paint** to use one of the eight ANSI base colors as foreground color, it just inserts a number between `30` and `37` into the sequence. The following colors are available:\n\n* `:black`\n* `:red`\n* `:green`\n* `:yellow`\n* `:blue`\n* `:magenta`\n* `:cyan`\n* `:white`, `:gray`\n* (`:default`)\n\nWhen combined with the `:bright` (= `:bold`) effect, the color in the terminal emulator often differs a little bit, thus it is possible to represent 16 colors.\n\nThrough special sequences it's also possible to set 256-colors, or even 16777215 colors, instead of only the 8 ANSI ones. However, this is not supported by all terminals. Paint automatically translates given RGB colors to a suitable color of the supported color spectrum.\n\nWhen using the `Paint.[]` method, Paint wraps the given string between the calculated escape sequence and an reset sequence (`\"\\e[0m\"`). You can get the raw escape sequence by using the `Paint.color` method.\n\n### Effects\n\nSee [en.wikipedia.org/wiki/ANSI_escape_code](https://en.wikipedia.org/wiki/ANSI_escape_code) for a more detailed discussion:\n\n#### Often supported\n\n    0) :reset, :nothing\n    1) :bright, :bold\n    4) :underline\n    7) :inverse, :negative\n    8) :conceal, :hide\n    22) :clean\n    24) :underline_off\n    26) :inverse_off, :positive\n    27) :conceal_off, :show, :reveal\n\n#### Not widely supported\n\n    2) :faint\n    3) :italic\n    5) :blink, :slow_blink\n    6) :rapid_blink\n    9) :crossed, :crossed_out\n    10) :default_font, :font0\n    11-19) :font1, :font2, :font3, :font4, :font5, :font6, :font7, :font8, :font9\n    20) :fraktur\n    21) :bright_off, :bold_off, :double_underline\n    23) :italic_off, :fraktur_off\n    25) :blink_off\n    29) :crossed_off, :crossed_out_off\n    51) :frame\n    52) :encircle\n    53) :overline\n    54) :frame_off, :encircle_off\n    55) :overline_off\n\n## Substitution \u0026 Nesting\n\nFrom time to time, you might find yourself in a situation where you want to colorize a substring differently from the rest of the string. Paint supports this via a simple templating approach using the `%` method with an array argument. Use the `%{var}` notation within a string, and pass the template variables as a hash:\n\n```ruby\nPaint%['Yellow string with a %{blue_text} in it', :yellow,\n  blue_text: [\"blue text\", :blue]\n]\n# =\u003e \"\\e[33mYellow string with a \\e[34mblue text\\e[0m\\e[33m in it\\e[0m\"\n```\n\nPlease note that the resulting ASCII escape sequence can be quite verbose since it restores the parent context after the substitution.\n\n## Utilities\n\nThe `Paint.random` method generates a random ANSI color you can pass into `Paint.[]`:\n\n```ruby\nPaint['Ruby', Paint.random]        # Get one of eight random ANSI foreground colors\nPaint['Ruby', Paint.random(true)]  # Get one of eight random ANSI background colors\n```\n\nAnother helper method is `Paint.unpaint`, which removes any ANSI colors:\n\n```ruby\nPaint.unpaint( Paint['Ruby', :red, :bright] ).should == 'Ruby'\n```\n\nYou can get a `p` like alternative for calling `puts Paint.[]`:\n\n```ruby\nrequire 'paint/pa'\npa \"Ruby\", :red, :underline  # same as puts Paint[\"Ruby\", :red, :underline]\n```\n\n## Advanced Usage: Shortcuts\n\nThere is an extension gem available which allows you to define custom color definitions, which you can reuse later. See [SHORTCUTS.md](https://github.com/janlelis/paint/blob/main/SHORTCUTS.md) for documentation. This is completely optional.\n\n## J-_-L\n\nCopyright (c) 2011-2024 Jan Lelis \u003chttps://janlelis.com\u003e, released under the\nMIT license.\n\nThank you to [rainbow](https://github.com/sickill/rainbow) and [term-ansicolor](https://github.com/flori/term-ansicolor) for ideas and inspiration. Also, a lot of thanks to all the [contributors](https://github.com/janlelis/paint/contributors)!\n","funding_links":[],"categories":["Developer Tools","CLI Utilities","Ruby"],"sub_categories":["Terminal Coloring"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanlelis%2Fpaint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanlelis%2Fpaint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanlelis%2Fpaint/lists"}