00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "terminal_tools/print.h"
00038
00040
00046 void
00047 terminal_tools::change_text_color (FILE *stream, int attribute, int fg, int bg)
00048 {
00049 char command[13];
00050
00051 sprintf (command, "%c[%d;%d;%dm", 0x1B, attribute, fg + 30, bg + 40);
00052 fprintf (stream, "%s", command);
00053 }
00054
00056
00061 void
00062 terminal_tools::change_text_color (FILE *stream, int attribute, int fg)
00063 {
00064 char command[13];
00065
00066 sprintf (command, "%c[%d;%dm", 0x1B, attribute, fg + 30);
00067 fprintf (stream, "%s", command);
00068 }
00069
00071
00074 void
00075 terminal_tools::reset_text_color (FILE *stream)
00076 {
00077 char command[13];
00078
00079 sprintf (command, "%c[0;m", 0x1B);
00080 fprintf (stream, "%s", command);
00081 }
00082
00084
00090 void
00091 terminal_tools::print_color (FILE *stream, int attr, int fg, const char *format, ...)
00092 {
00093 change_text_color (stream, attr, fg);
00094 va_list ap;
00095
00096 va_start (ap, format);
00097 vfprintf (stream, format, ap);
00098 va_end (ap);
00099
00100 reset_text_color (stream);
00101 }
00102
00104
00107 void
00108 terminal_tools::print_info (const char *format, ...)
00109 {
00110 reset_text_color (stdout);
00111
00112 va_list ap;
00113
00114 va_start (ap, format);
00115 vfprintf (stdout, format, ap);
00116 va_end (ap);
00117 }
00118
00120
00124 void
00125 terminal_tools::print_info (FILE *stream, const char *format, ...)
00126 {
00127 reset_text_color (stream);
00128
00129 va_list ap;
00130
00131 va_start (ap, format);
00132 vfprintf (stream, format, ap);
00133 va_end (ap);
00134 }
00135
00137
00140 void
00141 terminal_tools::print_highlight (const char *format, ...)
00142 {
00143 change_text_color (stdout, TT_BRIGHT, TT_GREEN);
00144 fprintf (stdout, "> ");
00145 reset_text_color (stdout);
00146
00147 va_list ap;
00148
00149 va_start (ap, format);
00150 vfprintf (stdout, format, ap);
00151 va_end (ap);
00152 }
00153
00155
00159 void
00160 terminal_tools::print_highlight (FILE *stream, const char *format, ...)
00161 {
00162 change_text_color (stream, TT_BRIGHT, TT_GREEN);
00163 fprintf (stream, "> ");
00164 reset_text_color (stream);
00165
00166 va_list ap;
00167
00168 va_start (ap, format);
00169 vfprintf (stream, format, ap);
00170 va_end (ap);
00171 }
00172
00174
00177 void
00178 terminal_tools::print_error (const char *format, ...)
00179 {
00180 change_text_color (stderr, TT_RESET, TT_RED);
00181 va_list ap;
00182
00183 va_start (ap, format);
00184 vfprintf (stderr, format, ap);
00185 va_end (ap);
00186
00187 reset_text_color (stderr);
00188 }
00189
00191
00195 void
00196 terminal_tools::print_error (FILE *stream, const char *format, ...)
00197 {
00198 change_text_color (stream, TT_RESET, TT_RED);
00199 va_list ap;
00200
00201 va_start (ap, format);
00202 vfprintf (stream, format, ap);
00203 va_end (ap);
00204
00205 reset_text_color (stream);
00206 }
00207
00209
00212 void
00213 terminal_tools::print_warn (const char *format, ...)
00214 {
00215 change_text_color (stderr, TT_RESET, TT_YELLOW);
00216 va_list ap;
00217
00218 va_start (ap, format);
00219 vfprintf (stderr, format, ap);
00220 va_end (ap);
00221
00222 reset_text_color (stderr);
00223 }
00224
00226
00230 void
00231 terminal_tools::print_warn (FILE *stream, const char *format, ...)
00232 {
00233 change_text_color (stream, TT_RESET, TT_YELLOW);
00234 va_list ap;
00235
00236 va_start (ap, format);
00237 vfprintf (stream, format, ap);
00238 va_end (ap);
00239
00240 reset_text_color (stream);
00241 }
00242
00244
00247 void
00248 terminal_tools::print_value (const char *format, ...)
00249 {
00250 change_text_color (stdout, TT_RESET, TT_CYAN);
00251 va_list ap;
00252
00253 va_start (ap, format);
00254 vfprintf (stdout, format, ap);
00255 va_end (ap);
00256
00257 reset_text_color (stdout);
00258 }
00259
00261
00265 void
00266 terminal_tools::print_value (FILE *stream, const char *format, ...)
00267 {
00268 change_text_color (stream, TT_RESET, TT_CYAN);
00269 va_list ap;
00270
00271 va_start (ap, format);
00272 vfprintf (stream, format, ap);
00273 va_end (ap);
00274
00275 reset_text_color (stream);
00276 }
00277
00279
00282 void
00283 terminal_tools::print_debug (const char *format, ...)
00284 {
00285 change_text_color (stdout, TT_RESET, TT_GREEN);
00286 va_list ap;
00287
00288 va_start (ap, format);
00289 vfprintf (stdout, format, ap);
00290 va_end (ap);
00291
00292 reset_text_color (stdout);
00293 }
00294
00296
00300 void
00301 terminal_tools::print_debug (FILE *stream, const char *format, ...)
00302 {
00303 change_text_color (stream, TT_RESET, TT_GREEN);
00304 va_list ap;
00305
00306 va_start (ap, format);
00307 vfprintf (stream, format, ap);
00308 va_end (ap);
00309
00310 reset_text_color (stream);
00311 }
00312