iPXE
Defines | 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.

Defines

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

Functions

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

Variables

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

Detailed Description

ANSI colour definitions.

Definition in file ansicoldef.c.


Define Documentation

#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.

Referenced by ansicol_define(), and ansicol_set().

#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.

Referenced by ansicol_define(), and ansicol_set().

#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.

Referenced by ansicol_define().

#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.

Referenced by ansicol_set().

#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.

Referenced by ansicol_set().

#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.

Referenced by ansicol_set().

#define ANSICOL_DEFAULT (   basic)
Value:
ANSICOL_DEFINE ( ( ( (basic) == COLOR_NORMAL_BG ) ?             \
                           ANSICOL_MAGIC : (basic) ),                   \
                         ANSICOL_NO_RGB )

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

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

Referenced by colour_exec().

                                                                             {
        uint32_t ansicol;

        /* Fail if colour index is out of range */
        if ( colour >= ( sizeof ( ansicols ) / sizeof ( ansicols[0] ) ) )
                return -EINVAL;

        /* Update colour definition */
        ansicol = ANSICOL_DEFINE ( basic, rgb );
        ansicols[colour] = ansicol;
        DBGC ( &ansicols[0], "ANSICOL redefined colour %d as basic %d RGB "
               "%#06lx%s\n", colour, ANSICOL_BASIC ( ansicol ),
               ANSICOL_RGB ( ansicol ),
               ( ( ansicol & ANSICOL_NO_RGB ) ? " [norgb]" : "" ) );

        return 0;
}
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.

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

                                                             {
        uint32_t ansicol;
        unsigned int basic;

        /* Use default colour if colour index is out of range */
        if ( colour < ( sizeof ( ansicols ) / sizeof ( ansicols[0] ) ) ) {
                ansicol = ansicols[colour];
        } else {
                ansicol = ANSICOL_DEFINE ( COLOUR_DEFAULT, ANSICOL_NO_RGB );
        }

        /* If basic colour is out of range, use the magic colour */
        basic = ANSICOL_BASIC ( ansicol );
        if ( basic >= 10 )
                basic = ansicol_magic;

        /* Set basic colour first */
        printf ( CSI "%c%dm", which, basic );

        /* Set 24-bit RGB colour, if applicable */
        if ( ! ( ansicol & ANSICOL_NO_RGB ) ) {
                printf ( CSI "%c8;2;%d;%d;%dm", which, ANSICOL_RED ( ansicol ),
                         ANSICOL_GREEN ( ansicol ), ANSICOL_BLUE ( ansicol ) );
        }
}
void ansicol_reset_magic ( void  )

Reset magic colour.

Definition at line 179 of file ansicoldef.c.

References ansicol_magic, and COLOR_NORMAL_BG.

Referenced by efifb_configure(), and vesafb_configure().

                                  {

        /* Set to the compile-time default background colour */
        ansicol_magic = COLOR_NORMAL_BG;
}

Set magic colour to transparent.

Definition at line 189 of file ansicoldef.c.

References ansicol_magic, and COLOR_DEFAULT.

Referenced by efifb_configure(), and vesafb_configure().

                                            {

        /* Set to the console default colour (which will give a
         * transparent background on the framebuffer console).
         */
        ansicol_magic = COLOR_DEFAULT;
}

Variable Documentation

uint32_t ansicols[] [static]

Magic basic colour.

Definition at line 115 of file ansicoldef.c.

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