Code Monkey home page Code Monkey logo

rainbow's Introduction

Rainbow

Gem Version CI Code Climate Coverage Status

Rainbow is a ruby gem for colorizing printed text on ANSI terminals.

It provides a string presenter object, which adds several methods to your strings for wrapping them in ANSI escape codes. These codes when printed in a terminal change text attributes like text color, background color, intensity etc.

Usage

To make your string colored wrap it with Rainbow() presenter and call .color(<color name>) on it.

Example

require 'rainbow'

puts Rainbow("this is red").red + " and " + Rainbow("this on yellow bg").bg(:yellow) + " and " + Rainbow("even bright underlined!").underline.bright

# => "\e[31mthis is red\e[0m and \e[43mthis on yellow bg\e[0m and \e[4m\e[1meven bright underlined!\e[0m"

Screenshot of the previous code in a terminal

Or, watch this video example

Rainbow presenter API

Rainbow presenter adds the following methods to presented string:

  • color(c) (with foreground, and fg aliases)
  • background(c) (with bg alias)
  • bright
  • underline
  • blink
  • inverse
  • hide
  • faint (not well supported by terminal emulators)
  • italic (not well supported by terminal emulators)
  • cross_out, strike

Text color can also be changed by calling a method named by a color:

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • aqua
  • silver
  • aliceblue
  • indianred

All of the methods return self (the presenter object) so you can chain method calls:

Rainbow("hola!").blue.bright.underline

Refinement

If you want to use the Refinements version, you can:

require 'rainbow/refinement'
using Rainbow
puts "Hi!".green

Here's an IRB session example:

>> 'Hello, World!'.blue.bright.underline
NoMethodError: undefined method `blue' for "Hello, World!":String
    (ripl):1:in `<main>'
>> using Rainbow
=> main
>> 'Hello, World!'.blue.bright.underline
=> "\e[34m\e[1m\e[4mHello, World!\e[0m"

Color specification

Both color and background accept color specified in any of the following ways:

  • ANSI color number (where 0 is black, 1 is red, 2 is green and so on): Rainbow("hello").color(1)

  • ANSI color name or X11 color name as a symbol: Rainbow("hello").color(:yellow). This can be simplified to Rainbow("hello").yellow

    See Color list for all available color names.
    Note that ANSI colors can be changed in accordance with terminal setting.
    But X11 color is just a syntax sugar for RGB triplet. So you always see what you specified.

  • RGB triplet as separate values in the range 0-255: Rainbow("hello").color(115, 23, 98)

  • RGB triplet as a hex string: Rainbow("hello").color("FFC482") or Rainbow("hello").color("#FFC482")

When you specify a color with a RGB triplet rainbow finds the nearest match from 256 colors palette. Note that it requires a 256-colors capable terminal to display correctly.

Example: Choose a random color

You can pick a random color with Rainbow, it's a one-liner:

colors = Range.new(0,7).to_a
"whoop dee doop".chars.map { |char| Rainbow(char).color(colors.sample) }.join
# => "\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"

colors = [:aliceblue, :antiquewhite, :aqua, :aquamarine, :azure, :beige, :bisque, :blanchedalmond, :blueviolet]
"whoop dee doop".chars.map { |char| Rainbow(char).color(colors.sample) }.join
# => "\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"

Configuration

Rainbow can be enabled/disabled globally by setting:

Rainbow.enabled = true/false

When disabled all the methods return an unmodified string (Rainbow("hello").red == "hello").

It's enabled by default, unless STDOUT/STDERR is not a TTY or a terminal is dumb.

Advanced usage

Rainbow() and Rainbow.enabled operate on the global Rainbow wrapper instance. If you would like to selectively enable/disable coloring in separate parts of your application you can get a new Rainbow wrapper instance for each of them and control the state of coloring during the runtime.

rainbow_one = Rainbow.new
rainbow_two = Rainbow.new

rainbow_one.enabled = false

Rainbow("hello").red          # => "\e[31mhello\e[0m" ("hello" if not on TTY)
rainbow_one.wrap("hello").red # => "hello"
rainbow_two.wrap("hello").red # => "\e[31mhello\e[0m" ("hello" if not on TTY)

By default each new instance inherits enabled/disabled state from the global Rainbow.enabled.

