File: colors.h

package info (click to toggle)
util-linux 2.41.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 92,868 kB
  • sloc: ansic: 179,124; sh: 22,714; yacc: 1,284; makefile: 525; xml: 422; python: 316; lex: 89; ruby: 75; csh: 37; exp: 19; sed: 16; perl: 15; sql: 9
file content (75 lines) | stat: -rw-r--r-- 1,767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * No copyright is claimed.  This code is in the public domain; do with
 * it what you wish.
 *
 * Authors: 2012 Ondrej Oprala <ooprala@redhat.com>
 *          2012-2025 Karel Zak <kzak@redhat.com>
 */
#ifndef UTIL_LINUX_COLORS_H
#define UTIL_LINUX_COLORS_H

#include <stdio.h>
#include <unistd.h>

#include "color-names.h"

/* --color[=WHEN] */
enum colortmode {
	UL_COLORMODE_AUTO = 0,
	UL_COLORMODE_NEVER,
	UL_COLORMODE_ALWAYS,
	UL_COLORMODE_UNDEF,

	__UL_NCOLORMODES	/* last */
};

#ifdef USE_COLORS_BY_DEFAULT
# define USAGE_COLORS_DEFAULT	_("colors are enabled by default")
#else
# define USAGE_COLORS_DEFAULT   _("colors are disabled by default")
#endif

extern int colormode_from_string(const char *str);
extern int colormode_or_err(const char *str, const char *errmsg);

/* Initialize the global variable UL_COLOR_TERM_OK */
extern int colors_init(int mode, const char *util_name);

/* Returns 1 or 0 */
extern int colors_wanted(void);

/* Returns UL_COLORMODE_* */
extern int colors_mode(void);

/* temporary enable/disable colors */
extern void colors_off(void);
extern void colors_on(void);


/* Set the color */
extern void color_fenable(const char *seq, FILE *f);

extern void color_scheme_fenable(const char *name, const char *dflt, FILE *f);
extern const char *color_scheme_get_sequence(const char *name, const char *dflt);

static inline void color_enable(const char *seq)
{
	color_fenable(seq, stdout);
}

static inline void color_scheme_enable(const char *name, const char *dflt)
{
	color_scheme_fenable(name, dflt, stdout);
}

/* Reset colors to default */
extern void color_fdisable(FILE *f);

static inline void color_disable(void)
{
	color_fdisable(stdout);
}

const char *color_get_disable_sequence(void);

#endif /* UTIL_LINUX_COLORS_H */