Giter Club home page Giter Club logo

ansi's Introduction

ANSI

HOME · API · ISSUES · SOURCE

Build Status


The ANSI project is a collection of ANSI escape code related libraries enabling ANSI code based colorization and stylization of output. It is very nice for beautifying shell output.

This collection is based on a set of scripts spun-off from Ruby Facets. Included are Code (used to be ANSICode), Logger, ProgressBar and String. In addition the library includes Terminal which provides information about the current output device.

Features

  • ANSI::Code provides ANSI codes as module functions.
  • String#ansi makes common usage very easy and elegant.
  • ANSI::Mixin provides an alternative mixin (like +colored+ gem).
  • Very Good coverage of standard ANSI codes.
  • Additional clases for colorized columns, tables, loggers and more.

Synopsis

There are a number of modules and classes provided by the ANSI package. To get a good understanding of them it is best to pursue the QED documents or the API documentation.

At the heart of all the provided libraries lies the ANSI::Code module which defines ANSI codes as constants and methods. For example:

require 'ansi/code'

ANSI.red + "Hello" + ANSI.blue + "World"
=> "\e[31mHello\e[34mWorld"

Or in block form.

ANSI.red{ "Hello" } + ANSI.blue{ "World" }
=> "\e[31mHello\e[0m\e[34mWorld\e[0m"

The methods defined by this module are used throughout the rest of the system.

Installation

Bundler

Add the usual gem line to your project's Gemfile.

gem 'ansi'

And run then bundle command.

RubyGems

To install with RubyGems simply open a console and type:

$ sudo gem install ansi

Setup.rb (not recommended)

Local installation requires Setup.rb (gem install setup), then download the tarball package and type:

$ tar -xvzf ansi-1.0.0.tgz
$ cd ansi-1.0.0
$ sudo setup.rb all

Windows users use 'ruby setup.rb all'.

Release Notes

Please see HISTORY.md file.

License & Copyrights

Copyright (c) 2009 Rubyworks

This program is redistributable under the terms of the FreeBSD license.

Some pieces of the code are copyrighted by others.

See LICENSE.txt and NOTICE.md files for details.

ansi's People

Contributors

apotheon avatar deepj avatar grosser avatar junegunn avatar sixeight avatar trans avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ansi's Issues

Kudos

Hi guys,

Just wanted to give you a hat tip for a well written Notice file with all of the contained licenses.
Only change required is Highline's homepage moved to https://github.com/JEG2/highline.

All the best

Doesn't work under windows command line 6.0.6001

Actual colour codes are displayed throughout the command line:
←[33m ERROR←[0m testPasswordChange (1.50s)

I did notice that the RUBY_PLATFORM check to load Win32/Console/ANSI is looking for win32 in the string but my RUBY_PLATFORM = i386-mingw32

A deactivation flag or variable that can be set disabling it for all gems that require colours would be nice.

ANSI::Terminal fails to detect Windows

I am on Windows XP.

When I type:

require "ansi"
ANSI::Terminal.terminal_width

I have the message: No such file or directory - stty size

In https://github.com/rubyworks/ansi/blob/master/lib/ansi/terminal.rb, the code seems to require successively ansi/terminal/stty, ansi/terminal/curses, ansi/terminal/termios and ansi/terminal/win32 until one of these require does not raises.

I guess that stty is supposed to raise on Windows, to avoid using this library. However when I require manually ansi/terminal/stty, it does not raises.

In fact, when I read the code of ansi/terminal/stty I do not see anything that can raise on Windows (or on any platform).

Unable to run test or tasks

Please add some info the the readme on how to do this, standard would be bundle && bundle exec rake but that does not work...

Un-bold, or "normal" code?

I searched through the API but couldn't figure out how to display an ANSI "normal" weight code... for instance, after bolding, going back to normal. Is this implemented?

Inverse Closes colors

puts ANSI.yellow{ "Foo" + ANSI.invert{ "∙∙∙" } + "bar" }

You can see the bar at the end isn't yellow, but you'd expect it to be. I'm using invert to make whitespace visible in a text based game.

The actual output is:

"\e[33mFoo\e[7m∙∙∙\e[0mbar\e[0m"

Expected:

- "\e[33mFoo\e[7m∙∙∙\e[0mbar\e[0m"
+ "\e[33mFoo\e[7m∙∙∙\e[27mbar\e[0m"

05_27_15 at 12 30 22pm

Non-Color ANSI::Diff option

Now that ANSI::Diff is in the picture, the class is going to need an an alternate non-color version for when color needs to be turned off.

I figure rather than colors use underlining with "=" and "-" and maybe "^".

methods broken?

Why are all these methods broken?

> ANSI::Code.hex '000000'
NoMethodError: undefined method `rgb_value` for ANSI::Code:Module
> ANSI::Code.rgb(0,255,0)
NoMethodError: undefined method `rgb_value` for ANSI::Code:Module
> ANSI::Code.rgb_256(0,255,0)
NoMethodError: private method `rgb_256` called for ANSI::Code:Module
> ANSI::Code.send(:rgb_256, 0,255,0)
NoMethodError: undefined method `rgb_valid` for ANSI::Code:Module

win32console deprecated (windows)

First the issue, even with win32console I can't get colors on windows:

irb(main):001:0> require 'ansi/code'
ansi: 'gem install win32console' to use color on Windows

The reason is that win32console is deprecated (and does not load on recent ruby versions). The good news is that, to the best of the my knowledge, it is no longer needed in ruby 2.0+.

The fix is very simple: don't require 'win32console' when ruby version is 2.0+ (assuming I am not missing anything here).

I verified this by changing code.rb, line 9 to:
if RUBY_PLATFORM =~ /(win32|w32)/ && RUBY_VERSION < "2.0"
This seems to work fine for me.

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.