This feature comes handy for example when you have multiple output formatters in your application and some of them print to a terminal but others write to a file. Normally rainbow would detect that STDIN/STDERR is a TTY and would colorize all the strings, even the ones that go through file writing formatters. You can easily solve that by disabling coloring for the Rainbow instances that are used by formatters with file output.

Installation

Add it to your Gemfile:

gem 'rainbow'

Or just install it via rubygems:

gem install rainbow

Color list

ANSI colors

black, red, green, yellow, blue, magenta, cyan, white

X11 colors

aliceblue, antiquewhite, aqua, aquamarine, azure, beige, bisque, blanchedalmond, blueviolet, brown, burlywood, cadetblue, chartreuse, chocolate, coral, cornflower, cornsilk, crimson, darkblue, darkcyan, darkgoldenrod, darkgray, darkgreen, darkkhaki, darkmagenta, darkolivegreen, darkorange, darkorchid, darkred, darksalmon, darkseagreen, darkslateblue, darkslategray, darkturquoise, darkviolet, deeppink, deepskyblue, dimgray, dodgerblue, firebrick, floralwhite, forestgreen, fuchsia, gainsboro, ghostwhite, gold, goldenrod, gray, greenyellow, honeydew, hotpink, indianred, indigo, ivory, khaki, lavender, lavenderblush, lawngreen, lemonchiffon, lightblue, lightcoral, lightcyan, lightgoldenrod, lightgray, lightgreen, lightpink, lightsalmon, lightseagreen, lightskyblue, lightslategray, lightsteelblue, lightyellow, lime, limegreen, linen, maroon, mediumaquamarine, mediumblue, mediumorchid, mediumpurple, mediumseagreen, mediumslateblue, mediumspringgreen, mediumturquoise, mediumvioletred, midnightblue, mintcream, mistyrose, moccasin, navajowhite, navyblue, oldlace, olive, olivedrab, orange, orangered, orchid, palegoldenrod, palegreen, paleturquoise, palevioletred, papayawhip, peachpuff, peru, pink, plum, powderblue, purple, rebeccapurple, rosybrown, royalblue, saddlebrown, salmon, sandybrown, seagreen, seashell, sienna, silver, skyblue, slateblue, slategray, snow, springgreen, steelblue, tan, teal, thistle, tomato, turquoise, violet, webgray, webgreen, webmaroon, webpurple, wheat, whitesmoke, yellowgreen

Authors

rainbow's People

Contributors

avdv avatar bakku avatar chiting avatar deivid-rodriguez avatar dependabot[bot] avatar elifoster avatar fatkodima avatar fcoury avatar flavorjones avatar gogainda avatar ku1ik avatar lkdjiin avatar mattrayner avatar mieko avatar mipearson avatar mishina2228 avatar nicolasleger avatar olleolleolle avatar pocke avatar rrosenblum avatar sato-s avatar sferik avatar sschuberth avatar stephan-nordnes-eriksen avatar sunny avatar swrobel avatar tbpgr avatar txag1995 avatar ybiquitous avatar ypresto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rainbow's Issues

Support for baked-in Regular Expression matched string colorization

Hello all, love this project.

I was hoping if a pull request that implements a feature to colorize strings based on a regular to match will be accepted.

I was hoping something along the lines of:

{name: "Bob Jones", age: 19}.to_json.red(:matches => /(?<=)name:\s"[^"]*"/) # Highlights all the name properties 

This is going to be extremely helpful for logging out JSONs and other streams of data making it easier to identify particular lines dynamically that you don't have control over.

I am willing to work on this pull request.

NullPresenter doesn't handle X11 color names

When an X11 color name method is used, e.g.:

puts Rainbow('something').orange

and the NullPresenter is used, e.g., by redirecting output to /dev/null,
then an exception is raised because the NullPresenter doesn't define the X11 color name methods in the same way as the standard presenter.

A work-around is to not use the X11 name methods, but only use the color method, e.g.:

puts Rainbow('something').color(:orange)

but it seems the NullPresenter should handle this.

Install issues with 2.2.1

looks like an undeclared rake dependency

> gem install rainbow -v 2.2.1
Fetching: rainbow-2.2.1.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing rainbow:
	ERROR: Failed to build gem native extension.

    /opt/rh/rh-ruby22/root/usr/bin/ruby mkrf_conf.rb

rake RUBYARCHDIR=/home/deployer/.gem/ruby/extensions/x86_64-linux/rainbow-2.2.1 RUBYLIBDIR=/home/deployer/.gem/ruby/extensions/x86_64-linux/rainbow-2.2.1
sh: rake: command not found

