StuBS
TextMode::Attribute Union Reference

Structure of a character attribute consists of 4 bit fore- and 3 bit background color, and a single blink bit. More...

#include <textmode.h>

Public Member Functions

 Attribute (Color foreground=LIGHT_GREY, Color background=BLACK, bool blink=false)
 Attribute constructor (with default values)
 

Public Attributes

uint8_t value
 combined value
 
uint8_t foreground: 4
 .... XXXX Foreground color
 
uint8_t background: 3
 .XXX .... Background color
 
uint8_t blink: 1
 X... .... Blink
 

Detailed Description

Structure of a character attribute consists of 4 bit fore- and 3 bit background color, and a single blink bit.

Bit fields can notably simplify the access and code readability.

Note
Type punning is indeed undefined behavior in C++. However, gcc explicitly allows this construct as a language extension. Some compilers (other than gcc might allow this feature only by disabling strict aliasing (-fno-strict-aliasing). In StuBS we use this feature extensively due to the improved code readability.

Constructor & Destructor Documentation

◆ Attribute()

TextMode::Attribute::Attribute ( Color  foreground = LIGHT_GREY,
Color  background = BLACK,
bool  blink = false 
)
inlineexplicit

Attribute constructor (with default values)

Parameters
foregroundForeground color (Default: LIGHT_GREY)
backgroundBackground color (Default: BLACK)
blinkBlink if true (default: no blinking)

The documentation for this union was generated from the following file: