term: implement bright background colour; linux/darwin support for format codes
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "../../print.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <Windows.h>
|
||||
#include "../../print.h"
|
||||
|
||||
int z__b_stream_is_tty(FILE *fp)
|
||||
{
|
||||
@@ -38,7 +39,6 @@ int z__b_stream_cursorpos(FILE *in, FILE *out, unsigned int *x, unsigned int *y)
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
HANDLE console = (HANDLE)_get_osfhandle(fileno(in));
|
||||
BOOL status = GetConsoleScreenBufferInfo(console, &csbi);
|
||||
|
||||
|
||||
if (status == FALSE) {
|
||||
return -1;
|
||||
@@ -55,16 +55,16 @@ int z__b_stream_cursorpos(FILE *in, FILE *out, unsigned int *x, unsigned int *y)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define APPLY_FLAG(mod, attrib, x, y) \
|
||||
#define APPLY_FLAG(mod, attrib, x, y) \
|
||||
if ((mod) & (x)) { \
|
||||
(attrib) |= (y); \
|
||||
}
|
||||
|
||||
#define APPLY_FLAG_X(mod, attrib, x, y) \
|
||||
if ((mod) & (x)) { \
|
||||
(attrib) |= (y); \
|
||||
} else { \
|
||||
(attrib) &= ~(y); \
|
||||
#define APPLY_FLAG_X(mod, attrib, x, y) \
|
||||
if ((mod) & (x)) { \
|
||||
(attrib) |= (y); \
|
||||
} else { \
|
||||
(attrib) &= ~(y); \
|
||||
}
|
||||
|
||||
int z__b_stream_set_modifier(FILE *fp, unsigned int mod)
|
||||
@@ -74,7 +74,7 @@ int z__b_stream_set_modifier(FILE *fp, unsigned int mod)
|
||||
|
||||
HANDLE console = (HANDLE)_get_osfhandle(fileno(fp));
|
||||
BOOL status = GetConsoleScreenBufferInfo(console, &csbi);
|
||||
|
||||
|
||||
if (status == FALSE) {
|
||||
return -1;
|
||||
}
|
||||
@@ -89,27 +89,44 @@ int z__b_stream_set_modifier(FILE *fp, unsigned int mod)
|
||||
|
||||
if (Z__B_STREAM_MOD_GET_FG_COLOUR(mod) != 0) {
|
||||
if (mod & Z__B_STREAM_MOD_BLACK) {
|
||||
attrib &= ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
attrib
|
||||
&= ~(FOREGROUND_RED | FOREGROUND_GREEN
|
||||
| FOREGROUND_BLUE);
|
||||
} else {
|
||||
APPLY_FLAG_X(mod, attrib, Z__B_STREAM_MOD_RED, FOREGROUND_RED);
|
||||
APPLY_FLAG_X(mod, attrib, Z__B_STREAM_MOD_GREEN, FOREGROUND_GREEN);
|
||||
APPLY_FLAG_X(mod, attrib, Z__B_STREAM_MOD_BLUE, FOREGROUND_BLUE);
|
||||
APPLY_FLAG_X(
|
||||
mod, attrib, Z__B_STREAM_MOD_RED, FOREGROUND_RED);
|
||||
APPLY_FLAG_X(
|
||||
mod, attrib, Z__B_STREAM_MOD_GREEN,
|
||||
FOREGROUND_GREEN);
|
||||
APPLY_FLAG_X(
|
||||
mod, attrib, Z__B_STREAM_MOD_BLUE, FOREGROUND_BLUE);
|
||||
}
|
||||
}
|
||||
|
||||
if (Z__B_STREAM_MOD_GET_BG_COLOUR(mod) != 0) {
|
||||
if (mod & Z__B_STREAM_MOD_BG_BLACK) {
|
||||
attrib &= ~(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
|
||||
attrib
|
||||
&= ~(BACKGROUND_RED | BACKGROUND_GREEN
|
||||
| BACKGROUND_BLUE);
|
||||
} else {
|
||||
APPLY_FLAG_X(mod, attrib, Z__B_STREAM_MOD_BG_RED, BACKGROUND_RED);
|
||||
APPLY_FLAG_X(mod, attrib, Z__B_STREAM_MOD_BG_GREEN, BACKGROUND_GREEN);
|
||||
APPLY_FLAG_X(mod, attrib, Z__B_STREAM_MOD_BG_BLUE, BACKGROUND_BLUE);
|
||||
APPLY_FLAG_X(
|
||||
mod, attrib, Z__B_STREAM_MOD_BG_RED,
|
||||
BACKGROUND_RED);
|
||||
APPLY_FLAG_X(
|
||||
mod, attrib, Z__B_STREAM_MOD_BG_GREEN,
|
||||
BACKGROUND_GREEN);
|
||||
APPLY_FLAG_X(
|
||||
mod, attrib, Z__B_STREAM_MOD_BG_BLUE,
|
||||
BACKGROUND_BLUE);
|
||||
}
|
||||
}
|
||||
|
||||
APPLY_FLAG(mod, attrib, Z__B_STREAM_MOD_ULINE, COMMON_LVB_UNDERSCORE);
|
||||
APPLY_FLAG(mod, attrib, Z__B_STREAM_MOD_INVERT, COMMON_LVB_REVERSE_VIDEO);
|
||||
APPLY_FLAG(mod, attrib, Z__B_STREAM_MOD_BRIGHT | Z__B_STREAM_MOD_BOLD, FOREGROUND_INTENSITY);
|
||||
APPLY_FLAG(
|
||||
mod, attrib, Z__B_STREAM_MOD_BRIGHT | Z__B_STREAM_MOD_BOLD,
|
||||
FOREGROUND_INTENSITY);
|
||||
APPLY_FLAG(mod, attrib, Z__B_STREAM_MOD_BG_BRIGHT, BACKGROUND_INTENSITY);
|
||||
|
||||
SetConsoleTextAttribute(console, attrib);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user