rake failed, exit code 127

Gem files will remain installed in /home/deployer/.gem/ruby/gems/rainbow-2.2.1 for inspection.
Results logged to /home/deployer/.gem/ruby/extensions/x86_64-linux/rainbow-2.2.1/gem_make.out

Installation on default Ubuntu 16.04 for release 2.2.2 is broken still

I hope it may be something in my setup but the installation of version 2.2.2 still appears to be broken:

Building native extensions.  This could take a while...
ERROR:  Error installing rainbow:
        ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/rainbow-2.2.2/ext
/usr/bin/ruby2.3 mkrf_conf.rb

current directory: /var/lib/gems/2.3.0/gems/rainbow-2.2.2/ext
/usr/bin/ruby2.3 -rubygems /usr/share/rubygems-integration/all/gems/rake-10.5.0/bin/rake RUBYARCHDIR=/var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/rainbow-2.2.2 RUBYLIBDIR=/var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/rainbow-2.2.2
/usr/bin/ruby2.3: No such file or directory -- /usr/share/rubygems-integration/all/gems/rake-10.5.0/bin/rake (LoadError)

rake failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/rainbow-2.2.2 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/rainbow-2.2.2/gem_make.out

I am trying with a clean Ubuntu 16.04 build and ruby that ships with it.

Image / Screenshot

Hello Olle,

Do you think you could show an image how rainbow looks on some terminal, on the main page of rainbow? (Feel free to close this issue here at any moment in time.)

CI needs an update

The CI system isn't running, so perhaps moving to a useful one is due, now?

Calling .color is changing variables

Rainbow 1.1.2 behavior (wrong! - the variable is changed):

$ gem install rainbow
Fetching: rainbow-1.1.2.gem (100%)
Successfully installed rainbow-1.1.2
1 gem installed

$ irb
ree-1.8.7-2011.03 :001 > require 'rainbow' 
 => true 
ree-1.8.7-2011.03 :002 > @string = "color-me-blind"
 => "color-me-blind" 
ree-1.8.7-2011.03 :003 > @string.color(:yellow)
 => "\e[33mcolor-me-blind\e[0m" 
ree-1.8.7-2011.03 :004 > @string
 => "\e[33mcolor-me-blind\e[0m"

Rainbow 1.1.1 behavior (correct - @string is not touched):

$ gem list rainbow

*** LOCAL GEMS ***

rainbow (1.1.1)

$ irb
ree-1.8.7-2011.03 :003 > require 'rainbow'
 => true 
ree-1.8.7-2011.03 :004 > @string = "color-me-blind"
 => "color-me-blind" 
ree-1.8.7-2011.03 :005 > @string.color(:yellow)
 => "\e[33mcolor-me-blind\e[0m" 
ree-1.8.7-2011.03 :006 > @string
 => "color-me-blind"

Issue with require or using as dependency in gem.

When using rainbow as a dependency in a gem or simply using it with 'require' in IRB, I can't access the X11 colors, ie: Rainbow("test").orange.

NoMethodError: undefined method `orange' for "Test orange":Rainbow::Presenter
    from (irb):2
    from /Users/aaronvb/.rbenv/versions/2.2.3/bin/irb:11:in `<main>'

However when using rainbow in a rails app by including in the gem file, it works fine.

I narrowed the problem down to the Color module not being loaded when being used with 'require' or as a gem dependency, and when orange goes to method_missing it doesn't find the color.

I then changed all the require's to require_relative and removed rainbow from the path and the problem went away.

yellow appears to be green

On my box. 2013 MacBook Pro 13" w/Retina. "foo".foreground(:yellow) gets you the word "foo" in bright green.

No license

Can't package it as there is no license specified in README nor LICENSE

ArgumentError when using color("red")

Specifying red color by name seems to fail, while it works for other colors. It also works if color name is specified as a symbol, eg :red

To reproduce

2.4.1 :001 > require 'rainbow'
 => true 
2.4.1 :002 > Rainbow("this is a test message").red
 => "\e[31mthis is a test message\e[0m" 
2.4.1 :003 > Rainbow("this is a test message").color(:red)
 => "\e[31mthis is a test message\e[0m" 
