
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
The most downloaded ANSI color gem you'll find :-)
It's an actively maintained fork of Chris @defunkt Wanstrath's gem colored, which appears to be no longer supported. So instead of accepting this as a pull request, a new gem was born.
This fork comes with a slightly spruced up syntax, some additional features, and a test suite written in RSpec.
In addition to the simple syntax of the original gem, which affected only the string to the left of the method call, the new "bang" syntax affects a string to the right. If the block or a method argument is provided, the contents is wrapped in the color, and the color is then reset back.
If no block or argument is provided, the color is left open-ended, and must be explicitly reset – when using the 'bang' notation.
Note: previous versions used method name
clear
instead ofno_color
, which clashed with many 3rd party frameworks that defined similarly named method in the global namespace. This highlights the dangers of introducing so many words into theString
namespace.
With this gem you can add color to not just strings, but to any other class. String
class is automatically decorated as soon as require 'colored2'
is parsed by the ruby interpreter. Note that future versions may refrain from auto-requiring colored2/strings
, and rely on explicitly requiring components they need colorized, eg require 'colored2/numbers'
.
To color numbers, require the following file, which automatically decorates Integer
and Float
. You can also add color methods to the Object
. Finally, you can add the methods to any custom class by including the Colored2
Module.
Below is an IRB
— session that shows a slightly more advanced usage.
There are several additional helpers tucked onto the String
class.
#to_bol
(to beginning of the line) will rewind the cursor back to the beginning of the current line.#to_eol
(to end of line)Add this line to your application's Gemfile:
gem 'colored2'
And then execute:
$ bundle
Or install it yourself as:
$ gem install colored2
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/kigster/colored2.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that colored2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.