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

Defines

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


Define Documentation

#define COLOUR_DEFAULT   9

Default colour (usually white foreground, black background)

Definition at line 16 of file ansicol.h.

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

Definition at line 17 of file ansicol.h.

Referenced by ansicol_set_magic_transparent().

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

#define ANSICOL_NO_RGB   0x01000000

RGB value for "not defined".

Definition at line 29 of file ansicol.h.

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


Function Documentation

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

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

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

                                             {
        struct ansicol_pair *pair;

        /* Colour pair indices are hardcoded and should never be out of range */
        assert ( cpair < ( sizeof ( ansicol_pairs ) /
                           sizeof ( ansicol_pairs[0] ) ) );

        /* Set both foreground and background colours */
        pair = &ansicol_pairs[cpair];
        ansicol_foreground ( pair->foreground );
        ansicol_background ( pair->background );
}
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.

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

Referenced by cpair_exec().

                                                    {
        struct ansicol_pair *pair;

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

        /* Update colour pair definition */
        pair = &ansicol_pairs[cpair];
        pair->foreground = foreground;
        pair->background = background;
        DBGC ( &ansicol_pairs[0], "ANSICOL redefined colour pair %d as "
               "foreground %d background %d\n", cpair, foreground, background );

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

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

                                                                    {

        /* Colour indices are hardcoded and should never be out of range */
        assert ( colour < 10 );

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