/[baselayout]/trunk/src/libeinfo.c
Gentoo

Diff of /trunk/src/libeinfo.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2970 Revision 2971
135 return (val ? false : true); 135 return (val ? false : true);
136 136
137 return (strcasecmp (v, val) ? false : true); 137 return (strcasecmp (v, val) ? false : true);
138} 138}
139 139
140static bool colour_terminal (void) 140static bool colour_terminal (FILE *f)
141{ 141{
142 static int in_colour = -1; 142 static int in_colour = -1;
143 int i = 0; 143 int i = 0;
144
145 if (f && ! isatty (fileno (f)))
146 return (false);
144 147
145 if (is_env ("RC_NOCOLOR", "yes")) 148 if (is_env ("RC_NOCOLOR", "yes"))
146 return (false); 149 return (false);
147 150
148 if (in_colour == 0) 151 if (in_colour == 0)
190 return (ws.ws_col); 193 return (ws.ws_col);
191 194
192 return (DEFAULT_COLS); 195 return (DEFAULT_COLS);
193} 196}
194 197
195void eprefix (const char *prefix) { 198void eprefix (const char *prefix)
199{
196 _eprefix = prefix; 200 _eprefix = prefix;
197} 201}
198 202
199static void elogv (int level, const char *fmt, va_list ap) 203static void elogv (int level, const char *fmt, va_list ap)
200{ 204{
242 /* Terminate it */ 246 /* Terminate it */
243 memset (indent + amount, 0, 1); 247 memset (indent + amount, 0, 1);
244 return (fprintf (stream, "%s", indent)); 248 return (fprintf (stream, "%s", indent));
245} 249}
246 250
247const char *ecolor (einfo_color_t color) { 251static const char *_ecolor (FILE *f, einfo_color_t color)
252{
248 const char *col = NULL; 253 const char *col = NULL;
249 254
250 if (! colour_terminal ()) 255 if (! colour_terminal (f))
251 return (""); 256 return ("");
252 257
253 switch (color) { 258 switch (color) {
254 case ECOLOR_GOOD: 259 case ECOLOR_GOOD:
255 if (! (col = getenv ("ECOLOR_GOOD"))) 260 if (! (col = getenv ("ECOLOR_GOOD")))
278 283
279 return (col); 284 return (col);
280} 285}
281hidden_def(ecolor) 286hidden_def(ecolor)
282 287
288const char *ecolor (einfo_color_t color)
289{
290 return (_ecolor (NULL, color));
291}
292
283#define EINFOVN(_file, _color) \ 293#define EINFOVN(_file, _color) \
284 if (_eprefix) \ 294 if (_eprefix) \
285 fprintf (_file, "%s%s%s|", ecolor (_color), _eprefix, ecolor (ECOLOR_NORMAL)); \ 295 fprintf (_file, "%s%s%s|", _ecolor (_file, _color), _eprefix, _ecolor (_file, ECOLOR_NORMAL)); \
286 fprintf (_file, " %s*%s ", ecolor (_color), ecolor (ECOLOR_NORMAL)); \ 296 fprintf (_file, " %s*%s ", _ecolor (_file, _color), _ecolor (_file, ECOLOR_NORMAL)); \
287 retval += _eindent (_file); \ 297 retval += _eindent (_file); \
288{ \ 298{ \
289 va_list _ap; \ 299 va_list _ap; \
290 va_copy (_ap, ap); \ 300 va_copy (_ap, ap); \
291 retval += vfprintf (_file, fmt, _ap) + 3; \ 301 retval += vfprintf (_file, fmt, _ap) + 3; \
292 va_end (_ap); \ 302 va_end (_ap); \
293} \ 303} \
294 if (colour_terminal ()) \ 304 if (colour_terminal (_file)) \
295 fprintf (_file, ECOLOR_FLUSH_A); 305 fprintf (_file, ECOLOR_FLUSH_A);
296 306
297static int _einfovn (const char *fmt, va_list ap) 307static int _einfovn (const char *fmt, va_list ap)
298{ 308{
299 int retval = 0; 309 int retval = 0;
458 468
459 va_start (ap, fmt); 469 va_start (ap, fmt);
460 retval = _einfovn (fmt, ap); 470 retval = _einfovn (fmt, ap);
461 va_end (ap); 471 va_end (ap);
462 retval += printf (" ..."); 472 retval += printf (" ...");
463 if (colour_terminal ()) 473 if (colour_terminal (stdout))
464 retval += printf ("\n"); 474 retval += printf ("\n");
465 475
466 return (retval); 476 return (retval);
467} 477}
468hidden_def(ebegin) 478hidden_def(ebegin)
487 term_is_cons25 = false; 497 term_is_cons25 = false;
488 } 498 }
489 if (term_is_cons25) 499 if (term_is_cons25)
490 cols--; 500 cols--;
491 501
492 if (cols > 0 && colour_terminal ()) { 502 if (cols > 0 && colour_terminal (fp)) {
493 fprintf (fp, "\033[A\033[%dC %s[ %s%s %s]%s\n", cols, 503 fprintf (fp, "\033[A\033[%dC %s[ %s%s %s]%s\n", cols,
494 ecolor (ECOLOR_BRACKET), ecolor (color), msg, 504 ecolor (ECOLOR_BRACKET), ecolor (color), msg,
495 ecolor (ECOLOR_BRACKET), ecolor (ECOLOR_NORMAL)); 505 ecolor (ECOLOR_BRACKET), ecolor (ECOLOR_NORMAL));
496 } else { 506 } else {
497 if (col > 0) 507 if (col > 0)
694 return (0); 704 return (0);
695 705
696 va_start (ap, fmt); 706 va_start (ap, fmt);
697 retval = _einfovn (fmt, ap); 707 retval = _einfovn (fmt, ap);
698 retval += printf (" ..."); 708 retval += printf (" ...");
699 if (colour_terminal ()) 709 if (colour_terminal (stdout))
700 retval += printf ("\n"); 710 retval += printf ("\n");
701 va_end (ap); 711 va_end (ap);
702 712
703 return (retval); 713 return (retval);
704} 714}

Legend:
Removed from v.2970  
changed lines
  Added in v.2971

  ViewVC Help
Powered by ViewVC 1.1.20