2.4.1 :004 > Rainbow("this is a test message").color("red")
ArgumentError: wrong number of arguments (given 1, expected 0)
	from /usr/local/rvm/gems/ruby-2.4.1/gems/rainbow-3.0.0/lib/rainbow/color.rb:42:in `to_i'
	from /usr/local/rvm/gems/ruby-2.4.1/gems/rainbow-3.0.0/lib/rainbow/color.rb:42:in `parse_hex_color'
	from /usr/local/rvm/gems/ruby-2.4.1/gems/rainbow-3.0.0/lib/rainbow/color.rb:34:in `build'
	from /usr/local/rvm/gems/ruby-2.4.1/gems/rainbow-3.0.0/lib/rainbow/presenter.rb:20:in `color'
	from (irb):4
	from /usr/local/rvm/rubies/ruby-2.4.1/bin/irb:11:in `<main>'
2.4.1 :005 > Rainbow("this is a test message").color("green")
 => "\e[38;5;46mthis is a test message\e[0m" 
2.4.1 :006 > 

Ruby: 2.4.1
rubygems: 2.6.14
rainbow gem: 3.0.0
OS: CentOS 7.4

rainbow requires rake but doesn't specify the dependency

        ERROR: Failed to build gem native extension.

    current directory: /nix/store/yrzx9j1awsgajys5r9phy9hq6bm6f8wc-ruby2.4.0-rainbow-2.2.1/lib/ruby/gems/2.4.0/gems/rainbow-2.2.1/ext
/nix/store/6y417nc5913mdqm2dzgv5gk9ipv47myd-ruby-2.4.0/bin/ruby mkrf_conf.rb

current directory: /nix/store/yrzx9j1awsgajys5r9phy9hq6bm6f8wc-ruby2.4.0-rainbow-2.2.1/lib/ruby/gems/2.4.0/gems/rainbow-2.2.1/ext
rake RUBYARCHDIR=/nix/store/yrzx9j1awsgajys5r9phy9hq6bm6f8wc-ruby2.4.0-rainbow-2.2.1/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0/rainbow-2.2.1 RUBYLIBDIR=/nix/store/yrzx9j1awsgajys5r9phy9hq6bm6f8wc-ruby2.4.0-rainbow-2.2.1/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0/rainbow-2.2.1
sh: rake: command not found

Improved contribution and setup docs

As a new contributor it would be nice to have a contributing doc for reference.
This same doc can also guide developers in setting the project up locally.

I am opening this issue so we can perhaps start the conversation around what we would like to include in such a document should we decide to go ahead and add a contributing doc.

2.2.0 failed to build gem native extension on travis-ci

just hit this issue on travis-ci: https://travis-ci.org/benbalter/jekyll-readme-index/builds/187073263
when the latest build pulled 2.2.0; previously it was using 2.1.0

Installing rainbow 2.2.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

As usual, travis tried 3 times and gave up, building under ubuntu. But locally on MacOSX, the project updated to 2.2.0 and built fine.

See the build log for exhaustive environment details.

Any idea why this platform variance and what it is about 2.2.0 that might have caused this?

Install issues with 2.2.0

Getting an error installing rainbow 2.2.0.

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
    current directory: /home/travis/.rvm/gems/ruby-2.3.0/gems/rainbow-2.2.0/ext
/home/travis/.rvm/rubies/ruby-2.3.0/bin/ruby mkrf_conf.rb
current directory: /home/travis/.rvm/gems/ruby-2.3.0/gems/rainbow-2.2.0/ext
/home/travis/.rvm/rubies/ruby-2.3.0/bin/ruby -rubygems
/home/travis/.rvm/gems/ruby-2.3.0/gems/rake-10.5.0/bin/rake
RUBYARCHDIR=/home/travis/.rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/rainbow-2.2.0
RUBYLIBDIR=/home/travis/.rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/rainbow-2.2.0
(in /home/travis/.rvm/gems/ruby-2.3.0/gems/rainbow-2.2.0)
fatal: Not a git repository (or any of the parent directories): .git
rake aborted!
LoadError: cannot load such file -- rspec/core/rake_task
/home/travis/.rvm/gems/ruby-2.3.0/gems/rainbow-2.2.0/Rakefile:2:in `<top
(required)>'
(See full trace by running task with --trace)
rake failed, exit code 1
Gem files will remain installed in
/home/travis/.rvm/gems/ruby-2.3.0/gems/rainbow-2.2.0 for inspection.
Results logged to
/home/travis/.rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/rainbow-2.2.0/gem_make.out
An error occurred while installing rainbow (2.2.0), and Bundler cannot
continue.
Make sure that `gem install rainbow -v '2.2.0'` succeeds before bundling.

