Project

isna

0.0
No commit activity in last 3 years
No release in over 3 years
Easily compiles transforms a string into ansi code
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

isna¶ ↑

A very simple ANSI manipulation library, checkout the examples below:

Try it yourself.¶ ↑

require 'rubygems'
require 'isna'
"Hello World".to_ansi
"Hello World".to_ansi.red
puts "Hello World".to_ansi.red
puts "Hello World".to_ansi.underline.blue
puts "Hello World".to_ansi.blink.yellow
puts "Hello World".to_ansi.cyan
puts "Hello World".to_ansi.negative.cyan
puts "Hello World".to_ansi.green_background.yellow
puts "Hello World".to_ansi.green_background.bright.red
puts "Hello World".to_ansi.green_background.red
puts "Hello World".to_ansi.green_background.dark.red
# *bright* and *dark* only work when a background is applied.
puts "Normal String" + ' concatenated-with-a ' + "Ansi String".to_ansi.green.to_s

Support¶ ↑

I’ve just added the very basic types, but you should be able to extend it pretty easily, if you think those changes should be on the core-gem send them over and I’ll apply those for you. (and add your name in the credits section) :)

Colors¶ ↑

* black
* red
* green
* yellow
* blue
* pink
* cyan
* white

Backgrounds¶ ↑

* black_background
* red_background
* green_background
* yellow_background
* blue_background
* pink_background
* cyan_background
* white_background

Behaviours¶ ↑

* normal
* bright
* dark
* italic
* underline
* blink
* fast_blink
* negative

Custom changes¶ ↑

You can create custom ansi combos easily! In the following example am replicating the exact same behaviour that some in-library functions do. But I am in control and manually set every single value I want to change. Check out the example :)

Try it yourself.¶ ↑

require 'rubygems'
require 'isna'
"Hello World".to_ansi.change_type(5).change_background(44).change_color(33)
"Hello World".to_ansi.blue_background.blink.yellow
puts "Hello World".to_ansi.change_type(5).change_background(44).change_color(33)
puts "Hello World".to_ansi.blue_background.blink.yellow

Extending¶ ↑

Want to extend and create your own cool formated methods? Perhaps you want to add xterm colors +(255) colors would be great right? The snippet below shows an easy way to extend isna yet keeping a clean and organized separation of code, and its quite simple :)

Try it yourself.¶ ↑

require 'rubygems'
require 'isna'

module MySpecialExtension

  def blinky_blue_1
    change_type(5).change_background(44).change_color(33)
  end

  def blinky_blue_2
    blue_background.blink.yellow
  end

end

Isna::String.send(:include, MySpecialExtension)
"Hello World".to_ansi.blinky_blue_1
"Hello World".to_ansi.blinky_blue_2
puts "Hello World".to_ansi.blinky_blue_1
puts "Hello World".to_ansi.blinky_blue_2

Finally¶ ↑

If you are thinking about extending look at the internals of this library. Specially Behaviours, Colors, and Backgrounds it’ll give you a good idea on how to code/organize your extensions. :)

How much intrusion are you making on the String object??¶ ↑

This is all the code that isna uses to extend strings.

class String

  def to_ansi
    Isna::String.new(self)
  end

end

There are no overrides, no intrusion, and no posible collisions withing the Data Type Object. Isna tries to do all its hard work separately and play nice with other libraries :)

Why isna??¶ ↑

“isna” is “ansi” spelled backwards, but the gem name was already taken :S

Enjoy!¶ ↑