tags:

views:

168

answers:

5

I have a program that I run through the command line and I wanted to print out bold or styled text similar to how the man pages are bold (I can't think of a styled example offhand).

How do I style text sent to the terminal?

If it makes a difference, I'm running a MacOSX terminal.

+1  A: 

I believe you want to use the ncurses library to accomplish this.

Dave Markle
+1  A: 

You can have a look at this SO question: Colored grep? which shows a simple way to color output for VT100 terminals (works great on MacOSX)

epatel
+1  A: 

Another useful SO Question is: Apply formatting to unix shell, with a link to ANSI escape codes, and examples from a shell.

mouviciel
+1  A: 

You can do this from any shell script using the tput program to output terminfo codes. Oddly, there's a code to turn vold on but not off---you have to turn everything off. Reverse video can be turned on and off with tput smso and tput rmso.

Here's an example for bold (/bin/ksh):

print -n "This word is "; tput bold; print -n "bold"; tput sgr0; print "!"

In most programming languages it is easier to fork a process and call tput than it is to bother with the ncurses library (to which tput is a command-line interface).

Norman Ramsey
A: 

I have also found this link which was pretty handy.

Info about escape codes and a script to generate escape codes

Teifion
If this works for you, great, but be aware these may not work in all command terminals that you come across. The whole point of ncurses and tputs is to access a database of special codes for all the possible terminals on the planet. Less important now in this X world, but still good to know.
Shannon Nelson