forked from tchernicum/bcapps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bc-ansi-color-fun.pl
executable file
·68 lines (56 loc) · 1.18 KB
/
bc-ansi-color-fun.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/perl
# silly prog to generate ansi color, etc sequences
%CODES=(
0,"All*attributes*OFF",
1,"Bold*ON",
4,"Underscore*ON",
5,"Blink*ON",
7,"Reverse*Video*ON",
8,"Concealed*ON",
30,"Black*FG",
31,"Red*FG",
32,"Green*FG",
33,"Yellow*FG",
34,"Blue*FG",
35,"Magenta*FG",
36,"Cyan*FG",
37,"White*FG",
40,"Black*BG",
41,"Red*BG",
42,"Green*BG",
43,"Yellow*BG",
44,"Blue*BG",
45,"Magenta*BG",
46,"Cyan*BG",
47,"White*BG",
"","nothing"
);
# bit string: (under)(blink)(revvid)(conceal)(fg-col)(fg-bold)(bg-col)(bg-bold)
for (;;) {
$m++;
$n=$m;
@a=();
if ($n&1==1) {push(@a,4);} # underscore
$n>>=1;
if ($n&1==1) {push(@a,5);} # blink
$n>>=1;
if ($n&1==1) {push(@a,7);} # revvid
$n>>=1;
if ($n&1==1) {push(@a,8);} # conceal
$n>>=1;
if ($n&1==1) {push(@a,1);} # fg bold
$n>>=1;
push(@a,30+($n&7)); # fg col
$n>>=3;
if ($n&1==1) {push(@a,1);} # bg bold
$n>>=1;
push(@a,40+($n&7)); # bg col
$n>>=3;
# if conditions below are met, back at 0 state
if ($a[0]==30 && $a[1]==40 && $#a==1) {exit;}
@b=();
for $i (@a) {push(@b,$CODES{$i});}
$str=join(";",@a);
$pri=join(", ",@b);
print "\e[${str}mThis line ($m) has the following codes: $pri\e[0m\n";
}