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)
 
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 45 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 53 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 61 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 69 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 77 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 85 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:13
#define ANSICOL_MAGIC
Magic colour.
Definition: ansicol.h:26
#define ANSICOL_NO_RGB
RGB value for "not defined".
Definition: ansicol.h:29
#define ANSICOL_DEFINE(basic, rgb)
Construct ANSI colour definition.
Definition: ansicoldef.c:45

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 97 of file ansicoldef.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ 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_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 149 of file ansicoldef.c.

149  {
150  uint32_t ansicol;
151  unsigned int basic;
152 
153  /* Use default colour if colour index is out of range */
154  if ( colour < ( sizeof ( ansicols ) / sizeof ( ansicols[0] ) ) ) {
155  ansicol = ansicols[colour];
156  } else {
158  }
159 
160  /* If basic colour is out of range, use the magic colour */
161  basic = ANSICOL_BASIC ( ansicol );
162  if ( basic >= 10 )
163  basic = ansicol_magic;
164 
165  /* Set basic colour first */
166  printf ( CSI "%c%dm", which, basic );
167 
168  /* Set 24-bit RGB colour, if applicable */
169  if ( ! ( ansicol & ANSICOL_NO_RGB ) ) {
170  printf ( CSI "%c8;2;%d;%d;%dm", which, ANSICOL_RED ( ansicol ),
171  ANSICOL_GREEN ( ansicol ), ANSICOL_BLUE ( ansicol ) );
172  }
173 }
#define ANSICOL_GREEN(ansicol)
Extract 24-bit RGB value green component from ANSI colour definition.
Definition: ansicoldef.c:77
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
#define ANSICOL_RED(ansicol)
Extract 24-bit RGB value red component from ANSI colour definition.
Definition: ansicoldef.c:69
#define CSI
Control Sequence Introducer.
Definition: ansiesc.h:95
#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
#define ANSICOL_BLUE(ansicol)
Extract 24-bit RGB value blue component from ANSI colour definition.
Definition: ansicoldef.c:85
#define COLOUR_DEFAULT
Default colour (usually white foreground, black background)
Definition: ansicol.h:16
unsigned int uint32_t
Definition: stdint.h:12
static uint8_t ansicol_magic
Magic basic colour.
Definition: ansicoldef.c:115
#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_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 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().

Variable Documentation

◆ ansicols

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

ANSI colour definitions.

Definition at line 103 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 115 of file ansicoldef.c.

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