Color your terminal's output

Jens Mueller jens.k.mueller at
Thu Oct 6 13:53:50 PDT 2011


I started writing a simple module to color terminal output some time ago.
In a recent thread people seemed interested in having such
functionality. I cleaned up this code and kindly ask whether such a
module is considered a useful addition.

On Posix systems it uses 4 Curses functions and on Windows systems the
Windows API is used. I tested it on Linux (using different terminal
emulators) and on Windows XP.
It allows setting foreground and background colors and setting bold,
underline, reverse and blink font faces.

Get the code from

To test (hopefully filling your terminal with colored output) run
on Posix
32 bit
$ dmd -unittest -m32 /usr/lib/libncurses.a -run terminal.d
64 bit
$ dmd -unittest -m64 /usr/lib/libncurses.a -run terminal.d

(The library path may need to be adjusted.)

and on Windows
$ dmd -unittest -run terminal.d

At this point there are some issues that I need to figure out, namely:
* Is there a portable way to unset font face attributes on Posix?
* How to portably obtain the default foreground/background color on
* How to properly test such a module?
* Possible license problems: I have no idea whether it's allowed to link
  against whatever license (the curses implementation uses). In doubt I
  need to use the license that I link against, I suppose.

Any help is very appreciated.

Though this module is functionality-wise inferior to something like
ncurses it conveniently allows coloring output for most use cases.


More information about the Digitalmars-d mailing list