]> git.ipfire.org Git - thirdparty/util-linux.git/blob - include/colors.h
tests: make sure TS_HELPER_MBSENCODE compiled
[thirdparty/util-linux.git] / include / colors.h
1 /*
2 * Copyright (C) 2012 Ondrej Oprala <ooprala@redhat.com>
3 * Copyright (C) 2012-2014 Karel Zak <kzak@redhat.com>
4 *
5 * This file may be distributed under the terms of the
6 * GNU Lesser General Public License.
7 */
8 #ifndef UTIL_LINUX_COLORS_H
9 #define UTIL_LINUX_COLORS_H
10
11 #include <stdio.h>
12 #include <unistd.h>
13
14 #include "color-names.h"
15
16 /* --color[=WHEN] */
17 enum colortmode {
18 UL_COLORMODE_AUTO = 0,
19 UL_COLORMODE_NEVER,
20 UL_COLORMODE_ALWAYS,
21 UL_COLORMODE_UNDEF,
22
23 __UL_NCOLORMODES /* last */
24 };
25
26 #ifdef USE_COLORS_BY_DEFAULT
27 # define USAGE_COLORS_DEFAULT _("colors are enabled by default")
28 #else
29 # define USAGE_COLORS_DEFAULT _("colors are disabled by default")
30 #endif
31
32 extern int colormode_from_string(const char *str);
33 extern int colormode_or_err(const char *str, const char *errmsg);
34
35 /* Initialize the global variable UL_COLOR_TERM_OK */
36 extern int colors_init(int mode, const char *util_name);
37
38 /* Returns 1 or 0 */
39 extern int colors_wanted(void);
40
41 /* Returns UL_COLORMODE_* */
42 extern int colors_mode(void);
43
44 /* temporary enable/disable colors */
45 extern void colors_off(void);
46 extern void colors_on(void);
47
48
49 /* Set the color */
50 extern void color_fenable(const char *seq, FILE *f);
51
52 extern void color_scheme_fenable(const char *name, const char *dflt, FILE *f);
53 extern const char *color_scheme_get_sequence(const char *name, const char *dflt);
54
55 static inline void color_enable(const char *seq)
56 {
57 color_fenable(seq, stdout);
58 }
59
60 static inline void color_scheme_enable(const char *name, const char *dflt)
61 {
62 color_scheme_fenable(name, dflt, stdout);
63 }
64
65 /* Reset colors to default */
66 extern void color_fdisable(FILE *f);
67
68 static inline void color_disable(void)
69 {
70 color_fdisable(stdout);
71 }
72
73 #endif /* UTIL_LINUX_COLORS_H */