0.0
No commit activity in last 3 years
No release in over 3 years
A simple library for coloring text output. Heavily inspired from term-ansicolor and rainbow, I recommend using these gems for more complex color needs. By default this gem does not do any core extension. When mixed in String it only add two methods: color and uncolor. Paint is another gem similar to this one, but with more powerful shortcuts definitions.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.0
~> 10
~> 0.8
 Project Readme

simplecolor

Gem Version Ruby test result Build Status

Description

A simple library for coloring text output. Heavily inspired by rainbow, term-ansicolor and paint.

By default this gem does not change the String class, unlike rainbow. The reason I wrote this gem is that when mixed in String it only adds two methods: color and uncolor. This is the main reason I don't use term-ansicolor which is more powerful, but adds more methods when mixed in. The gem paint is similar to this one, but with more powerful shortcuts definitions.

Features

  • No string extensions (suitable for library development)

  • Mixing the library in String only add two methods: color and uncolor.

  • Supports setting any effects (although most terminals won’t support it)

  • Simple to use

Examples

require 'simplecolor'

SimpleColor.color("blue", :blue, :bold)
SimpleColor.color(:blue,:bold) { "blue" }
SimpleColor.color(:blue,:bold) << "blue" << SimpleColor.color(:clear)

SimpleColor.mix_in_string
"blue".color(:blue,:bold)
"\e[34m\e[1mblue\e[0m".uncolor

Usage

There is a global switch SimpleColor.enabled to select the color mode. The possible values are

  • true: activate color output
  • false: desactivate all color output
  • :shell: activate color output for use in zsh prompt

When using a color escape sequence in a prompt in zsh, zsh will count the escape sequences as part of the length of a prompt. To mark them as non printable, one has to wrap them around %{ and %}. With SimpleColor.enabled=:shell this is done automatically by SimpleColor.

Requirements

None.

Install

$ gem install simplecolor

This installs v0.3.0, the current master version may not work.

When installing from git, you can regenerate the list of color names by running data/rgb_colors.rb.

TODO

  • Autodetect color capabilities (using COLORTERM)
  • Use terminfo settings when possible
  • Better color conversion (RGB is non linear)
  • Utilities to darken/lighten colors

Copyright

Copyright © 2013–2020 Damien Robert

MIT License. See LICENSE.txt for details.