11

This is in my top 10 list of tiny annoying things in Linux. I love colored output in terminals: it's nice to see and useful when reading.

The first thing I do on a new system is to set aliases for both ls and grep to show colored output, and the second is to install vim and htop.

I use both Gentoo and Ubuntu, and I see that emerge, the package manager of Gentoo, has a higher readability than apt-get/aptitude just because it uses way much more color output than the latter.

So, whenever I have to pipe an emerge command with more, all the color is lost and I have to focus my attention on every line to avoid missing anything important.

I can understand that a basic command such as more shouldn't depend on ncurses (someone could argue that we also have less, so one of the two could be even color-friendly), but why there isn't a famous alternative to more that supports colors, as there is for vi/vim, top/htop etc.?

Thanks for any hint.

Avio
  • 2,700
  • 6
  • 30
  • 50
  • Oops, [you are right](http://superuser.com/questions/36022/less-and-grep-color). But this works only with `ls` and `grep`. And for other color-enabled commands like `emerge`? – Avio May 27 '12 at 20:34
  • [... What about it?](http://stackoverflow.com/questions/4233808/piping-data-to-linux-program-which-expects-a-tty-terminal) – Ignacio Vazquez-Abrams May 27 '12 at 20:38
  • I'm sorry, I don't get how `unbuffer` works. Can you please provide an example with `ls`, it seems interesting... – Avio May 27 '12 at 20:56
  • 1
    `more` does support color, and it has nothing to do with ncurses. Try: `printf '\033[31mfoo\033[0;37m\n' | more` – William Pursell May 28 '12 at 16:11

1 Answers1

20

Most commands that can output color have an option to choose between:

  • ON: Always output color
  • OFF: Never output color
  • AUTO: Show color if and only if the output is a terminal

Many commands work automatically in color AUTO mode. That is the case for emerge. And that is why you do not have color when you pipe the output: the pioe is not a terminal.

The solution is to tell emerge to output the colors unconditionally. And tell less not to filter them, of course.

Try:

emerge --color y | less -R
Meetai.com
  • 6,622
  • 3
  • 31
  • 38
rodrigo
  • 94,151
  • 12
  • 143
  • 190
  • 2
    @Avio - BTW, you can set `-R` into the `LESS` environment variable. That with `alias grep='grep --color=always'` and `alias ls='ls --color=always'` works beautifully. – rodrigo May 27 '12 at 20:55
  • Ok, thank you, I'll do it! Honestly I almost never used `less`, I always thought it was a mere alternative to `more`. Now you'll tell that even `nano` supports colors? :) – Avio May 27 '12 at 21:00
  • 1
    @Avio - Of course! `nano -Y c test.c`. You still have to tweak your `nanorc` file to include the `c.nanorc` or whatever syntaxes you want to enable. But that would be another question... – rodrigo May 27 '12 at 21:11
  • 2
    Avio - Actually `more` will always show the colors if they are present in the input. The nicest things about `less` IMO are not colors, but that you can navigate the ouput and do searches (with '/'). – rodrigo May 27 '12 at 21:14
  • Wow, even `nano` has colors! It seems that I blacklisted in my mind too many commands. I suppose I'll have to give them another chance. Yes I think you're right, I'll force myself to use `less` instead of `more` and search text with it. Thank you for all the advices! – Avio May 27 '12 at 21:46
  • Thanks a lot! `do not have color when you pipe the output: the pipe is not a terminal`. I didn't have this concept before. – Puspam Jun 30 '22 at 13:11