Life seems dull with no colors. Curses has a nice mechanism to handle colors. Let’s get into the thick of things with a small program.
#!/usr/bin/guile !# (use-modules (ncurses curses)) (define stdscr (initscr)) (if (has-colors?) (begin (start-color!) (init-pair! 1 COLOR_GREEN COLOR_YELLOW) (attr-on! stdscr (logior A_BOLD (color-pair 1))) (addstr stdscr "Voila!! In color...") (refresh stdscr) (sleep 3) (endwin) 0) (begin (endwin) (display "Your terminal does not support color") 1))
As you can see, to start using color, you should first call
start-color!. After that you can use color capabilities of your
terminal. To find out whether a terminal has color capabilities or
not, you can use
has-colors?, which returns
#f if the
terminal does not support color.
Curses initializes all the color support for the terminal when
start-color! is called. Usually, a color terminal will have at
least eight colors available that can be accessed by constants like
COLOR_BLACK, etc. Now to actually start using colors, you
have to define pairs. Colors are always used in pairs. That means
you have to use the function
init-pair! to define the foreground
and background for the pair number you give. After that, that pair
number can be used as a normal attribute with the
procedure. This may seem to be cumbersome at first.
The following colors are defined. You can use these as parameters for the various color functions.