An open API service indexing awesome lists of open source software.

https://github.com/whiteleaf7/termcolorlight

lightweight version of TermColor
https://github.com/whiteleaf7/termcolorlight

Last synced: over 1 year ago
JSON representation

lightweight version of TermColor

Awesome Lists containing this project

README

          

# TermColorLight

This gem is library that convert color tags (e.g. `str` ) to
ansicolor(vt100 escape sequence). And this's lightweight version of
TermColor.gem without other gems. In addition process spedd is surprisingly fast.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'termcolorlight'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install termcolorlight

## Usage

```ruby
require "termcolorlight"

TermColorLight.parse("strings") # => \e[31mstrings\e[0m
"strings".termcolor # a ditto

str = "

container
"
"#{str.escape}".termcolor # => \e[1m\e[32m
container
\e[0m\e[1m\e[0m
```

```ruby
require "termcolorlight/html"
str = "

container
"
TermColorLight.to_html("#{str.escape}")
# => <div>container</div>
```

![HTML ScreenCapture](html_ss.png)

You can use the following tags.

```
# forground tags
black, red, green, yellow, blue, magenta, cyan, white, gray

# background tags
on_black, on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white, on_gray

# decorations
bold, dark, underline, underscore, blink, reverse, concealed
```

## Benchmark

### Code

```ruby
require "termcolor"
require "termcolorlight"
require "benchmark"

n = 100000
Benchmark.bm(20) do |bm|
bm.report "TermColor.parse" do
n.times do
TermColor.parse("red")
end
end
bm.report "TermColorLight.parse" do
n.times do
TermColorLight.parse("red")
end
end
end
```

### Results

> Performed by OSX.

Use ruby 2.0.0p451

```
user system total real
TermColor.parse 13.770000 5.830000 19.600000 ( 19.595587)
TermColorLight.parse 2.880000 0.010000 2.890000 ( 2.899383)
```

You could see that processing speed of TermColorLight is much faster
than TermColor's one.

Use ruby 2.2.0 (2014-08-20 trunk 47225 [x86_64-darwin13])

```
user system total real
TermColor.parse 12.960000 4.720000 17.680000 ( 17.674688)
TermColorLight.parse 0.850000 0.000000 0.850000 ( 0.853439)
```

Oops...

## Changelogs

### version 1.1.0 (2014/10/03)

+ add a method **TermColorLight.to_html**
- Perfect emuration of terminal

## Contributing

1. Fork it ( https://github.com/whiteleaf7/termcolorlight/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request