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) More...
 
static void ansicol_foreground (unsigned int colour)
 Set ANSI foreground colour. More...
 
static void ansicol_background (unsigned int colour)
 Set ANSI background colour. More...
 
void ansicol_set_pair (unsigned int cpair)
 Set ANSI foreground and background colour. More...
 
int ansicol_define_pair (unsigned int cpair, unsigned int foreground, unsigned int background)
 Define ANSI colour pair. More...
 

Variables

static struct ansicol_pair ansicol_pairs []
 ANSI colour pair definitions. More...
 

Detailed Description

ANSI colours.

Definition in file ansicol.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

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

57  {
58 
59  /* Colour indices are hardcoded and should never be out of range */
60  assert ( colour < 10 );
61 
62  /* Set basic colour */
63  printf ( CSI "%c%dm", which, colour );
64 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
#define CSI
Control Sequence Introducer.
Definition: ansiesc.h:95
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define colour
Colour for debug messages.
Definition: acpi.c:39

Referenced by ansicol_background(), and ansicol_foreground().

◆ ansicol_foreground()

static void ansicol_foreground ( unsigned int  colour)
static

Set ANSI foreground colour.

Parameters
colourColour index

Definition at line 71 of file ansicol.c.

71  {
72  ansicol_set ( colour, '3' );
73 }
#define colour
Colour for debug messages.
Definition: acpi.c:39
__weak void ansicol_set(unsigned int colour, unsigned int which)
Set ANSI colour (when no colour definition support is present)
Definition: ansicol.c:57

References ansicol_set(), and colour.

Referenced by ansicol_set_pair().

◆ ansicol_background()

static void ansicol_background ( unsigned int  colour)
static

Set ANSI background colour.

Parameters
colourColour index

Definition at line 80 of file ansicol.c.

80  {
81  ansicol_set ( colour, '4' );
82 }
#define colour
Colour for debug messages.
Definition: acpi.c:39
__weak void ansicol_set(unsigned int colour, unsigned int which)
Set ANSI colour (when no colour definition support is present)
Definition: ansicol.c:57

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

89  {
90  struct ansicol_pair *pair;
91 
92  /* Colour pair indices are hardcoded and should never be out of range */
93  assert ( cpair < ( sizeof ( ansicol_pairs ) /
94  sizeof ( ansicol_pairs[0] ) ) );
95 
96  /* Set both foreground and background colours */
97  pair = &ansicol_pairs[cpair];
100 }
static void ansicol_background(unsigned int colour)
Set ANSI background colour.
Definition: ansicol.c:80
uint8_t foreground
Foreground colour index.
Definition: ansicol.h:65
An ANSI colour pair definition.
Definition: ansicol.h:63
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static struct ansicol_pair ansicol_pairs[]
ANSI colour pair definitions.
Definition: ansicol.c:40
static void ansicol_foreground(unsigned int colour)
Set ANSI foreground colour.
Definition: ansicol.c:71
uint8_t background
Background colour index.
Definition: ansicol.h:67

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

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

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:17
#define COLOR_ALERT_FG
Definition: colour.h:24
#define COLOR_SEPARATOR_BG
Definition: colour.h:19
#define CPAIR_EDIT
Editable text.
Definition: ansicol.h:49
#define COLOR_EDIT_BG
Definition: colour.h:22
#define CPAIR_NORMAL
Normal text.
Definition: ansicol.h:40
#define COLOR_URL_BG
Definition: colour.h:28
#define COLOR_ALERT_BG
Definition: colour.h:25
#define COLOR_NORMAL_BG
Definition: colour.h:13
#define CPAIR_PXE
PXE selected menu entry.
Definition: ansicol.h:58
#define COLOR_NORMAL_FG
Definition: colour.h:12
#define COLOR_SEPARATOR_FG
Definition: colour.h:18
#define CPAIR_ALERT
Error text.
Definition: ansicol.h:52
#define CPAIR_URL
URL text.
Definition: ansicol.h:55
#define COLOR_SELECT_BG
Definition: colour.h:16
#define COLOR_EDIT_FG
Definition: colour.h:21
#define COLOR_PXE_BG
Definition: colour.h:31
#define CPAIR_SEPARATOR
Unselectable text (e.g.
Definition: ansicol.h:46
#define CPAIR_DEFAULT
Default colour pair.
Definition: ansicol.h:37
#define COLOR_SELECT_FG
Definition: colour.h:15
#define CPAIR_SELECT
Highlighted text.
Definition: ansicol.h:43
#define COLOR_URL_FG
Definition: colour.h:27
#define COLOR_PXE_FG
Definition: colour.h:30

ANSI colour pair definitions.

Definition at line 40 of file ansicol.c.

Referenced by ansicol_define_pair(), and ansicol_set_pair().