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