I know many programs use color - (vim, ack, color-ls to name a few) but there are still many cases where you're stuck with black and white.
There are scripts that will color output based on regular expressions (i.e. "make anything that matches 'dog' red") but these must be invoked with pipes - for example: "> cat myfile | color dog red" and this is useless for anything interactive.
What I'm looking for is something that hooks the terminal emulator (or an terminal that actually does this) and colors anything that matches a given regex, independent of the shell or program i'm currently using. If this works with ncurses as well that would be awesome. I have too many monochrome programs and it would be great if I could specify a list of keywords to highlight/color when they appear or are typed.
I use Guake console which probably uses GNOME Terminal, I don't know if GNOME has this feature already.
Short version is: why, yes, you can pipe output from the shell, like any other program.
From there, you can use whatever you like, like, say
Thought I'd add my 'rainbow'. Enjoy:
I'm still looking for a linux terminal emulator with this feature, but for those reading this who are on macOS X:
^.*\[ERROR\].*$
and set the action to "Highlight text" and the parameter to something like "Red foreground".There are probably better solutions than this, but you may be able to work something simple out with expect: http://expect.nist.gov/. There are expect libraries available for many other programming/scripting languages if you would rather avoid TCL.
In general, TCL is used for automating interactive programs, but it is possible to make them interactive as well.
I'd give you some code to start with but I haven't used it in quite a while myself.
I do not have a solution but I have thought about how this kind of program should function. What you are asking is not straightforward.
For example, assume your regular expression is simple "flower". 1. If the terminal output is "f" "lower" we should perform the coloring. Or using an editor we first type "lower" and then go to the beginning of the word and type "f". 2. If the terminal output is "flower" we should cancel the already performed coloring. 3. If the output is slow, say five second delay between all the characters in "flower", we should not annoyingly stop the output, and should be able to immediately perform the coloring.
Either the functionality should be very tightly coupled with the terminal program (like you suggest), checking if any of the specified regular expressions matches the current line and then do the coloring. Or to make it more useful, we could use a program (little bit like /usr/bin/script) that acts like terminal device and keeps track of the screen output, for which it needs to know the terminal behavior very well; in this case we should also be able to redisplay the characters with different color (perform coloring and cancel already performed coloring).
You provide nice little programming idea...
I'm pretty sure KDE Konsole (at least the KDE3 version) could do this, however I don't see the support in KDE4.
You can do something with grep like this:
This should highlight matches but have so much context as to be the whole file.
urxvt with the matcher plugin has this feature, for example if you want to change the foreground of strings that look like movie ip addresses (4x3 digits with dots in between) you can have the following in your .Xdefaults:
and it will make that happen. You will need to add more things to it but it works.