-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathatr2ansi.c
49 lines (40 loc) · 1.16 KB
/
atr2ansi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
** Form a command string for ANSI.SYS to set a given video attribute
**
** Public domain demo by Bob Stout
*/
#include <string.h>
#include "scrnmacs.h"
static void add_str(char *, char *);
/*
** Example:
** Video attribute of yellow text on blue background = BG_(BLUE_)+YELLOW_
*/
char *make_ansi(int vatr)
{
static char string[40];
static char *fore[8] = {"30","34","32","36","31","35","33","37"};
static char *back[8] = {"40","44","42","46","41","45","43","47"};
strcpy(string, "\033[");
if (vatr == 0x07)
strcat(string, "0");
else
{
if (vatr & 0x80)
add_str(string, "5");
if (vatr & 0x08)
add_str(string, "1");
add_str(string, fore[vatr & 0x07]);
add_str(string, back[(vatr & 0x70) >> 4]);
}
strcat(string, "m");
return string;
}
static void add_str(char *string1, char *string2)
{
char last_char;
last_char = string1[strlen(string1) - 1];
if (last_char != '[')
strcat(string1, ";");
strcat(string1, string2);
}