iPXE
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)
 FILE_SECBOOT (PERMITTED)
__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()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ ansicol_set()

__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 58 of file ansicol.c.

58 {
59
60 /* Colour indices are hardcoded and should never be out of range */
61 assert ( colour < 10 );
62
63 /* Set basic colour */
64 printf ( CSI "%c%dm", which, colour );
65}
#define colour
Colour for debug messages.
Definition acpi.c:42
#define CSI
Control Sequence Introducer.
Definition ansiesc.h:96
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465

References __weak, assert, colour, CSI, and printf().

Referenced by ansicol_background(), and ansicol_foreground().

◆ ansicol_foreground()

void ansicol_foreground ( unsigned int colour)
static

Set ANSI foreground colour.

Parameters
colourColour index

Definition at line 72 of file ansicol.c.

72 {
73 ansicol_set ( colour, '3' );
74}
__weak void ansicol_set(unsigned int colour, unsigned int which)
Set ANSI colour (when no colour definition support is present)
Definition ansicol.c:58

References ansicol_set(), and colour.

Referenced by ansicol_set_pair().

◆ ansicol_background()

void ansicol_background ( unsigned int colour)
static

Set ANSI background colour.

Parameters
colourColour index

Definition at line 81 of file ansicol.c.

81 {
82 ansicol_set ( colour, '4' );
83}

References ansicol_set(), and colour.

Referenced by ansicol_set_pair().

◆ ansicol_set_pair()

void ansicol_set_pair ( unsigned int cpair)

Set ANSI foreground and background colour.

Parameters
cpairColour pair index

Definition at line 90 of file ansicol.c.

90 {
91 struct ansicol_pair *pair;
92
93 /* Colour pair indices are hardcoded and should never be out of range */
94 assert ( cpair < ( sizeof ( ansicol_pairs ) /
95 sizeof ( ansicol_pairs[0] ) ) );
96
97 /* Set both foreground and background colours */
98 pair = &ansicol_pairs[cpair];
101}
static void ansicol_background(unsigned int colour)
Set ANSI background colour.
Definition ansicol.c:81
static void ansicol_foreground(unsigned int colour)
Set ANSI foreground colour.
Definition ansicol.c:72
static struct ansicol_pair ansicol_pairs[]
ANSI colour pair definitions.
Definition ansicol.c:41
An ANSI colour pair definition.
Definition ansicol.h:64
uint8_t foreground
Foreground colour index.
Definition ansicol.h:66
uint8_t background
Background colour index.
Definition ansicol.h:68

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

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

◆ ansicol_define_pair()

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 111 of file ansicol.c.

112 {
113 struct ansicol_pair *pair;
114
115 /* Fail if colour index is out of range */
116 if ( cpair >= ( sizeof ( ansicol_pairs ) / sizeof ( ansicol_pairs[0] )))
117 return -EINVAL;
118
119 /* Update colour pair definition */
120 pair = &ansicol_pairs[cpair];
121 pair->foreground = foreground;
122 pair->background = background;
123 DBGC ( &ansicol_pairs[0], "ANSICOL redefined colour pair %d as "
124 "foreground %d background %d\n", cpair, foreground, background );
125
126 return 0;
127}
#define DBGC(...)
Definition compiler.h:505
#define EINVAL
Invalid argument.
Definition errno.h:429

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

Referenced by cpair_exec().

Variable Documentation

◆ ansicol_pairs

struct ansicol_pair ansicol_pairs[]
static
Initial value:
= {
}
#define COLOR_DEFAULT
Definition ansicol.h:18
#define COLOR_ALERT_BG
Definition colour.h:26
#define COLOR_EDIT_FG
Definition colour.h:22
#define COLOR_SEPARATOR_BG
Definition colour.h:20
#define COLOR_ALERT_FG
Definition colour.h:25
#define COLOR_URL_FG
Definition colour.h:28
#define COLOR_EDIT_BG
Definition colour.h:23
#define COLOR_PXE_FG
Definition colour.h:31
#define COLOR_NORMAL_BG
Definition colour.h:14
#define COLOR_NORMAL_FG
Definition colour.h:13
#define COLOR_SEPARATOR_FG
Definition colour.h:19
#define COLOR_PXE_BG
Definition colour.h:32
#define COLOR_SELECT_FG
Definition colour.h:16
#define COLOR_SELECT_BG
Definition colour.h:17
#define COLOR_URL_BG
Definition colour.h:29
#define CPAIR_SELECT
Highlighted text.
Definition ansicol.h:44
#define CPAIR_EDIT
Editable text.
Definition ansicol.h:50
#define CPAIR_NORMAL
Normal text.
Definition ansicol.h:41
#define CPAIR_DEFAULT
Default colour pair.
Definition ansicol.h:38
#define CPAIR_SEPARATOR
Unselectable text (e.g.
Definition ansicol.h:47
#define CPAIR_ALERT
Error text.
Definition ansicol.h:53
#define CPAIR_PXE
PXE selected menu entry.
Definition ansicol.h:59
#define CPAIR_URL
URL text.
Definition ansicol.h:56

ANSI colour pair definitions.

Definition at line 41 of file ansicol.c.

Referenced by ansicol_define_pair(), and ansicol_set_pair().