iPXE
ansicol.h File Reference

ANSI colours. More...

#include <stdint.h>
#include <curses.h>

Go to the source code of this file.

Data Structures

struct  ansicol_pair
 An ANSI colour pair definition. More...

Macros

#define COLOUR_DEFAULT   9
 Default colour (usually white foreground, black background)
#define COLOR_DEFAULT   COLOUR_DEFAULT
#define ANSICOL_MAGIC   15
 Magic colour.
#define ANSICOL_NO_RGB   0x01000000
 RGB value for "not defined".
#define CPAIR_DEFAULT   0
 Default colour pair.
#define CPAIR_NORMAL   1
 Normal text.
#define CPAIR_SELECT   2
 Highlighted text.
#define CPAIR_SEPARATOR   3
 Unselectable text (e.g.
#define CPAIR_EDIT   4
 Editable text.
#define CPAIR_ALERT   5
 Error text.
#define CPAIR_URL   6
 URL text.
#define CPAIR_PXE   7
 PXE selected menu entry.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
void ansicol_set_pair (unsigned int cpair)
 Set ANSI foreground and background colour.
int ansicol_define_pair (unsigned int cpair, unsigned int foreground, unsigned int background)
 Define ANSI colour pair.
int ansicol_define (unsigned int colour, unsigned int ansi, uint32_t rgb)
 Define ANSI colour.
void ansicol_reset_magic (void)
 Reset magic colour.
void ansicol_set_magic_transparent (void)
 Set magic colour to transparent.
void ansicol_set (unsigned int colour, unsigned int which)
 Set ANSI colour (when no colour definition support is present)

Detailed Description

ANSI colours.

Definition in file ansicol.h.

Macro Definition Documentation

◆ COLOUR_DEFAULT

#define COLOUR_DEFAULT   9

Default colour (usually white foreground, black background)

Definition at line 17 of file ansicol.h.

Referenced by ansicol_set(), colour_exec(), and cpair_exec().

◆ COLOR_DEFAULT

#define COLOR_DEFAULT   COLOUR_DEFAULT

Definition at line 18 of file ansicol.h.

Referenced by ansicol_set_magic_transparent().

◆ ANSICOL_MAGIC

#define ANSICOL_MAGIC   15

Magic colour.

The magic basic colour is automatically remapped to the colour stored in ansicol_magic. This is used to allow the UI background to automatically become transparent when a background picture is used.

Definition at line 27 of file ansicol.h.

◆ ANSICOL_NO_RGB

#define ANSICOL_NO_RGB   0x01000000

RGB value for "not defined".

Definition at line 30 of file ansicol.h.

Referenced by ansicol_define(), ansicol_set(), and colour_exec().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ ansicol_set_pair()

void ansicol_set_pair ( unsigned int cpair)
extern

Set ANSI foreground and background colour.

Parameters
cpairColour pair index

Definition at line 90 of file ansicol.c.

90 {
91 struct ansicol_pair *pair;
92
93 /* Colour pair indices are hardcoded and should never be out of range */
94 assert ( cpair < ( sizeof ( ansicol_pairs ) /
95 sizeof ( ansicol_pairs[0] ) ) );
96
97 /* Set both foreground and background colours */
98 pair = &ansicol_pairs[cpair];
101}
static void ansicol_background(unsigned int colour)
Set ANSI background colour.
Definition ansicol.c:81
static void ansicol_foreground(unsigned int colour)
Set ANSI foreground colour.
Definition ansicol.c:72
static struct ansicol_pair ansicol_pairs[]
ANSI colour pair definitions.
Definition ansicol.c:41
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
An ANSI colour pair definition.
Definition ansicol.h:64
uint8_t foreground
Foreground colour index.
Definition ansicol.h:66
uint8_t background
Background colour index.
Definition ansicol.h:68

References ansicol_background(), ansicol_foreground(), ansicol_pairs, assert, ansicol_pair::background, and ansicol_pair::foreground.

Referenced by ansiscr_attrs(), ansiscr_reset(), colour_exec(), console_exec(), and cpair_exec().

◆ ansicol_define_pair()

int ansicol_define_pair ( unsigned int cpair,
unsigned int foreground,
unsigned int background )
extern

Define ANSI colour pair.

Parameters
cpairColour pair index
foregroundForeground colour index
backgroundBackground colour index
Return values
rcReturn status code

Definition at line 111 of file ansicol.c.

112 {
113 struct ansicol_pair *pair;
114
115 /* Fail if colour index is out of range */
116 if ( cpair >= ( sizeof ( ansicol_pairs ) / sizeof ( ansicol_pairs[0] )))
117 return -EINVAL;
118
119 /* Update colour pair definition */
120 pair = &ansicol_pairs[cpair];
121 pair->foreground = foreground;
122 pair->background = background;
123 DBGC ( &ansicol_pairs[0], "ANSICOL redefined colour pair %d as "
124 "foreground %d background %d\n", cpair, foreground, background );
125
126 return 0;
127}
#define DBGC(...)
Definition compiler.h:505
#define EINVAL
Invalid argument.
Definition errno.h:429

References ansicol_pairs, ansicol_pair::background, DBGC, EINVAL, and ansicol_pair::foreground.

Referenced by cpair_exec().

◆ ansicol_define()

int ansicol_define ( unsigned int colour,
unsigned int basic,
uint32_t rgb )
extern

Define ANSI colour.

Parameters
colourColour index
basicBasic colour
rgb24-bit RGB value (or ANSICOL_NO_RGB)
Return values
rcReturn status code

Definition at line 126 of file ansicoldef.c.

126 {
127 uint32_t ansicol;
128
129 /* Fail if colour index is out of range */
130 if ( colour >= ( sizeof ( ansicols ) / sizeof ( ansicols[0] ) ) )
131 return -EINVAL;
132
133 /* Update colour definition */
134 ansicol = ANSICOL_DEFINE ( basic, rgb );
135 ansicols[colour] = ansicol;
136 DBGC ( &ansicols[0], "ANSICOL redefined colour %d as basic %d RGB "
137 "%#06lx%s\n", colour, ANSICOL_BASIC ( ansicol ),
138 ANSICOL_RGB ( ansicol ),
139 ( ( ansicol & ANSICOL_NO_RGB ) ? " [norgb]" : "" ) );
140
141 return 0;
142}
#define colour
Colour for debug messages.
Definition acpi.c:42
#define ANSICOL_NO_RGB
RGB value for "not defined".
Definition ansicol.h:30
#define ANSICOL_DEFINE(basic, rgb)
Construct ANSI colour definition.
Definition ansicoldef.c:46
#define ANSICOL_BASIC(ansicol)
Extract basic colour from ANSI colour definition.
Definition ansicoldef.c:54
static uint32_t ansicols[]
ANSI colour definitions.
Definition ansicoldef.c:104
#define ANSICOL_RGB(ansicol)
Extract 24-bit RGB value from ANSI colour definition.
Definition ansicoldef.c:62
unsigned int uint32_t
Definition stdint.h:12

References ANSICOL_BASIC, ANSICOL_DEFINE, ANSICOL_NO_RGB, ANSICOL_RGB, ansicols, colour, DBGC, and EINVAL.

Referenced by colour_exec().

◆ ansicol_reset_magic()

void ansicol_reset_magic ( void )
extern

Reset magic colour.

Definition at line 180 of file ansicoldef.c.

180 {
181
182 /* Set to the compile-time default background colour */
184}
static uint8_t ansicol_magic
Magic basic colour.
Definition ansicoldef.c:116
#define COLOR_NORMAL_BG
Definition colour.h:14

References ansicol_magic, and COLOR_NORMAL_BG.

Referenced by efifb_configure(), and vesafb_configure().

◆ ansicol_set_magic_transparent()

void ansicol_set_magic_transparent ( void )
extern

Set magic colour to transparent.

Definition at line 190 of file ansicoldef.c.

190 {
191
192 /* Set to the console default colour (which will give a
193 * transparent background on the framebuffer console).
194 */
196}
#define COLOR_DEFAULT
Definition ansicol.h:18

References ansicol_magic, and COLOR_DEFAULT.

Referenced by efifb_configure(), and vesafb_configure().

◆ ansicol_set()

void ansicol_set ( unsigned int colour,
unsigned int which )
extern

Set ANSI colour (when no colour definition support is present)

Parameters
colourColour index
whichForeground/background selector

Set ANSI colour (when no colour definition support is present)

Parameters
colourColour index
whichForeground/background selector

Definition at line 58 of file ansicol.c.

58 {
59
60 /* Colour indices are hardcoded and should never be out of range */
61 assert ( colour < 10 );
62
63 /* Set basic colour */
64 printf ( CSI "%c%dm", which, colour );
65}
#define CSI
Control Sequence Introducer.
Definition ansiesc.h:96
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465

References __weak, ANSICOL_BASIC, ANSICOL_BLUE, ANSICOL_DEFINE, ANSICOL_GREEN, ansicol_magic, ANSICOL_NO_RGB, ANSICOL_RED, ansicols, assert, colour, COLOUR_DEFAULT, CSI, and printf().

Referenced by ansicol_background(), and ansicol_foreground().