Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Display color output in less
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
qnx
l33t
l33t


Joined: 25 Jun 2002
Posts: 638
Location: Göteborg, Sweden

PostPosted: Sat Dec 14, 2002 10:14 pm    Post subject: Display color output in less Reply with quote

Hi! When I run
Code:
qpkg --help | less

the result I get is less readable... Something like:
Code:
ESC[0;01mUsage:
        ESC[36;01mqpkgESC[0;0m [ESC[0;01moptionsESC[0;0m] [ESC[33;01mpkgnameESC[
0;0m] [ESC[34;01m-gESC[33;01m groupESC[0;0m] [ESC[34;01m-fESC[33;01m <file>ESC[0
;0m|ESC[34;01m-fpESC[33;01m <patern>ESC[0;0m]
        ESC[36;01mqpkgESC[0;0m ESC[34;01m--dupsESC[0;0m [ESC[34;01m--slotESC[0;0
m]
        ESC[36;01mqpkgESC[0;0m ESC[34;01m--helpESC[0;0m

What can I do to display colors in less?? Or should I use another pager??
Cheers!
P.S. Of course, in this case I can just run qpkg with -nc atribut (no color). But I have this problem with other commands that do not support no-color-mode. Also, I hate to use more.
_________________
Registred Linux user #191143!
Abit NF7-S rev. 2.00 (BIOS v. 2.7)
AMD AthlonXP 2500+ (Barton)
PATA Seagate ST3120022A
SATA Seagate ST3200822AS & Silicon Image 3112 chipset
Gentoo Linux :)
Back to top
View user's profile Send private message
Pigeon
Guru
Guru


Joined: 21 Jun 2002
Posts: 307

PostPosted: Sat Dec 14, 2002 11:09 pm    Post subject: Reply with quote

Code:
qpkg --help|less -R
Back to top
View user's profile Send private message
qnx
l33t
l33t


Joined: 25 Jun 2002
Posts: 638
Location: Göteborg, Sweden

PostPosted: Sat Dec 14, 2002 11:10 pm    Post subject: Reply with quote

Thanks man!
_________________
Registred Linux user #191143!
Abit NF7-S rev. 2.00 (BIOS v. 2.7)
AMD AthlonXP 2500+ (Barton)
PATA Seagate ST3120022A
SATA Seagate ST3200822AS & Silicon Image 3112 chipset
Gentoo Linux :)
Back to top
View user's profile Send private message
carambola5
Apprentice
Apprentice


Joined: 10 Jul 2002
Posts: 214

PostPosted: Sun Dec 15, 2002 12:35 am    Post subject: Reply with quote

Code:
qpkg --help | more

fewer keystrokes :D
Back to top
View user's profile Send private message
joycea
Apprentice
Apprentice


Joined: 23 Jul 2002
Posts: 191
Location: Kingston, Canada

PostPosted: Sun Dec 15, 2002 2:38 am    Post subject: Reply with quote

To make it permanent you can alias less in your .bashrc file such as,
Code:

alias less="less -r"


or you can set the environment variable LESS, such as,

Code:

export LESS="-r"


Both of these will make the color option rather automatic.
Back to top
View user's profile Send private message
qnx
l33t
l33t


Joined: 25 Jun 2002
Posts: 638
Location: Göteborg, Sweden

PostPosted: Sun Dec 15, 2002 10:00 am    Post subject: Reply with quote

Yes, it's a good idea to alias less with -r. Thanks!
_________________
Registred Linux user #191143!
Abit NF7-S rev. 2.00 (BIOS v. 2.7)
AMD AthlonXP 2500+ (Barton)
PATA Seagate ST3120022A
SATA Seagate ST3200822AS & Silicon Image 3112 chipset
Gentoo Linux :)
Back to top
View user's profile Send private message
foxcub
Tux's lil' helper
Tux's lil' helper


Joined: 25 Jun 2002
Posts: 131
Location: North Carolina

PostPosted: Mon May 19, 2003 6:44 pm    Post subject: Reply with quote

Here is a follow up question. Why is "emerge -s phoenix" (or any other package) colorized, while "emerge -s phoenix | more" is not? And how can I colorize the later one?

Thanks.
Back to top
View user's profile Send private message
sekh
n00b
n00b


Joined: 20 Dec 2002
Posts: 55

PostPosted: Tue May 20, 2003 1:49 pm    Post subject: Reply with quote

sorry to bring back this thread from the dead :(

But does anyone know the answer to the question in the above post? i was wondering this myself?
Back to top
View user's profile Send private message
joycea
Apprentice
Apprentice


Joined: 23 Jul 2002
Posts: 191
Location: Kingston, Canada

PostPosted: Tue May 20, 2003 4:44 pm    Post subject: Reply with quote

I don't think either less or more are capable of displaying the colours, only stripping out the control characters. I don't know if there is going to be a simple solution to this problem, it may have to do with how less and more have to keep redrawing the display that they are discarded.
Back to top
View user's profile Send private message
PowerFactor
Veteran
Veteran


Joined: 30 Jan 2003
Posts: 1693
Location: out of it

PostPosted: Tue May 20, 2003 7:27 pm    Post subject: Reply with quote

foxcub wrote:
Here is a follow up question. Why is "emerge -s phoenix" (or any other package) colorized, while "emerge -s phoenix | more" is not?
I think it is something in emerge that checks if it's output is the terminal or a pipe I say this because qpkg still colorizes the output when piped or redirected, unless you specify the --nocolor option. I don't know if there is any way to change this without modifying emerge, nothing listed in the man page.

joycea, did you not read any of the previous posts? Both less and more can display color. :wink:
Back to top
View user's profile Send private message
foxcub
Tux's lil' helper
Tux's lil' helper


Joined: 25 Jun 2002
Posts: 131
Location: North Carolina

PostPosted: Tue May 20, 2003 11:17 pm    Post subject: Reply with quote

Is this worth submitting a bug report (to bugzilla)?
Back to top
View user's profile Send private message
sekh
n00b
n00b


Joined: 20 Dec 2002
Posts: 55

PostPosted: Wed May 21, 2003 12:12 pm    Post subject: Reply with quote

joycea: less is quite capable of displaying colors.... try for instance

Code:
qpkg --help | less -R

or
Code:
ls -l --color | less -R

should work

what powerfactor suggest about it checking what the output is sounds like a probable reason to me :) howver it would be nice to be able to do an
Code:
emerge -up system | less -R

when the update list is REALLY long :p
Back to top
View user's profile Send private message
BigBaaadBob
Guru
Guru


Joined: 19 Apr 2003
Posts: 342
Location: Swampscott, MA USA

PostPosted: Wed May 21, 2003 11:11 pm    Post subject: Reply with quote

I was going to post a bug report about this.

What typcally happens is that programs check to see whether the stdout is a tty, and if it isn't they (by default) turn off all fancy stuff like color. This still allows you to use color if you want, by specifying explicit options. The theory is that if the stdout isn't a tty then it is probably a pipeline where you want to deal with the raw data. An example would be:
Code:
qpkg -I | wc
where you don't want all the colorizing stuff to end up in the character count.

Qpkg also misbehaves when working into a pipeline like this:
Code:
spooky root # qpkg -l -nc emacs | less
/usr/bin/qpkg: line 478:  9635 Broken pipe             cat
/usr/bin/qpkg: line 478:  9632 Exit 141                if [ ! \( "${tcheck}" -o "${mcheck}" -o "${info}" -o "${list}" -o "${query}" -o ${verb} -gt 0 \) ]; then
    sed -e "s:-r[0-9]\+$::" -e "s:-[0-9][^-]*$::" | sort -k2 | uniq -1;
else
    if [ ! \( "${tcheck}" -o "${mcheck}" -o "${info}" -o "${list}" -o "${query}" -o ${verb} -lt 2 \) ]; then
        sort -k2 | uniq -1;
    else
        cat;
    fi;
fi
      9634 Broken pipe             | sed -e "s:^iii ${X}/${X}:${BR}\1/${CY}\2${STAR}${NO}:" -e "s:^uuu ${X}/${X}:${BR}\1/${YL}\2${NO}:" -e "s:^vvv \(.*\)$:${BL}\1${NO}:" -e "s:^obj ::;s:^sym ::;s:^dir ::"
/usr/bin/qpkg: line 478:  9641 Broken pipe             sed -e "s:\(^obj \)\([^ ]*\)\(.*$\):\1${BR}\2${NO}:;
                                        s:\(^sym \)\([^ ]*\)\( -> \)\([^ ]*\)\(.*$\):\1${CY}\2${NO}\3\4:;
                                        s:\(^dir \)\([^ ]*\)\(.*$\):\1${YL}\2${NO}:"
/usr/bin/qpkg: line 478:  9640 Broken pipe             cat $d/CONTENTS
s
What happened is I hit "q" in less.

As I said I was going to report it as a bug, but I wanted to take a crack at fixing it first. In my free time.... Riiiight...
Back to top
View user's profile Send private message
foxcub
Tux's lil' helper
Tux's lil' helper


Joined: 25 Jun 2002
Posts: 131
Location: North Carolina

PostPosted: Thu May 22, 2003 12:09 am    Post subject: Reply with quote

So in other words, both qpkg and emerge need an explicit "--color" option that would force the output to include the control characters even if it's going into the pipe; and without it both programs should check whether they are outputting into a tty, and based on that include or exclude the control information? Just trying to make sure I understood you correctly.
Back to top
View user's profile Send private message
BigBaaadBob
Guru
Guru


Joined: 19 Apr 2003
Posts: 342
Location: Swampscott, MA USA

PostPosted: Thu May 22, 2003 12:40 am    Post subject: Reply with quote

foxcub: Yup. I expressed it as deciding on the "default" option of color or nocolor based on whether or not stdout is a tty, but you said it just as well. :D
Back to top
View user's profile Send private message
_Vinz_
n00b
n00b


Joined: 22 Jan 2004
Posts: 20
Location: Vannes, France

PostPosted: Wed Feb 18, 2004 10:02 am    Post subject: Reply with quote

Hi,

I have been encountering the same problem. Is there any progress in that field before I post a bug report on Bugzilla to add a default --color option to emerge?

Vinz
Back to top
View user's profile Send private message
foxcub
Tux's lil' helper
Tux's lil' helper


Joined: 25 Jun 2002
Posts: 131
Location: North Carolina

PostPosted: Thu Feb 19, 2004 12:24 am    Post subject: Reply with quote

Not that I know of, so I'd file a bug report since I don't think anybody else has bothered to look at this problem, though, to be frank I have no clue.
Back to top
View user's profile Send private message
_Vinz_
n00b
n00b


Joined: 22 Jan 2004
Posts: 20
Location: Vannes, France

PostPosted: Thu Feb 19, 2004 7:45 am    Post subject: Reply with quote

Yo foxcub,

Thanks for the reply. Looking on the database, I found these related problems :
bugs #1006 and #5714. They are more or less ;) related to our problem.

Bug report filed in : https://bugs.gentoo.org/show_bug.cgi?id=42115

I'll let you know how it goes.

Vinz
Back to top
View user's profile Send private message
AVernon
n00b
n00b


Joined: 06 Mar 2004
Posts: 3
Location: Atlanta, GA

PostPosted: Wed Mar 31, 2004 3:04 am    Post subject: Reply with quote

On the subject of pagers check out most:

http://www.jedsoft.org/most/

It's similar to less with additional features.


The current ebuild is out of date. I filled a bug report for it:

https://bugs.gentoo.org/show_bug.cgi?id=46314
Back to top
View user's profile Send private message
devslashzero
n00b
n00b


Joined: 28 Feb 2012
Posts: 1

PostPosted: Tue Feb 28, 2012 4:53 pm    Post subject: Back from the dead Reply with quote

Wow, 2004... Well, emerge still doesn't do this by default, so I spent a long while accepting monochrome paged output until I found this thread and poked around the manpages for less and emerge. In case it helps someone else, the following is a working combination of the two:
Code:
emerge --color y | less

That is, less doesn't need -r or -R in this chain. The hint to emerge takes care of it.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum