1 /* Test for the term-ostream API. */
5 #include "term-ostream.h"
13 static struct { const char *name; term_color_t c; int r; int g; int b; }
16 { "black", -2, 0, 0, 0 },
17 { "blue", -2, 0, 0, 255 },
18 { "green", -2, 0, 255, 0 },
19 { "cyan", -2, 0, 255, 255 },
20 { "red", -2, 255, 0, 0 },
21 { "magenta", -2, 255, 0, 255 },
22 { "yellow", -2, 255, 255, 0 },
23 { "white", -2, 255, 255, 255 },
24 { "default", COLOR_DEFAULT }
26 term_ostream_t stream;
29 stream = term_ostream_create (1, "stdout");
31 for (i = 0; i < 8; i++)
33 term_ostream_rgb_to_color (stream, colors[i].r, colors[i].g, colors[i].b);
35 ostream_write_str (stream, "Colors (foreground/background):\n");
36 ostream_write_str (stream, " ");
37 for (col = 0; col <= 8; col++)
39 const char *name = colors[col].name;
40 ostream_write_str (stream, "|");
41 ostream_write_str (stream, name);
42 ostream_write_mem (stream, " ", 7 - strlen (name));
44 ostream_write_str (stream, "\n");
45 for (row = 0; row <= 8; row++)
47 const char *name = colors[row].name;
48 ostream_write_str (stream, name);
49 ostream_write_mem (stream, " ", 7 - strlen (name));
50 for (col = 0; col <= 8; col++)
52 term_color_t row_color = colors[row].c;
53 term_color_t col_color = colors[col].c;
55 ostream_write_str (stream, "|");
56 term_ostream_set_color (stream, row_color);
57 term_ostream_set_bgcolor (stream, col_color);
58 if (!(term_ostream_get_color (stream) == row_color
59 && term_ostream_get_bgcolor (stream) == col_color))
61 ostream_write_str (stream, " Words ");
62 term_ostream_set_color (stream, COLOR_DEFAULT);
63 term_ostream_set_bgcolor (stream, COLOR_DEFAULT);
64 if (!(term_ostream_get_color (stream) == COLOR_DEFAULT
65 && term_ostream_get_bgcolor (stream) == COLOR_DEFAULT))
68 ostream_write_str (stream, "\n");
70 ostream_write_str (stream, "\n");
72 ostream_write_str (stream, "Colors (hue/saturation):\n");
73 /* Hue from 0 to 1. */
74 for (row = 0; row <= 17; row++)
76 for (col = 0; col <= 64; col++)
79 int b = (int) (255.0f / 64.0f * col + 0.5f);
80 int g = b + (int) (row / 17.0f * (r - b) + 0.5f);
81 term_color_t c = term_ostream_rgb_to_color (stream, r, g, b);
82 term_ostream_set_bgcolor (stream, c);
83 ostream_write_str (stream, " ");
84 term_ostream_set_bgcolor (stream, COLOR_DEFAULT);
86 ostream_write_str (stream, "\n");
88 /* Hue from 1 to 2. */
89 for (row = 17; row >= 0; row--)
91 for (col = 0; col <= 64; col++)
94 int b = (int) (255.0f / 64.0f * col + 0.5f);
95 int r = b + (int) (row / 17.0f * (g - b) + 0.5f);
96 term_color_t c = term_ostream_rgb_to_color (stream, r, g, b);
97 term_ostream_set_bgcolor (stream, c);
98 ostream_write_str (stream, " ");
99 term_ostream_set_bgcolor (stream, COLOR_DEFAULT);
101 ostream_write_str (stream, "\n");
103 /* Hue from 2 to 3. */
104 for (row = 0; row <= 17; row++)
106 for (col = 0; col <= 64; col++)
109 int r = (int) (255.0f / 64.0f * col + 0.5f);
110 int b = r + (int) (row / 17.0f * (g - r) + 0.5f);
111 term_color_t c = term_ostream_rgb_to_color (stream, r, g, b);
112 term_ostream_set_bgcolor (stream, c);
113 ostream_write_str (stream, " ");
114 term_ostream_set_bgcolor (stream, COLOR_DEFAULT);
116 ostream_write_str (stream, "\n");
118 /* Hue from 3 to 4. */
119 for (row = 17; row >= 0; row--)
121 for (col = 0; col <= 64; col++)
124 int r = (int) (255.0f / 64.0f * col + 0.5f);
125 int g = r + (int) (row / 17.0f * (b - r) + 0.5f);
126 term_color_t c = term_ostream_rgb_to_color (stream, r, g, b);
127 term_ostream_set_bgcolor (stream, c);
128 ostream_write_str (stream, " ");
129 term_ostream_set_bgcolor (stream, COLOR_DEFAULT);
131 ostream_write_str (stream, "\n");
133 /* Hue from 4 to 5. */
134 for (row = 0; row <= 17; row++)
136 for (col = 0; col <= 64; col++)
139 int g = (int) (255.0f / 64.0f * col + 0.5f);
140 int r = g + (int) (row / 17.0f * (b - g) + 0.5f);
141 term_color_t c = term_ostream_rgb_to_color (stream, r, g, b);
142 term_ostream_set_bgcolor (stream, c);
143 ostream_write_str (stream, " ");
144 term_ostream_set_bgcolor (stream, COLOR_DEFAULT);
146 ostream_write_str (stream, "\n");
148 /* Hue from 5 to 6. */
149 for (row = 17; row >= 0; row--)
151 for (col = 0; col <= 64; col++)
154 int g = (int) (255.0f / 64.0f * col + 0.5f);
155 int b = g + (int) (row / 17.0f * (r - g) + 0.5f);
156 term_color_t c = term_ostream_rgb_to_color (stream, r, g, b);
157 term_ostream_set_bgcolor (stream, c);
158 ostream_write_str (stream, " ");
159 term_ostream_set_bgcolor (stream, COLOR_DEFAULT);
161 ostream_write_str (stream, "\n");
163 ostream_write_str (stream, "\n");
165 ostream_write_str (stream, "Weights:\n");
166 term_ostream_set_weight (stream, WEIGHT_NORMAL);
167 if (term_ostream_get_weight (stream) != WEIGHT_NORMAL)
169 ostream_write_str (stream, "normal, ");
170 term_ostream_set_weight (stream, WEIGHT_BOLD);
171 if (term_ostream_get_weight (stream) != WEIGHT_BOLD)
173 ostream_write_str (stream, "bold, ");
174 term_ostream_set_weight (stream, WEIGHT_DEFAULT);
175 if (term_ostream_get_weight (stream) != WEIGHT_DEFAULT)
177 ostream_write_str (stream, "default \n");
178 ostream_write_str (stream, "\n");
180 ostream_write_str (stream, "Postures:\n");
181 term_ostream_set_posture (stream, POSTURE_NORMAL);
182 if (term_ostream_get_posture (stream) != POSTURE_NORMAL)
184 ostream_write_str (stream, "normal, ");
185 term_ostream_set_posture (stream, POSTURE_ITALIC);
186 if (term_ostream_get_posture (stream) != POSTURE_ITALIC)
188 ostream_write_str (stream, "italic, ");
189 term_ostream_set_posture (stream, POSTURE_DEFAULT);
190 if (term_ostream_get_posture (stream) != POSTURE_DEFAULT)
192 ostream_write_str (stream, "default \n");
193 ostream_write_str (stream, "\n");
195 ostream_write_str (stream, "Text decorations:\n");
196 term_ostream_set_underline (stream, UNDERLINE_OFF);
197 if (term_ostream_get_underline (stream) != UNDERLINE_OFF)
199 ostream_write_str (stream, "normal, ");
200 term_ostream_set_underline (stream, UNDERLINE_ON);
201 if (term_ostream_get_underline (stream) != UNDERLINE_ON)
203 ostream_write_str (stream, "underlined, ");
204 term_ostream_set_underline (stream, UNDERLINE_DEFAULT);
205 if (term_ostream_get_underline (stream) != UNDERLINE_DEFAULT)
207 ostream_write_str (stream, "default \n");
208 ostream_write_str (stream, "\n");
210 ostream_free (stream);