Register
It is currently Sat Dec 20, 2014 7:59 am

piping a text file through a script to convert ansi colors


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Sun Nov 18, 2007 8:48 am   

Joined: Sun Nov 18, 2007 8:28 am
Posts: 6
I've seen a few ansi color scripts but I was hoping to find one to change the ansi color of a simple text file through redirection preferably using sed.

For example: I would direct
cat somefile | colors -bg=blue -fg=white > bluesomefile

and the original file would have it's ansi colors converted.

Code:
#!/bin/bash
for i in $(cat somefile); do
       echo -e '\E[37;44m'"\033[1m$i\033[0m"
done

It is a start, but I would like to be able to direct standard out through it. This also completely destroys ascii art.
For example I would like to take the output from figlet or toilet and pipe it through this script to change colors.

I've seen this function:

Code:

#!/bin/sh

#f foreground colors
#b background colors

initializeANSI()
{
esc="\033" #if this doesn't work enter esc manually

blackf="{$esc}[30m";   redf="{$esc}[31m";      greenf="{$esc}[32m";
yellowf="{$esc}[33m";  bluef="{$esc}[34m";     purplef="{$esc}[35m";
cyanf="{$esc}[36m";    whitef="{$esc}[37m";

blackb="{$esc}[40m";   redb="{$esc}[41m";      greenb="{$esc}[42m";
yellowb="{$esc}[43m";  blueb="{$esc}[44m";     purpleb="{$esc}[45m";
cyanb="{$esc}[46m";    whiteb="{$esc}[47m";

boldon="{$esc}[1m";    boldoff="{$esc}[22m";
italicson="{$esc}[3m"; italicsoff="{$esc}[23m";
ulon="{$esc}[4m";      uloff="{$esc}[24m";
invon="{$esc}[7m";     invoff="{$esc}[27m";
blinkon="{$esc}[5m";   blinkoff="{$esc}[25m";

reset="{$esc}[0m";
}


but I'm unsure on how to implement it.


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP