iPXE
Macros | Functions | Variables
ansicoldef.c File Reference

ANSI colour definitions. More...

#include <stdio.h>
#include <errno.h>
#include <ipxe/ansiesc.h>
#include <ipxe/ansicol.h>
#include <config/colour.h>

Go to the source code of this file.

Macros

#define ANSICOL_DEFINE(basic, rgb)   ( ( (basic) << 28 ) | (rgb) )
 Construct ANSI colour definition. More...
 
#define ANSICOL_BASIC(ansicol)   ( (ansicol) >> 28 )
 Extract basic colour from ANSI colour definition. More...
 
#define ANSICOL_RGB(ansicol)   ( ( (ansicol) >> 0 ) & 0xffffffUL )
 Extract 24-bit RGB value from ANSI colour definition. More...
 
#define ANSICOL_RED(ansicol)   ( ( (ansicol) >> 16 ) & 0xff )
 Extract 24-bit RGB value red component from ANSI colour definition. More...
 
#define ANSICOL_GREEN(ansicol)   ( ( (ansicol) >> 8 ) & 0xff )
 Extract 24-bit RGB value green component from ANSI colour definition. More...
 
#define ANSICOL_BLUE(ansicol)   ( ( (ansicol) >> 0 ) & 0xff )
 Extract 24-bit RGB value blue component from ANSI colour definition. More...
 
#define ANSICOL_DEFAULT(basic)
 Construct default ANSI colour definition. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
int ansicol_define (unsigned int colour, unsigned int basic, uint32_t rgb)
 Define ANSI colour. More...
 
void ansicol_set (unsigned int colour, unsigned int which)
 Set ANSI colour (using colour definitions) More...
 
void ansicol_reset_magic (void)
 Reset magic colour. More...
 
void ansicol_set_magic_transparent (void)
 Set magic colour to transparent. More...
 

Variables

static uint32_t ansicols []
 ANSI colour definitions. More...
 
static uint8_t ansicol_magic = COLOR_NORMAL_BG
 Magic basic colour. More...
 

Detailed Description

ANSI colour definitions.

Definition in file ansicoldef.c.

Macro Definition Documentation

◆ ANSICOL_DEFINE

#define ANSICOL_DEFINE (   basic,
  rgb 
)    ( ( (basic) << 28 ) | (rgb) )

Construct ANSI colour definition.

Parameters
basicBasic colour
rgb24-bit RGB value (or ANSICOL_NO_RGB)
Return values
ansicolANSI colour definition

Definition at line 46 of file ansicoldef.c.

◆ ANSICOL_BASIC

#define ANSICOL_BASIC (   ansicol)    ( (ansicol) >> 28 )

Extract basic colour from ANSI colour definition.

Parameters
ansicolANSI colour definition
Return values
basicBasic colour

Definition at line 54 of file ansicoldef.c.

◆ ANSICOL_RGB

#define ANSICOL_RGB (   ansicol)    ( ( (ansicol) >> 0 ) & 0xffffffUL )

Extract 24-bit RGB value from ANSI colour definition.

Parameters
ansicolANSI colour definition
Return values
rgb24-bit RGB value

Definition at line 62 of file ansicoldef.c.

◆ ANSICOL_RED

#define ANSICOL_RED (   ansicol)    ( ( (ansicol) >> 16 ) & 0xff )

Extract 24-bit RGB value red component from ANSI colour definition.

Parameters
ansicolANSI colour definition
Return values
redRed component

Definition at line 70 of file ansicoldef.c.

◆ ANSICOL_GREEN

#define ANSICOL_GREEN (   ansicol)    ( ( (ansicol) >> 8 ) & 0xff )

Extract 24-bit RGB value green component from ANSI colour definition.

Parameters
ansicolANSI colour definition
Return values
greenGreen component

Definition at line 78 of file ansicoldef.c.

◆ ANSICOL_BLUE

#define ANSICOL_BLUE (   ansicol)    ( ( (ansicol) >> 0 ) & 0xff )

Extract 24-bit RGB value blue component from ANSI colour definition.

Parameters
ansicolANSI colour definition
Return values
blueBlue component

Definition at line 86 of file ansicoldef.c.

◆ ANSICOL_DEFAULT

