Skip to content

Corsaair/ansilib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ansilib

A basic library to encode strings with ANSI escape codes to provide colors output in the terminal (Linux and Mac OS X).

Install

This AS3 library is meant to be used in the context of Redtamarin or other utilities like as3shebang.

We do not have yet a package manager for Redtamarin, so you will have to install "by hand" (eg. copy the right file at the right place).

Usage

ABC library

var ansilib:* = Domain.currentDomain.load( "ansilib.abc" );
trace( ansilib + " loaded"  ); //optional

import encoding.ansi.*;

//use any definitions of the ansi library

sources

Copy ansilib/src to your current AS3 project path.

In your main AS3 file

include "ansilib.as";

import encoding.ansi.*;

//use any definitions of the ansi library

Example

import encoding.ansi.*;

function testColors():void
{ 
	var name:String;
	var names:Array = colors.all();

	for( var i:uint = 0; i < names.length; i++ )
	{
		name = names[i];
		if( name == "black" )
		{
			trace( colorize( name, colors[ name ], backgrounds.white ) );
			continue;
		}

		trace( colorize( name, colors[ name ] ) );
	}
}

function testBackgrounds():void
{
	var name:String;
	var names:Array = backgrounds.all();

	for( var i:uint = 0; i < names.length; i++ )
	{
		name = names[i];
		if( name == "black" )
		{
			trace( colorize( name, backgrounds[ name ], colors.white ) );
			continue;
		}

		trace( colorize( name, backgrounds[ name ], colors.black ) );
	}
}

trace( "----" );
trace( "colors:" );
testColors();
trace( "----" );
trace( "" );

trace( "----" );
trace( "backgrounds:" );
testBackgrounds();
trace( "----" );
trace( "" );

It will look like this

screenshot

More examples

examples

See the wiki for the ANSI notation.