Coder Social home page Coder Social logo

mikbe / term-ansicolor-hi Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 601 KB

Ruby library that colors strings using ANSI escape sequences. Exactly the same as term-ansicolor (http://flori.github.com/term-ansicolor) but includes the high intensity colors.

Home Page: http://mikbe.tk

License: GNU General Public License v2.0

Ruby 100.00%

term-ansicolor-hi's Introduction

== ANSI escape sequences in Ruby

Note:
The original author is not answering pull requests and I really needed high-intensity colors.  
This necessitated me renaming the library so I could publish a new one.  
All credit remains with Florian Frank.  

=== Description

This library can be used to color/decolor strings using ANSI escape sequences.

=== Installation

Just type into the command line as root:

# ruby install.rb

Or if you prefer using Rake, try:

# rake install

Or if you want to use rubygems just type this and rubygems fetches the gem and
installs it for you:

# gem install term-ansicolor-hi

=== Current Downloads and Links

For more current versions of unsupported software visit:

* http://mikbe.tk

The source code for this updated library can be found here

* https://github.com/mikbe/term-ansicolor-hi

=== Links to original version

The old version of this library can be found here

* http://www.ping.de/~flori

The homepage of the original library is

* http://flori.github.com/term-ansicolor

=== Examples

Additional to the two executables cdiff and decolor, the file
examples/example.rb in the source/gem-distribution shows how this library can
be used:

    require 'term/ansicolorhi'

    # Use this trick to work around namespace cluttering that
    # happens if you just include Term::ANSIColorHI:

    class Color
      extend Term::ANSIColorHI
    end

    # Begin Edit (Mike Bethany)
    
    # You don't just have to use print to get the colors. 
    # You can use the color attributes as standard Ruby string by adding
    # them and embedding them with other strings as you normally would:
    #
    c = Term::ANSIColorHI
    my_red_string = "#{c.red}I'm red!#{c.reset}"
    my_green_string = "#{c.green}I'm green!#{c.reset}"
    my_blue_string = "#{c.blue}I'm blue!#{c.reset}"

    # Then you can output them using the standard Ruby 'puts' command:
    puts my_red_string
    puts my_green_string
    puts my_blue_string
    
    # End edit

    print Color.red, Color.bold, "No Namespace cluttering:", Color.clear, "\n"
    print Color.green + "green" + Color.clear, "\n"
    print Color.on_red(Color.green("green")), "\n"
    print Color.yellow { Color.on_black { "yellow on_black" } }, "\n\n"

    # Or shortcut Term::ANSIColorHI by assignment:
    c = Term::ANSIColorHI

    print c.red, c.bold, "No Namespace cluttering (alternative):", c.clear, "\n"
    print c.green + "green" + c.clear, "\n"
    print c.on_red(c.green("green")), "\n"
    print c.yellow { c.on_black { "yellow on_black" } }, "\n\n"

    # Anyway, I don't define any of Term::ANSIColorHI's methods in this example
    # and I want to keep it short:
    include Term::ANSIColorHI

    print red, bold, "Usage as constants:", reset, "\n"
    print clear, "clear", reset, reset, "reset", reset,
      bold, "bold", reset, dark, "dark", reset,
      underscore, "underscore", reset, blink, "blink", reset,
      negative, "negative", reset, concealed, "concealed", reset, "|\n",
      black, "black", reset, red, "red", reset, green, "green", reset,
      yellow, "yellow", reset, blue, "blue", reset, magenta, "magenta", reset,
      cyan, "cyan", reset, white, "white", reset, "|\n",
      on_black, "on_black", reset, on_red, "on_red", reset,
      on_green, "on_green", reset, on_yellow, "on_yellow", reset,
      on_blue, "on_blue", reset, on_magenta, "on_magenta", reset,
      on_cyan, "on_cyan", reset, on_white, "on_white", reset, "|\n\n"

    print red, bold, "Usage as unary argument methods:", reset, "\n"
    print clear("clear"), reset("reset"), bold("bold"), dark("dark"),
      underscore("underscore"), blink("blink"), negative("negative"),
      concealed("concealed"), "|\n",
      black("black"), red("red"), green("green"), yellow("yellow"),
      blue("blue"), magenta("magenta"), cyan("cyan"), white("white"), "|\n",
      on_black("on_black"), on_red("on_red"), on_green("on_green"),#
      on_yellow("on_yellow"), on_blue("on_blue"), on_magenta("on_magenta"),
      on_cyan("on_cyan"), on_white("on_white"), "|\n\n"

    print red { bold { "Usage as block forms:" } }, "\n"
    print clear { "clear" }, reset { "reset" }, bold { "bold" },
      dark { "dark" }, underscore { "underscore" }, blink { "blink" },
      negative { "negative" }, concealed { "concealed" }, "|\n",
      black { "black" }, red { "red" }, green { "green" },
      yellow { "yellow" }, blue { "blue" }, magenta { "magenta" },
      cyan { "cyan" }, white { "white" }, "|\n",
      on_black { "on_black" }, on_red { "on_red" }, on_green { "on_green" },
      on_yellow { "on_yellow" }, on_blue { "on_blue" },
      on_magenta { "on_magenta" }, on_cyan { "on_cyan" },
      on_white { "on_white" }, "|\n\n"

    # Usage as Mixin into String or its Subclasses
    class String
      include Term::ANSIColorHI
    end

    print "Usage as String Mixins:".red.bold, "\n"
    print "clear".clear, "reset".reset, "bold".bold, "dark".dark,
      "underscore".underscore, "blink".blink, "negative".negative,
      "concealed".concealed, "|\n",
      "black".black, "red".red, "green".green, "yellow".yellow,
      "blue".blue, "magenta".magenta, "cyan".cyan, "white".white, "|\n",
      "on_black".on_black, "on_red".on_red, "on_green".on_green,
      "on_yellow".on_yellow, "on_blue".on_blue, "on_magenta".on_magenta,
      "on_cyan".on_cyan, "on_white".on_white, "|\n\n"

    symbols = Term::ANSIColorHI::attributes
    print red { bold { "All supported attributes = " } },
      blue { symbols.inspect }, "\n\n"

    print "Send symbols to strings:".send(:red).send(:bold), "\n"
    print symbols[12, 8].map { |c| c.to_s.send(c) }, "\n\n"

    print red { bold { "Make strings monochromatic again:" } }, "\n"
    print [
        "red".red,
        "not red anymore".red.uncolored,
        uncolored { "not red anymore".red },
        uncolored("not red anymore".red)
      ].map { |x| x + "\n" }

=== Version History

1.0.7 Changed ANSIColor to ANSIColorHI to avoid conflicts with apps using the Original ANSIColor class (like Cucumber)
1.0.6 Update to allow high intensity colors

=== Author

Florian Frank mailto:[email protected]

=== Minor update by 

Mike Bethany mailto:[email protected]

=== License

This is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License Version 2 as published by the Free
Software Foundation: www.gnu.org/copyleft/gpl.html

term-ansicolor-hi's People

Contributors

mikbe avatar shahor avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.