Gentoo Archives: gentoo-user

From: Mick <michaelkintzios@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] How do I turn off ansi (colour) codes in ... script output
Date: Sat, 03 Jun 2017 08:52:44
Message-Id: 9980750.Uv5VB8igHJ@dell_xps
In Reply to: Re: [gentoo-user] How do I turn off ansi (colour) codes in ... script output by "Toralf Förster"
1 On Saturday 03 Jun 2017 10:37:46 Toralf Förster wrote:
2 > On 06/03/2017 01:06 AM, Mick wrote:
3 > > Hi All,
4 > >
5 > > Walter had posted a message about ANSI codes showing up in portage output.
6 > > I am getting the same when I run /usr/bin/script and examine the
7 > > contents of the resultant file with a text editor; e.g. in Vim I get:
8 > >
9 > > ^[[0;32m~ ^[[35m$ ^[[0mtest^H^[[K^H^[[K^H^[[K^H^[[Kecho
10 > > S^H^[[K|^H^[[K$term^M
11 > >
12 > > but when I use less I can see:
13 > >
14 > > ~ $ echo $TERM
15 > >
16 > > Is there a way of suppressing these characters in gedit, kwrite, vim,
17 > > etc.?
18
19 Reading this again in the cold light of day, coffee helped too, it seems as if
20 I want to strip ANSI colours in these particular applications above, but I
21 don't. I want to suppress colours in what the script command captures in a
22 terminal.
23
24
25 > Well, one solution could be to use something like this :
26 >
27 > # strip away escape sequences
28 > # hint: colorstrip() doesn't modify its argument, instead it returns the
29 > result
30 > #
31 > function stresc() {
32 > perl -MTerm::ANSIColor=colorstrip -nle '
33 > $_ = colorstrip($_);
34 > s,\r,\n,g;
35 > s/\x00/<0x00>/g;
36 > s/\x1b\x28\x42//g;
37 > s/\x1b\x5b\x4b//g;
38 > print;
39 > '
40 > }
41 >
42 >
43 > This works fine here since a while
44
45 Where do you put the above, or how to you use it?
46 --
47 Regards,
48 Mick

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies