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.