|
Packit |
709fb3 |
/* Output colorization.
|
|
Packit |
709fb3 |
Copyright 2011-2017 Free Software Foundation, Inc.
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
This program is free software; you can redistribute it and/or modify
|
|
Packit |
709fb3 |
it under the terms of the GNU General Public License as published by
|
|
Packit |
709fb3 |
the Free Software Foundation; either version 3, or (at your option)
|
|
Packit |
709fb3 |
any later version.
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
This program is distributed in the hope that it will be useful,
|
|
Packit |
709fb3 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
709fb3 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
709fb3 |
GNU General Public License for more details.
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
You should have received a copy of the GNU General Public License
|
|
Packit |
709fb3 |
along with this program; if not, write to the Free Software
|
|
Packit |
709fb3 |
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
|
|
Packit |
709fb3 |
02110-1301, USA. */
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
/* Without this pragma, gcc 4.7.0 20120102 suggests that the
|
|
Packit |
709fb3 |
init_colorize function might be candidate for attribute 'const' */
|
|
Packit |
709fb3 |
#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
|
|
Packit |
709fb3 |
# pragma GCC diagnostic ignored "-Wsuggest-attribute=const"
|
|
Packit |
709fb3 |
#endif
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
#include <config.h>
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
#include "colorize.h"
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
#include <stdio.h>
|
|
Packit |
709fb3 |
#include <stdlib.h>
|
|
Packit |
709fb3 |
#include <string.h>
|
|
Packit |
709fb3 |
#include <unistd.h>
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
/* Return non-zero if we should highlight matches in output to file
|
|
Packit |
709fb3 |
descriptor FD. */
|
|
Packit |
709fb3 |
int
|
|
Packit |
709fb3 |
should_colorize (void)
|
|
Packit |
709fb3 |
{
|
|
Packit |
709fb3 |
char const *t = getenv ("TERM");
|
|
Packit |
709fb3 |
return t && strcmp (t, "dumb") != 0;
|
|
Packit |
709fb3 |
}
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
void init_colorize (void) { }
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
/* Start a colorized text attribute on stdout using the SGR_START
|
|
Packit |
709fb3 |
format; the attribute is specified by SGR_SEQ. */
|
|
Packit |
709fb3 |
void
|
|
Packit |
709fb3 |
print_start_colorize (char const *sgr_start, char const *sgr_seq)
|
|
Packit |
709fb3 |
{
|
|
Packit |
709fb3 |
printf (sgr_start, sgr_seq);
|
|
Packit |
709fb3 |
}
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
/* Restore the normal text attribute using the SGR_END string. */
|
|
Packit |
709fb3 |
void
|
|
Packit |
709fb3 |
print_end_colorize (char const *sgr_end)
|
|
Packit |
709fb3 |
{
|
|
Packit |
709fb3 |
fputs (sgr_end, stdout);
|
|
Packit |
709fb3 |
}
|