Doesn't work with ruby2.4 on linux

Trying to install rainbow with rubocop and ruby2.4. Here is what i get in the end:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    can't modify frozen String

Gem files will remain installed in
/home/ubuntu/inboundsms/vendor/bundle/ruby/2.4.0/gems/rainbow-2.2.1 for
inspection.
Results logged to
/home/ubuntu/inboundsms/vendor/bundle/ruby/2.4.0/extensions/x86_64-linux/2.4.0-static/rainbow-2.2.1/gem_make.out

An error occurred while installing rainbow (2.2.1), and Bundler cannot
continue.
Make sure that `gem install rainbow -v '2.2.1'` succeeds before bundling.

X11 named color methods not available through String refinement

Version

Ruby: 3.2.2
Rainbow gem: 3.1.1
or
Rainbow commit: 629cde5

Description

Using the String refinement interface, ANSI foreground color methods can be used but their X11 counterparts cannot.

$ irb --simple-prompt -r rainbow/refinement
>> using Rainbow
=> main
>> Rainbow("hello").red
=> "\e[31mhello\e[0m"
>> "hello".red
=> "\e[31mhello\e[0m"
>> Rainbow("hello").tomato
=> "\e[38;5;209mhello\e[0m"
>> "hello".tomato
(irb):5:in `<main>': undefined method `tomato' for "hello":String (NoMethodError)

Workarounds

  • just use the Presenter interface
  • use another rainbow method earlier in the method chain, if appropriate, as they return a Presenter object
    >> "hello".bright.tomato
    => "\e[1m\e[38;5;209mhello\e[0m"
    >> "hello".tomato.bright
    (irb):7:in `<main>': undefined method `tomato' for "hello":String (NoMethodError)
    

Diagnosis

The reason the ANSI methods work but the X11 ones don't is that the refinement works by defining Presenter's instance methods onto String. While the ANSI methods are explicitly defined on Presenter, the X11 ones are handled by Presenter's method_missing, so they don't get added. I'll make a PR.

Feature request: Themes

I find myself using Rainbow for a CLI tool which wants colorized output, and I put it in some colors.

Are these the right colors?, I ask myself. Not every terminal color setup will be good with this.

What if Rainbow had a feature for setting colors in Themes, and I could switch to a new theme programatically?

CI: JRuby tests fail on JDK installation

https://travis-ci.org/sickill/rainbow/builds/634729227 is a failed JRuby build where the CI configuration fails to install the JDKs needed.

$ ~/bin/install-jdk.sh --target "/home/travis/oraclejdk8" --workspace "/home/travis/.cache/install-jdk" --feature "8" --license "BCL"

Ignoring license option: BCL -- using GPLv2+CE by default

install-jdk.sh 2019-12-16

Expected feature release number in range of 9 to 15, but got: 8

The command "~/bin/install-jdk.sh --target "/home/travis/oraclejdk8" --workspace "/home/travis/.cache/install-jdk" --feature "8" --license "BCL"" failed and exited with 3 during .

Release 3.0.1 (or 3.1)?

master has TargetRubyVersion: 2.3.
Similar issue to: #87 and #88.

Released gem 3.0.0 only includes PR's through #79.

We could use a released gem that includes the newer PR's. We're running into an issue with Ruby 2.1 being targetted from 3.0.0 (even though we don't need it)
See: hanami/cli#54

I'm not sure if it should be 3.0.1 or 3.1.0, since I don't know of all the changes. Might be better to bump to 3.1.0 to be safe?

Thank you!

JRuby support!

Looks like @olleolleolle is way head of me :-)

I just ran into this while trying to run Mastodon on JRuby, because it depends on i18n-tasks which depends on rainbow 2.2.2, which still had an extension.

I have gathered that the extension is going away, and a 3.0 release without it may come soon. What can I do to help? :-)

Enhancement: Rainbow.clear?

I am using rainbow to build up tables with possibly colored components, and I need to compute the width of a string that may or may not be rainbowized. I would like to have a method on Rainbow that would return just the wrapped string without any escape codes if the string is already wrapped or just the string otherwise.

Then I could calculate the width of an element that may or may not be wrapped with something like

