Next: Include files, Up: The programmer’s perspective [Contents][Index]
Source code that makes use of GNU libtextstyle needs an include statement:
#include <textstyle.h>
Basic use of GNU libtextstyle consists of statements like these:
styled_ostream_t stream = styled_ostream_create (STDOUT_FILENO, "(stdout)", TTYCTL_AUTO, style_file_name); ... styled_ostream_begin_use_class (stream, css_class); ... ostream_write_str (stream, string); ... styled_ostream_end_use_class (stream, css_class); ... styled_ostream_free (stream);
Before this snippet, your code needs to determine the name of the style
file to use (style_file_name
). If no styling is desired – the
precise condition depends on the value of color_mode
but also on
your application logic –, you should set style_file_name
to
NULL
.
An object of type styled_ostream_t
is allocated. The function
styled_ostream_create
allocates it; the function
styled_ostream_free
deallocates it.
Such styled_ostream_t
supports output operations
(ostream_write_str
), interleaved with adding and removing CSS
classes. The CSS class in effect when an output operation is performed
determines, through the style file, the text attributes associated with
that piece of text.