-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlog-styled-message.js
45 lines (42 loc) · 1.48 KB
/
log-styled-message.js
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
const ansi = require('ansi-styles');
const csound = require('bindings')('csound-api.node');
const textColors = {
[csound.MSG_FG_BLACK] : ansi.black,
[csound.MSG_FG_RED] : ansi.red,
[csound.MSG_FG_GREEN] : ansi.green,
[csound.MSG_FG_YELLOW] : ansi.yellow,
[csound.MSG_FG_BLUE] : ansi.blue,
[csound.MSG_FG_MAGENTA] : ansi.magenta,
[csound.MSG_FG_CYAN] : ansi.cyan,
[csound.MSG_FG_WHITE] : ansi.gray
};
const backgroundColors = {
[csound.MSG_BG_BLACK] : ansi.bgBlack,
[csound.MSG_BG_RED] : ansi.bgRed,
[csound.MSG_BG_GREEN] : ansi.bgGreen,
[csound.MSG_BG_ORANGE] : ansi.bgYellow,
[csound.MSG_BG_BLUE] : ansi.bgBlue,
[csound.MSG_BG_MAGENTA] : ansi.bgMagenta,
[csound.MSG_BG_CYAN] : ansi.bgCyan,
[csound.MSG_BG_GREY] : ansi.bgWhite
};
const Csound = csound.Create();
csound.SetMessageCallback(Csound, (attributes, string) => {
let color = textColors[attributes & csound.MSG_FG_COLOR_MASK];
if (color)
string = color.open + string + color.close;
if (attributes & csound.MSG_FG_BOLD)
string = ansi.bold.open + string + ansi.bold.close;
if (attributes & csound.MSG_FG_UNDERLINE)
string = ansi.underline.open + string + ansi.underline.close;
color = backgroundColors[attributes & csound.MSG_BG_COLOR_MASK];
if (color)
string = color.open + string + color.close;
console.log(string);
});
csound.MessageS(
Csound,
csound.MSG_FG_YELLOW | csound.MSG_FG_UNDERLINE | csound.MSG_BG_BLUE,
'Hail!'
);
csound.Destroy(Csound);