xx = Rainbow("hello").color(:auqamarine).blink
yy = 'hello'
Rainbow.clear(xx) # => 'hello'
Rainbow.clear(yy) # => 'hello'
Rainbow.clear(xx).length # => 6
Rainbow.clear(yy).length # => 6

In the meantime, any easy way to do this with current gem?
Also, thanks for a great gem.

Installation on rainbow 2.2.2 on ruby 2.4.0 broken

Adding rainbow ~> 2.2 to my Gemfile and running bundle install, I see:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    can't modify frozen String

Gem files will remain installed in
/var/lib/jenkins/workspace/vendor/gems/ruby/2.4.0/gems/rainbow-2.2.2 for
inspection.
Results logged to
/var/lib/jenkins/workspace/vendor/gems/ruby/2.4.0/extensions/x86_64-linux/2.4.0-static/rainbow-2.2.2/gem_make.out

An error occurred while installing rainbow (2.2.2), and Bundler cannot continue.
Make sure that `gem install rainbow -v '2.2.2'` succeeds before bundling.

I expected it to install properly. Is this a known issue? Is there any other information I can provide to help debug this?

Use of mutation testing in rainbow - Help needed

Hello there!

My name is Ana. I noted that you use the mutation testing tool mutant in the project.
I am a postdoctoral researcher at the University of Seville (Spain), and my colleagues and I are studying how mutation testing tools are used in practice. With this aim in mind, we have analysed over 3,500 public GitHub repositories using mutation testing tools, including yours! This work has recently been published in a journal paper available at https://link.springer.com/content/pdf/10.1007/s10664-022-10177-8.pdf.

To complete this study, we are asking for your help to understand better how mutation testing is used in practice, please! We would be extremely grateful if you could contribute to this study by answering a brief survey of 21 simple questions (no more than 6 minutes). This is the link to the questionnaire https://forms.gle/FvXNrimWAsJYC1zB9.

Drop me an e-mail if you have any questions or comments ([email protected]). Thank you very much in advance!!

Bundler 0.14 breaks 2.2.1 build

Workaround

Suggested solutions for people encountering this problem at the moment: gem update --system or locking down rainbow to 2.1.x in your Gemfile.

Original description:

The new bundler version 0.14 exits with the following message:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    can't modify frozen String

Downgrading to previous bundler version 1.13.7 is a workaround.

Rainbow incompatible with vendor/bundle and rubocop styling gems

When installing rainbow (From other gems), to vendor bundle. It is copying down the extra files, such as rubocop config e.t.c.

