]> git.ipfire.org Git - thirdparty/util-linux.git/blob - include/colors.h
su: change error message
[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 /* temporary enable/disable colors */
42 extern void colors_off(void);
43 extern void colors_on(void);
44
45
46 /* Set the color */
47 extern void color_fenable(const char *seq, FILE *f);
48
49 extern void color_scheme_fenable(const char *name, const char *dflt, FILE *f);
50 extern const char *color_scheme_get_sequence(const char *name, const char *dflt);
51
52 static inline void color_enable(const char *seq)
53 {
54 color_fenable(seq, stdout);
55 }
56
57 static inline void color_scheme_enable(const char *name, const char *dflt)
58 {
59 color_scheme_fenable(name, dflt, stdout);
60 }
61
62 /* Reset colors to default */
63 extern void color_fdisable(FILE *f);
64
65 static inline void color_disable(void)
66 {
67 color_fdisable(stdout);
68 }
69
70 #endif /* UTIL_LINUX_COLORS_H */