iPXE
Functions | Variables
ansicol.c File Reference

ANSI colours. More...

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

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
__weak void ansicol_set (unsigned int colour, unsigned int which)
 Set ANSI colour (when no colour definition support is present)
static void ansicol_foreground (unsigned int colour)
 Set ANSI foreground colour.
static void ansicol_background (unsigned int colour)
 Set ANSI background colour.
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.

Variables

static struct ansicol_pair ansicol_pairs []
 ANSI colour pair definitions.

Detailed Description

ANSI colours.

Definition in file ansicol.c.


Function Documentation

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

Definition at line 57 of file ansicol.c.

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 );
}
static void ansicol_foreground ( unsigned int  colour) [static]

Set ANSI foreground colour.

Parameters:
colourColour index

Definition at line 71 of file ansicol.c.

References ansicol_set().

Referenced by ansicol_set_pair().

                                                       {
        ansicol_set ( colour, '3' );
}
static void ansicol_background ( unsigned int  colour) [static]

Set ANSI background colour.

Parameters:
colourColour index

Definition at line 80 of file ansicol.c.

References ansicol_set().

Referenced by ansicol_set_pair().

                                                       {
        ansicol_set ( colour, '4' );
}
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;
}

Variable Documentation

struct ansicol_pair ansicol_pairs[] [static]