Because these files are copied, they are being lazily loaded in (I'm using a custom rubocop config), when using other gems, there is a conflict in TargetRubyVersion.

This then causes the entire build to crash with something like

error: RuboCop found unsupported Ruby version 2.1 in `TargetRubyVersion` parameter (in vendor/bundle/ruby/2.7.0/gems/rainbow-3.0.0/.rubocop.yml). 2.1-compatible analysis was dropped after version 0.58.
Supported versions: 2.4, 2.5, 2.6, 2.7
rake aborted!

Solution: Remove all non-necessary files in the gemspec. This is a blocking change meaning we've had to uninstall rubocop for now.

Support mode for colorize

Would be great if you could offer a support mode, where I can still use the old colorize syntax:

"test".colorize(:blue).on_black

But replace colorize with rainbow in the Gemfile..

Do you think this would be possible?

Dropped support for TargetRubyVersion: "2.1"

In the latest release, v0.60.0, it appears Rubocop has dropped support for TargetRubyVersion being less than 2.2.

This gem is listed as a runtime dependency in rubocop:
https://github.com/rubocop-hq/rubocop/blob/master/rubocop.gemspec#L41

Yet since this project is requiring an older, unsupported ruby version i.e. 2.1:
https://github.com/sickill/rainbow/blob/master/.rubocop.yml#L6

It is preventing my project to build properly in CircleCI whilst using a ruby 2.4.1, throwing the following error:

Error: Unsupported Ruby version 2.1 found in `TargetRubyVersion` parameter (in vendor/bundle/ruby/2.4.0/gems/rainbow-3.0.0/.rubocop.yml). 2.1-compatible analysis was dropped after version 0.58.
Supported versions: 2.2, 2.3, 2.4, 2.5, 2.6

3.0.0 release?

Just wondering when 3.0.0 will be released and added to rubygems.org?

The Rake dependency is definitely an issue in our company, as it causes build conflicts.

minimum version of ruby supported making Github Action rubocop crash + version missing on rubygems

On my computer bundle exec rubocop gives no offenses or error (ruby 2.7).

But on the CI (Github Action, image ruby 2.6) I get an error because ruby 2.1 is not supported by rubocop.
Rubocop detects ruby 2.1 in TargetRubyVersion of Rainbow rubocop file. It seems to be because I use the paint gems that requires rainbow 3.0.0 which is the last version available on rubygems.

Seems you know requires ruby 2.3 in git tag 3.1.0 but it will still crash since rubocops says:

Supported versions: 2.4, 2.5, 2.6, 2.7, 3.0

So could you requires at least ruby 2.4 in the rubocop file (and gemspec for no mismatch or disable the cop that check that), I don't really understand why rubocops on the CI is running on all the sub-dependencies instead of just my code, my best guess is that I requires paint here that itself requires rainbow.

So please:

  1. Release 3.1.0 on rubygems
  2. Make a new 3.2.0 with ruby 2.4 as min version and release it on rubygems

rake dependency

I was installing on the ubuntu/xenial32 vagrant machine which had only ruby and ruby-dev apt packages installed (in addition to the base machine) and i was getting this error below.

running gem install rake first solved the problem.

i'd submit a PR but i'm not sure where it goes in the specfile -- add_development_dependency, or another type of dependency?

ubuntu@ubuntu-xenial:/vagrant$ sudo gem install rainbow
Building native extensions.  This could take a while...
ERROR:  Error installing rainbow:
	ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/rainbow-2.2.1/ext
/usr/bin/ruby2.3 mkrf_conf.rb

current directory: /var/lib/gems/2.3.0/gems/rainbow-2.2.1/ext
/usr/bin/ruby2.3 -rubygems /usr/share/rubygems-integration/all/gems/rake-10.5.0/bin/rake RUBYARCHDIR=/var/lib/gems/2.3.0/extensions/x86-linux/2.3.0/rainbow-2.2.1 RUBYLIBDIR=/var/lib/gems/2.3.0/extensions/x86-linux/2.3.0/rainbow-2.2.1
/usr/bin/ruby2.3: No such file or directory -- /usr/share/rubygems-integration/all/gems/rake-10.5.0/bin/rake (LoadError)

rake failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/rainbow-2.2.1 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86-linux/2.3.0/rainbow-2.2.1/gem_make.out

Blank Line Insertion

Sometimes printing colored strings inserts blank lines afterwards. Any ideas?
Weird thing is that happens only sometimes.
If I remove the coloring, the result is normal.

Enhancement: random color selection

It would be nice to have a way of randomly adding colors to strings, like randomly adding different colors to every letter. Also, a way of randomly selecting a color from the list of predefined basic and X11 colors would be interesting to see.

Doesn't seem to work with printf

When I'm using rainbow to add colour to strings that are displayed with printf, it seems to mess up the alignments. Example using irb below. Is there anything I can do to work around this?

stewart@host:~$ irb
ruby-1.9.2-head > require "rainbow" 
 => true
ruby-1.9.2-head > printf("%20s\n", "foo")
                 foo # this is indented by 17 chars (correctly)
 => nil
ruby-1.9.2-head > printf("%20s\n", "foo".foreground(:red))
        foo # this is coloured, but only indented by 8 chars
 => nil 
ruby-1.9.2-head > printf("%20s\n", "foo".foreground(:red).background(:white))
   foo # this is coloured, but it's only indented by 3 chars
 => nil

Possibility to pass style as symbol

Is there a possibility to pass the style as a symbol? I wanted to write a generic method for coloring aka:

def colorize(string, foreground, style = :reset)
  Rainbow(string).fg(foreground).style(style)
end

Is there something similar possible?

Issues with Ruby 2.2.1

For some reason, gems that include rainbow, like RuboCop, are failing when used with Ruby 2.2.1. This might be a bug with Ruby's 2.2.x refinements feature.

private method `color' called for "An error occurred while Style/MultilineOperationIndentation":String
/Users/justin/.rvm/gems/ruby-2.2.1@madrone/gems/rubocop-0.30.1/lib/rubocop/cop/team.rb:93:in `block (2 levels) in process_commissioner_errors'

UPDATE

Actually, I'm seeing this with Ruby 2.1.5. Researching.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.