Reputation: 21
Hi I am trying to print colored text in terminal as well as in file also, I am using "tee" command to print the contents in terminal has to be printed in file. But I am not able to print colored text in file, but in terminal i can print colored texts
Here is my code:
#!usr/bin/perl
use Data::Dumper qw(Dumper);
use Cwd;
use Term::ANSIColor qw(:constants);
local $Term::ANSIColor::AUTORESET = 1;
open( STDOUT, "| tee -ai report.txt" );
print BOLD RED "Here your texts are colored\n";
I am able to print "Here your texts are colored" in BOLD RED, but same thing i am not able to print in report.txt, if i open the report.txt i am getting [0m[0m[1m[32m Here your texts are colored
Please help me to solve this
thanks in advance
Upvotes: 1
Views: 414
Reputation: 69314
There's nothing to solve. You program is working as expected.
The ANSI colour codes are just characters. Your ANSI terminal is configured to look for these sequences of characters and to change the colour of the text when it sees them. Whatever software you are using to view your file has no such feature.
In general, there is no way to encode colour in a plain text file in such a way that the colour is displayed in any software that is used to view the file.
In order for us to help, you need to explain a little more. Why do you want coloured text in your text file?
Upvotes: 2