Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Using the less paginator, you can use the -r option to properly display colored input and the -S option to disable line wrap.

However, when using less -rS or equivalently less -r -S, colors are diplayed but lines are wrapped. How can this be achieved?

share|improve this question
2  
Specifying -R instead of -r might work for you. –  devnull Mar 3 at 8:36

2 Answers 2

up vote 5 down vote accepted

If the -r option doesn't work, maybe the -R option will do what you want:

-R or --RAW-CONTROL-CHARS

Like -r, but only ANSI "color" escape sequences are output in "raw" form. Unlike -r, the screen appearance is maintained correctly in most cases. ANSI "color" escape sequences are sequences of the form:

ESC [ ... m

where the "..." is zero or more color specification characters For the purpose of keeping track of screen appearance, ANSI color escape sequences are assumed to not move the cursor. You can make less think that characters other than "m" can end ANSI color escape sequences by setting the environment variable LESSANSIENDCHARS to the list of characters which can end a color escape sequence. And you can make less think that characters other than the standard ones may appear between the ESC and the m by setting the environment variable LESSANSIMIDCHARS to the list of characters which can appear.

share|improve this answer
    
Thank you! Actually this was meant to be a self-answered question (after a while I figured this out and wanted to share), but I've got too few reputation and -after letting me write the answer- it said I should wait 8 hours before posting... Never mind, my answer looked exately like yours –  Davide Mar 3 at 10:08
1  
As a side-note, this is similar to what git does: by default it uses less as its pager and invokes it with LESS=FRSX in the environment (just like less -FRSX) –  Davide Mar 3 at 10:14
    
@Davide, that's interesting about git, I always wondered why it behaved differently, never got around to investigating though. Thanks. –  Graeme Mar 3 at 10:25

I'm afraid you can't. From the man page:

Warning: when the -r option is used, less cannot keep track of the actual appearance of the screen (since this depends on how the screen responds to each type of control character). Thus, various display problems may result, such as long lines being split in the wrong place.

share|improve this answer
    
Indeed. While I do not use colors myself, I think they should be for syntax highlighting in an editor or file highlighting when running "ls". A UNIX file, traditionally, is an unmarked plain text file, and I personally do not see the point of having metainfo like the color of a given character in it. –  samiam Mar 3 at 8:37
    
@samiam, consider that less is [most?] often used to paginate command output, not just to display files. In my use case, I actually wanted to save a colorful git output for displaying it later, and with less -RS it worked smoothly –  Davide Mar 3 at 10:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.