2012-10-16 09:39:00 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Ondrej Oprala <ooprala@redhat.com>
|
2014-05-05 09:22:43 -05:00
|
|
|
* Copyright (C) 2012-2014 Karel Zak <kzak@redhat.com>
|
2012-10-16 09:39:00 -05:00
|
|
|
*
|
|
|
|
* This file may be distributed under the terms of the
|
|
|
|
* GNU Lesser General Public License.
|
|
|
|
*/
|
|
|
|
#ifndef UTIL_LINUX_COLORS_H
|
|
|
|
#define UTIL_LINUX_COLORS_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2015-07-24 05:57:46 -05:00
|
|
|
#include "color-names.h"
|
2015-02-25 05:35:05 -06:00
|
|
|
|
2013-05-06 12:07:23 -05:00
|
|
|
/* --color[=WHEN] */
|
|
|
|
enum colortmode {
|
|
|
|
UL_COLORMODE_AUTO = 0,
|
|
|
|
UL_COLORMODE_NEVER,
|
|
|
|
UL_COLORMODE_ALWAYS,
|
2014-01-23 06:03:45 -06:00
|
|
|
UL_COLORMODE_UNDEF,
|
2013-05-06 12:07:23 -05:00
|
|
|
|
|
|
|
__UL_NCOLORMODES /* last */
|
|
|
|
};
|
|
|
|
|
2015-08-01 03:23:07 -05:00
|
|
|
#ifdef USE_COLORS_BY_DEFAULT
|
2017-05-27 15:50:57 -05:00
|
|
|
# define USAGE_COLORS_DEFAULT _("colors are enabled by default")
|
2015-02-25 05:35:05 -06:00
|
|
|
#else
|
2017-05-27 15:50:57 -05:00
|
|
|
# define USAGE_COLORS_DEFAULT _("colors are disabled by default")
|
2015-02-25 05:35:05 -06:00
|
|
|
#endif
|
|
|
|
|
2013-05-06 12:07:23 -05:00
|
|
|
extern int colormode_from_string(const char *str);
|
2013-05-07 02:09:35 -05:00
|
|
|
extern int colormode_or_err(const char *str, const char *errmsg);
|
2013-05-06 12:07:23 -05:00
|
|
|
|
2014-01-23 06:03:45 -06:00
|
|
|
/* Initialize the global variable UL_COLOR_TERM_OK */
|
|
|
|
extern int colors_init(int mode, const char *util_name);
|
2012-10-16 09:39:00 -05:00
|
|
|
|
2013-09-02 03:54:30 -05:00
|
|
|
/* Returns 1 or 0 */
|
|
|
|
extern int colors_wanted(void);
|
|
|
|
|
2019-02-04 07:14:37 -06:00
|
|
|
/* Returns UL_COLORMODE_* */
|
|
|
|
extern int colors_mode(void);
|
|
|
|
|
2014-04-30 07:51:46 -05:00
|
|
|
/* temporary enable/disable colors */
|
|
|
|
extern void colors_off(void);
|
|
|
|
extern void colors_on(void);
|
|
|
|
|
|
|
|
|
2014-05-05 09:22:43 -05:00
|
|
|
/* Set the color */
|
|
|
|
extern void color_fenable(const char *seq, FILE *f);
|
2014-08-13 03:09:08 -05:00
|
|
|
|
2014-05-05 09:22:43 -05:00
|
|
|
extern void color_scheme_fenable(const char *name, const char *dflt, FILE *f);
|
2014-08-13 03:09:08 -05:00
|
|
|
extern const char *color_scheme_get_sequence(const char *name, const char *dflt);
|
2013-09-02 03:54:30 -05:00
|
|
|
|
2014-05-05 09:22:43 -05:00
|
|
|
static inline void color_enable(const char *seq)
|
2013-09-02 03:54:30 -05:00
|
|
|
{
|
2014-05-05 09:22:43 -05:00
|
|
|
color_fenable(seq, stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void color_scheme_enable(const char *name, const char *dflt)
|
|
|
|
{
|
|
|
|
color_scheme_fenable(name, dflt, stdout);
|
2013-09-02 03:54:30 -05:00
|
|
|
}
|
2012-10-16 09:39:00 -05:00
|
|
|
|
|
|
|
/* Reset colors to default */
|
2013-09-02 03:54:30 -05:00
|
|
|
extern void color_fdisable(FILE *f);
|
|
|
|
|
|
|
|
static inline void color_disable(void)
|
|
|
|
{
|
|
|
|
color_fdisable(stdout);
|
|
|
|
}
|
|
|
|
|
2012-10-16 09:39:00 -05:00
|
|
|
#endif /* UTIL_LINUX_COLORS_H */
|