#define ANSICOL_DEFAULT (   basic)
Value:
ANSICOL_DEFINE ( ( ( (basic) == COLOR_NORMAL_BG ) ? \
ANSICOL_MAGIC : (basic) ), \
#define COLOR_NORMAL_BG
Definition: colour.h:14
#define ANSICOL_MAGIC
Magic colour.
Definition: ansicol.h:27
#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

Construct default ANSI colour definition.

Parameters
basicBasic colour
Return values
ansicolANSI colour definition

Colours default to being just a basic colour. If the colour matches the normal UI text background colour, then its basic colour value is set to ANSICOL_MAGIC.

Definition at line 98 of file ansicoldef.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ 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 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 EINVAL
Invalid argument.
Definition: errno.h:429
#define ANSICOL_RGB(ansicol)
Extract 24-bit RGB value from ANSI colour definition.
Definition: ansicoldef.c:62
#define DBGC(...)
Definition: compiler.h:505
#define colour
Colour for debug messages.
Definition: acpi.c:42
#define ANSICOL_BASIC(ansicol)
Extract basic colour from ANSI colour definition.
Definition: ansicoldef.c:54
unsigned int uint32_t
Definition: stdint.h:12
#define ANSICOL_NO_RGB
RGB value for "not defined".
Definition: ansicol.h:30
static uint32_t ansicols[]
ANSI colour definitions.
Definition: ansicoldef.c:104
#define ANSICOL_DEFINE(basic, rgb)
Construct ANSI colour definition.
Definition: ansicoldef.c:46

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

Referenced by colour_exec().

◆ ansicol_set()

void ansicol_set ( unsigned int  colour,
unsigned int  which 
)

Set ANSI colour (using colour definitions)

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

Parameters
colourColour index
whichForeground/background selector

Definition at line 150 of file ansicoldef.c.

150  {
151  uint32_t ansicol;
152  unsigned int basic;
153 
154  /* Use default colour if colour index is out of range */
155  if ( colour < ( sizeof ( ansicols ) / sizeof ( ansicols[0] ) ) ) {
156  ansicol = ansicols[colour];
157  } else {
159  }
160 
161  /* If basic colour is out of range, use the magic colour */
162  basic = ANSICOL_BASIC ( ansicol );
163  if ( basic >= 10 )
164  basic = ansicol_magic;
165 
166  /* Set basic colour first */
167  printf ( CSI "%c%dm", which, basic );
168 
169  /* Set 24-bit RGB colour, if applicable */
170  if ( ! ( ansicol & ANSICOL_NO_RGB ) ) {
171  printf ( CSI "%c8;2;%d;%d;%dm", which, ANSICOL_RED ( ansicol ),
172  ANSICOL_GREEN ( ansicol ), ANSICOL_BLUE ( ansicol ) );
173  }
174 }
#define ANSICOL_GREEN(ansicol)
Extract 24-bit RGB value green component from ANSI colour definition.
Definition: ansicoldef.c:78
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:465
#define ANSICOL_RED(ansicol)
Extract 24-bit RGB value red component from ANSI colour definition.
Definition: ansicoldef.c:70
#define CSI
Control Sequence Introducer.
Definition: ansiesc.h:96
#define colour
Colour for debug messages.
Definition: acpi.c:42
#define ANSICOL_BASIC(ansicol)
Extract basic colour from ANSI colour definition.
Definition: ansicoldef.c:54
#define ANSICOL_BLUE(ansicol)
Extract 24-bit RGB value blue component from ANSI colour definition.
Definition: ansicoldef.c:86
#define COLOUR_DEFAULT
Default colour (usually white foreground, black background)
Definition: ansicol.h:17
unsigned int uint32_t
Definition: stdint.h:12
static uint8_t ansicol_magic
Magic basic colour.
Definition: ansicoldef.c:116
#define ANSICOL_NO_RGB
RGB value for "not defined".
Definition: ansicol.h:30
static uint32_t ansicols[]
ANSI colour definitions.
Definition: ansicoldef.c:104
#define ANSICOL_DEFINE(basic, rgb)
Construct ANSI colour definition.
Definition: ansicoldef.c:46

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

◆ ansicol_reset_magic()

void ansicol_reset_magic ( void  )

Reset magic colour.

Definition at line 180 of file ansicoldef.c.

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

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 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
static uint8_t ansicol_magic
Magic basic colour.
Definition: ansicoldef.c:116

References ansicol_magic, and COLOR_DEFAULT.

Referenced by efifb_configure(), and vesafb_configure().

Variable Documentation

◆ ansicols

uint32_t ansicols[]
static
Initial value:
= {
}
#define COLOR_YELLOW
Definition: curses.h:206
#define COLOR_BLACK
Definition: curses.h:200
#define COLOR_BLUE
Definition: curses.h:201
#define COLOR_WHITE
Definition: curses.h:207
#define COLOR_GREEN
Definition: curses.h:202
#define COLOR_CYAN
Definition: curses.h:203
#define COLOR_RED
Definition: curses.h:204
#define COLOR_MAGENTA
Definition: curses.h:205
#define ANSICOL_DEFAULT(basic)
Construct default ANSI colour definition.
Definition: ansicoldef.c:98

ANSI colour definitions.

Definition at line 104 of file ansicoldef.c.

Referenced by ansicol_define(), and ansicol_set().

◆ ansicol_magic

uint8_t ansicol_magic = COLOR_NORMAL_BG
static

Magic basic colour.

Definition at line 116 of file ansicoldef.c.

Referenced by ansicol_reset_magic(), ansicol_set(), and ansicol_set_magic_transparent().