1 /* Output stream for attributed text, producing ANSI escape sequences.
2 Copyright (C) 2006 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2006.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #ifndef _TERM_OSTREAM_H
19 #define _TERM_OSTREAM_H
24 /* Querying and setting of text attributes.
25 The stream has a notion of the current text attributes; they apply
26 implicitly to all following output. The attributes are automatically
27 reset when the stream is closed.
28 Note: Not all terminal types can actually render all attributes adequately.
29 For example, xterm cannot render POSTURE_ITALIC nor the combination of
30 WEIGHT_BOLD and UNDERLINE_ON. */
32 /* Colors are represented by indices >= 0 in a stream dependent format. */
33 typedef int term_color_t;
34 /* The value -1 denotes the default (foreground or background) color. */
37 COLOR_DEFAULT = -1 /* unknown */
44 WEIGHT_DEFAULT = WEIGHT_NORMAL
50 POSTURE_ITALIC, /* same as oblique */
51 POSTURE_DEFAULT = POSTURE_NORMAL
58 UNDERLINE_DEFAULT = UNDERLINE_OFF
61 struct term_ostream : struct ostream
65 /* Convert an RGB value (red, green, blue in [0..255]) to a color, valid
66 for this stream only. */
67 term_color_t rgb_to_color (term_ostream_t stream,
68 int red, int green, int blue);
70 /* Get/set the text color. */
71 term_color_t get_color (term_ostream_t stream);
72 void set_color (term_ostream_t stream, term_color_t color);
74 /* Get/set the background color. */
75 term_color_t get_bgcolor (term_ostream_t stream);
76 void set_bgcolor (term_ostream_t stream, term_color_t color);
78 /* Get/set the font weight. */
79 term_weight_t get_weight (term_ostream_t stream);
80 void set_weight (term_ostream_t stream, term_weight_t weight);
82 /* Get/set the font posture. */
83 term_posture_t get_posture (term_ostream_t stream);
84 void set_posture (term_ostream_t stream, term_posture_t posture);
86 /* Get/set the text underline decoration. */
87 term_underline_t get_underline (term_ostream_t stream);
88 void set_underline (term_ostream_t stream,
89 term_underline_t underline);
98 /* Create an output stream referring to the file descriptor FD.
99 FILENAME is used only for error messages.
100 The resulting stream will be line-buffered.
101 Note that the resulting stream must be closed before FD can be closed. */
102 extern term_ostream_t term_ostream_create (int fd, const char *filename);
109 #endif /* _TERM_OSTREAM_H */