started implementation for coloured outupt
This commit is contained in:
1 parent
1149db2312
commit
fe4b863d19
2 files changed
+113
No files matched your search
@@ -0,0 +1,94 @@
|
|||||||
|
/* ------------------------------------------------------------------
|
||||||
|
* -- project: SCAN
|
||||||
|
* -- description: abstraction for terminal control sequences
|
||||||
|
* ------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __FORMAT_H
|
||||||
|
#define __FORMAT_H
|
||||||
|
|
||||||
|
/* -- type definitions */
|
||||||
|
typedef struct {
|
||||||
|
unsigned char black;
|
||||||
|
unsigned char red;
|
||||||
|
unsigned char green;
|
||||||
|
unsigned char yellow;
|
||||||
|
unsigned char blue;
|
||||||
|
unsigned char magenta;
|
||||||
|
unsigned char cyan;
|
||||||
|
unsigned char white;
|
||||||
|
unsigned char extended;
|
||||||
|
unsigned char normal;
|
||||||
|
} colours_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned char bold;
|
||||||
|
unsigned char dim;
|
||||||
|
unsigned char italic;
|
||||||
|
unsigned char underlined;
|
||||||
|
unsigned char blinking;
|
||||||
|
unsigned char reversed;
|
||||||
|
unsigned char invisible;
|
||||||
|
unsigned char strikethrough;
|
||||||
|
} style_t;
|
||||||
|
|
||||||
|
|
||||||
|
/* -- constant definitions */
|
||||||
|
const char* ESCAPE = "\x1b";
|
||||||
|
const char* SEQUENCE_PREFIX = "\x1b[";
|
||||||
|
const char* SEQUENCE_SUFFIX = "m";
|
||||||
|
|
||||||
|
const style_t STYLE_SET = {
|
||||||
|
.bold = 1u,
|
||||||
|
.dim = 2u,
|
||||||
|
.italic = 3u,
|
||||||
|
.underlined = 4u,
|
||||||
|
.blinking = 5u,
|
||||||
|
.reversed = 7u,
|
||||||
|
.invisible = 8u,
|
||||||
|
.strikethrough = 9u,
|
||||||
|
};
|
||||||
|
|
||||||
|
const style_t STYLE_RESET = {
|
||||||
|
.bold = 22u,
|
||||||
|
.dim = 22u,
|
||||||
|
.italic = 23u,
|
||||||
|
.underlined = 24u,
|
||||||
|
.blinking = 25u,
|
||||||
|
.reversed = 27u,
|
||||||
|
.invisible = 28u,
|
||||||
|
.strikethrough = 29u,
|
||||||
|
};
|
||||||
|
|
||||||
|
const colours_t COLOUR_FG = {
|
||||||
|
.black = 30u,
|
||||||
|
.red = 31u,
|
||||||
|
.green = 32u,
|
||||||
|
.yellow = 33u,
|
||||||
|
.blue = 34u,
|
||||||
|
.magenta = 35u,
|
||||||
|
.cyan = 36u,
|
||||||
|
.white = 37u,
|
||||||
|
.extended = 38u,
|
||||||
|
.normal = 39u,
|
||||||
|
};
|
||||||
|
|
||||||
|
const colours_t COLOUR_BG = {
|
||||||
|
.black = 40u,
|
||||||
|
.red = 41u,
|
||||||
|
.green = 42u,
|
||||||
|
.yellow = 43u,
|
||||||
|
.blue = 44u,
|
||||||
|
.magenta = 45u,
|
||||||
|
.cyan = 46u,
|
||||||
|
.white = 47u,
|
||||||
|
.extended = 48u,
|
||||||
|
.normal = 49u,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* -- function prototypes */
|
||||||
|
void format_reset( void );
|
||||||
|
void format_set_style( unsigned char style );
|
||||||
|
void format_reset_style( unsigned char style );
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "format.h"
|
||||||
|
|
||||||
|
void format_reset( void )
|
||||||
|
{
|
||||||
|
printf( "%s0%s", SEQUENCE_PREFIX, SEQUENCE_SUFFIX );
|
||||||
|
}
|
||||||
|
|
||||||
|
void format_set_style( unsigned char style )
|
||||||
|
{
|
||||||
|
if ( COLOUR_FG.extended == style ) return;
|
||||||
|
if ( COLOUR_BG.extended == style ) return;
|
||||||
|
|
||||||
|
printf( "%s%d%s", SEQUENCE_PREFIX, style, SEQUENCE_SUFFIX );
|
||||||
|
}
|
||||||
|
|
||||||
|
// void format_reset_style( unsigned char style )
|
||||||
|
// {
|
||||||
|
// }
|
||||||
Reference in new issue
Block a user