-
Notifications
You must be signed in to change notification settings - Fork 0
ANSI_notation
The ANSI notation is a bit like the markdown of the ANSI strings.
ANSI colors are nice but they come with some problems
- it depends on a library, without it your AS3 code will break.
- it is daunting, not practical and repetitive to use
colorize()
in the middle of your regular strings. - it will not work under Windows.
To remedy all those little problems we came with an "ANSI notation"
which look like that "Hello World「Y!* 」"
;
The idea is to allow you to implement a toANSIString()
method to your classes
without having a hard dependency on the ansilib.
It works like that, with "Hello World「Y!* 」"
,
is a notation that basically says "(regular string)「ANSI code」"
,
or apply this "sequence of ANSI code" to the preceding "string sequence".
The ANSI code sequences are contained within 「
and 」
,
and inside those separators, one character is equivalent to an ANSI escape code:
k
for colors.black
, !
for controls.bold
, etc.
character | ANSI escape code |
---|---|
「 | begin separator |
」 | end separator |
! | controls.bold |
_ | controls.underline |
* | controls.flash |
i | controls.invert |
? | controls.conceal |
" " | ignoreSpace = false |
k | colors.black |
r | colors.red |
g | colors.green |
y | colors.yellow |
b | colors.blue |
m | colors.magenta |
c | colors.cyan |
w | colors.white |
K | colors.brightBlack |
R | colors.brightRed |
G | colors.brightGreen |
Y | colors.brightYellow |
B | colors.brightBlue |
M | colors.brightMagenta |
C | colors.brightCyan |
W | colors.brightWhite |
0 | backgrounds.black |
1 | backgrounds.red |
2 | backgrounds.green |
3 | backgrounds.yellow |
4 | backgrounds.blue |
5 | backgrounds.magenta |
6 | backgrounds.cyan |
7 | backgrounds.white |
Code example
#!/usr/bin/as3shebang --
import shell.*;
var ansilib:* = Domain.currentDomain.load( "ansilib.abc" );
trace( ansilib + " loaded" );
import encoding.ansi.*;
var hello:* = new AnsiString( "hello world「Y!* 」" );
trace( hello );
var foobar:* = new AnsiString( "Hello World" );
foobar.altLetter( "b", "w" );
trace( foobar );
var barfoo:* = new AnsiString( "hello world" );
barfoo.altWord( "G", "R" );
trace( barfoo );
var logo:String = "";
logo += "\n";
logo += " █ \n";
logo += " █████ █ ██ █ █ ██ █ \n";
logo += " ██ ██ █ ██ ███████ ██ █ █ █ ██ \n";
logo += " █ ██ ██ █████ █████ ███████ ██████ █ ████ ██████ █ ████ ██ ████ \n";
logo += " ███ █ ██ ██ ██ ███ █ ██ ███ █████ █ █ ██ ████ █ ████ ██ \n";
logo += " ███████ ███████ █ ██ █ ██ ██ ██ ███ ████ ██ ██ █ ██ █ \n";
logo += " ████ ████ █ ██ █ ██ ██ ██ █ ████ ██ ██ █ ██ █ ██ \n";
logo += " ██ ███ ████ █ ██████ ██ ███████ ██ █ █ ██ ██████ █ █ ██ ██ \n";
logo += " █ ██ ████ █████ █ ██ ████ █ █ █ ██ ███ █ █ █ █ ██ \n";
logo += " █ ";
var redtamarin:* = new AnsiString( logo );
redtamarin.altLine( "M", "C" );
trace( redtamarin );
var logo2:String = "";
logo2 += "\n";
logo2 += " █「R 」 \n";
logo2 += " █████ █「R 」 ██ █ █ ██ █ 「Y 」\n";
logo2 += " ██ ██ █ ██「R 」 ███████ ██ █ █ █ ██ 「y 」\n";
logo2 += " █ ██ ██ █████ █████「R 」 ███████ ██████ █ ████ ██████ █ ████ ██ ████ 「Y 」\n";
logo2 += " ███ █ ██ ██ ██ ███「R 」 █ ██ ███ █████ █ █ ██ ████ █ ████ ██ 「y 」\n";
logo2 += " ███████ ███████ █ ██「R 」 █ ██ ██ ██ ███ ████ ██ ██ █ ██ █ 「Y 」\n";
logo2 += " ████ ████ █ ██「R 」 █ ██ ██ ██ █ ████ ██ ██ █ ██ █ ██ 「y 」\n";
logo2 += " ██ ███ ████ █ ██████「R 」 ██ ███████ ██ █ █ ██ ██████ █ █ ██ ██ 「Y 」\n";
logo2 += " █ ██ ████ █████ █「R 」 ██ ████ █ █ █ ██ ███ █ █ █ █ ██ 「y 」\n";
logo2 += " █「R 」 ";
var ansi_logo2:* = new AnsiString( logo2 );
trace( ansi_logo2 );
var message:String = "";
message += "Mission Statement「W!_ 」\n";
message += "To support the use of the 「K 」AS3 language「Y! 」 for 「K 」cross-platform「R 」 command-line「M 」 executable「G 」,「K 」\n";
message += "as 「K 」single exe「r_ 」 either for the「K 」 desktop「G7i」 or「Ki」 the「K 」 server「R7i」,「K 」\n";
message += "as 「K 」scripts「b* 」 for 「K 」automation「y_」,「K 」\n";
message += "as 「K 」tools「B7!i 」 for the 「K 」Flash Platform「W!1 」 community「W!」.「K 」\n";
trace( new AnsiString( message ) );
will gives the following output