]>
Commit | Line | Data |
---|---|---|
dfa68ad1 | 1 | /* |
79feaa60 KZ |
2 | * SPDX-License-Identifier: LGPL-2.1-or-later |
3 | * | |
dfa68ad1 | 4 | * Copyright (C) 2012 Ondrej Oprala <ooprala@redhat.com> |
7a4704d8 | 5 | * Copyright (C) 2012-2014 Karel Zak <kzak@redhat.com> |
dfa68ad1 OO |
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 | ||
0bef6f75 | 16 | #include "color-names.h" |
62dc0ee8 | 17 | |
a10c0434 KZ |
18 | /* --color[=WHEN] */ |
19 | enum colortmode { | |
20 | UL_COLORMODE_AUTO = 0, | |
21 | UL_COLORMODE_NEVER, | |
22 | UL_COLORMODE_ALWAYS, | |
d0c9ddc3 | 23 | UL_COLORMODE_UNDEF, |
a10c0434 KZ |
24 | |
25 | __UL_NCOLORMODES /* last */ | |
26 | }; | |
27 | ||
62eea9ce | 28 | #ifdef USE_COLORS_BY_DEFAULT |
25c7b43e | 29 | # define USAGE_COLORS_DEFAULT _("colors are enabled by default") |
62dc0ee8 | 30 | #else |
25c7b43e | 31 | # define USAGE_COLORS_DEFAULT _("colors are disabled by default") |
62dc0ee8 KZ |
32 | #endif |
33 | ||
a10c0434 | 34 | extern int colormode_from_string(const char *str); |
b7faf991 | 35 | extern int colormode_or_err(const char *str, const char *errmsg); |
a10c0434 | 36 | |
d0c9ddc3 OO |
37 | /* Initialize the global variable UL_COLOR_TERM_OK */ |
38 | extern int colors_init(int mode, const char *util_name); | |
dfa68ad1 | 39 | |
80a1712f KZ |
40 | /* Returns 1 or 0 */ |
41 | extern int colors_wanted(void); | |
42 | ||
5db59623 KZ |
43 | /* Returns UL_COLORMODE_* */ |
44 | extern int colors_mode(void); | |
45 | ||
e66a6627 KZ |
46 | /* temporary enable/disable colors */ |
47 | extern void colors_off(void); | |
48 | extern void colors_on(void); | |
49 | ||
50 | ||
7a4704d8 KZ |
51 | /* Set the color */ |
52 | extern void color_fenable(const char *seq, FILE *f); | |
b8731ebc | 53 | |
7a4704d8 | 54 | extern void color_scheme_fenable(const char *name, const char *dflt, FILE *f); |
b8731ebc | 55 | extern const char *color_scheme_get_sequence(const char *name, const char *dflt); |
80a1712f | 56 | |
7a4704d8 | 57 | static inline void color_enable(const char *seq) |
80a1712f | 58 | { |
7a4704d8 KZ |
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); | |
80a1712f | 65 | } |
dfa68ad1 OO |
66 | |
67 | /* Reset colors to default */ | |
80a1712f KZ |
68 | extern void color_fdisable(FILE *f); |
69 | ||
70 | static inline void color_disable(void) | |
71 | { | |
72 | color_fdisable(stdout); | |
73 | } | |
74 | ||
f0175fe2 TW |
75 | const char *color_get_disable_sequence(void); |
76 | ||
dfa68ad1 | 77 | #endif /* UTIL_LINUX_COLORS_H */ |