2

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.

Teifion
  • 108,121
  • 75
  • 161
  • 195

4 Answers4

3

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

Dave Markle
  • 95,573
  • 20
  • 147
  • 170
1

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)

Community
  • 1
  • 1
epatel
  • 45,805
  • 17
  • 110
  • 144
1

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

Community
  • 1
  • 1
mouviciel
  • 66,855
  • 13
  • 106
  • 140
1

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
  • 198,648
  • 61
  • 360
  • 533