iPXE
Data Structures | Macros | Functions
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) More...
 
#define COLOR_DEFAULT   COLOUR_DEFAULT
 
#define ANSICOL_MAGIC   15
 Magic colour. More...
 
#define ANSICOL_NO_RGB   0x01000000
 RGB value for "not defined". More...
 
#define CPAIR_DEFAULT   0
 Default colour pair. More...
 
#define CPAIR_NORMAL   1
 Normal text. More...
 
#define CPAIR_SELECT   2
 Highlighted text. More...
 
#define CPAIR_SEPARATOR   3
 Unselectable text (e.g. More...
 
#define CPAIR_EDIT   4
 Editable text. More...
 
#define CPAIR_ALERT   5
 Error text. More...
 
#define CPAIR_URL   6
 URL text. More...
 
#define CPAIR_PXE   7
 PXE selected menu entry. More...
 

Functions

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

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 16 of file ansicol.h.

◆ COLOR_DEFAULT

#define COLOR_DEFAULT   COLOUR_DEFAULT

Definition at line 17 of file ansicol.h.

◆ 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 26 of file ansicol.h.

◆ ANSICOL_NO_RGB

#define ANSICOL_NO_RGB   0x01000000

RGB value for "not defined".

Definition at line 29 of file ansicol.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ansicol_set_pair()

void ansicol_set_pair ( unsigned int  cpair)

Set ANSI foreground and background colour.

Parameters
cpairColour pair index

Definition at line 89 of file ansicol.c.

89  {
90  struct ansicol_pair *pair;
91 
92  /* Colour pair indices are hardcoded and should never be out of range */
93  assert ( cpair < ( sizeof ( ansicol_pairs ) /
94  sizeof ( ansicol_pairs[0] ) ) );
95 
96  /* Set both foreground and background colours */
97  pair = &ansicol_pairs[cpair];
100 }
static void ansicol_background(unsigned int colour)
Set ANSI background colour.
Definition: ansicol.c:80
uint8_t foreground
Foreground colour index.
Definition: ansicol.h:65
An ANSI colour pair definition.
Definition: ansicol.h:63
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static struct ansicol_pair ansicol_pairs[]
ANSI colour pair definitions.
Definition: ansicol.c:40
static void ansicol_foreground(unsigned int colour)
Set ANSI foreground colour.
Definition: ansicol.c:71
uint8_t background
Background colour index.
Definition: ansicol.h:67

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 
)

Define ANSI colour pair.

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

Definition at line 110 of file ansicol.c.

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

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 
)

Define ANSI colour.

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

Definition at line 125 of file ansicoldef.c.

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

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  )

Reset magic colour.

Definition at line 179 of file ansicoldef.c.

179  {
180 
181  /* Set to the compile-time default background colour */
183 }
#define COLOR_NORMAL_BG
Definition: colour.h:13
static uint8_t ansicol_magic
Magic basic colour.
Definition: ansicoldef.c:115

References ansicol_magic, and COLOR_NORMAL_BG.

Referenced by efifb_configure(), and vesafb_configure().

◆ ansicol_set_magic_transparent()

void ansicol_set_magic_transparent ( void  )

Set magic colour to transparent.

Definition at line 189 of file ansicoldef.c.

189  {
190 
191  /* Set to the console default colour (which will give a
192  * transparent background on the framebuffer console).
193  */
195 }
#define COLOR_DEFAULT
Definition: ansicol.h:17
static uint8_t ansicol_magic
Magic basic colour.
Definition: ansicoldef.c:115

References ansicol_magic, and COLOR_DEFAULT.

Referenced by efifb_configure(), and vesafb_configure().

◆ ansicol_set()

void ansicol_set ( unsigned int  colour,
unsigned int  which 
)

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 57 of file ansicol.c.

57  {
58 
59  /* Colour indices are hardcoded and should never be out of range */
60  assert ( colour < 10 );
61 
62  /* Set basic colour */
63  printf ( CSI "%c%dm", which, colour );
64 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
#define CSI
Control Sequence Introducer.
Definition: ansiesc.h:95
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define colour
Colour for debug messages.
Definition: acpi.c:39

References 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().