-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasyansi.js
137 lines (134 loc) · 3.25 KB
/
easyansi.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
exports.fromHTML = function(text){
return text.replace(/\<b\>/g, `\x1B[1m`)
.replace(/\<dim\>/g, "\x1B[2m")
.replace(/\<i\>/g, `\x1B[3m`)
.replace(/\<u\>/g, "\x1B[4m")
.replace(/\<blink\>/g, `\x1B[5m`)
.replace(/\<s\>/g, "\x1B[9m")
.replace(/\<\/b\>/g, "\x1B[22m")
.replace(/\<\/dim\>/g, "\x1B[22m")
.replace(/\<\/i\>/g, "\x1B[23m")
.replace(/\<\/u\>/g, "\x1B[24m")
.replace(/\<\/blink\>/g, "\x1B[25m")
.replace(/\<\/s\>/g, "\x1B[29m")
}
exports.resetModes = function(){
return "\x1B[0m";
};
exports.styleMode = function(mode){
switch(mode){
case "bold":
return `\x1B[1m`;
break;
case "dim":
return `\x1B[2m`;
break;
case "italic":
return `\x1B[3m`;
break;
case "underline":
return `\x1B[4m`;
break;
case "blink":
return `\x1B[5m`;
break;
case "inverse":
return `\x1B[7m`;
break;
case "hidden":
return `\x1B[8m`;
break;
case "strikethrough":
return `\x1B[9m`;
break;
case "reset":
return "\x1B[0m";
break;
}
};
exports.colorTextMode = function(id){
if((id >= 30 && id <= 37) ||
(id >= 39 && id <= 47) ||
(id == 49) ||
(id >= 90 && id <= 97) ||
(id >= 100 && id <= 107)){
return `\x1B[${parseInt(id)}m`;
}
};
exports.colorMode16 = function(fob, id){
return `\x1B[${2+(fob?1:2)}8;5;${parseInt(id)}m`;
}
exports.colorModeRGB = function(fob,r,g,b){
return `\x1B[${2+(fob?1:2)}8;2;${parseInt(r)};${parseInt(g)};${parseInt(b)}m`
}
exports.clearFromCursor = function(){
process.stdout.write(`\x1B[0J`)
}
exports.clearToCursor = function(){
process.stdout.write(`\x1B[1J`)
}
exports.clearScreen = function(){
process.stdout.write(`\x1B[2J`)
}
exports.clearLineFromCursor = function(){
process.stdout.write(`\x1B[0K`)
}
exports.clearLineToCursor = function(){
process.stdout.write(`\x1B[1K`)
}
exports.clearLine = function(){
process.stdout.write(`\x1B[2K`)
}
exports.requestCursorPos = function() {
process.stdout.write(`\x1B[6n`)
}
exports.cursorHome = function() {
process.stdout.write(`\x1B[H`)
}
exports.cursorTo = function(x,y) {
process.stdout.write(`\x1B[${parseInt(y)};${parseInt(x)}H`)
}
exports.cursorUp = function(num) {
process.stdout.write(`\x1B[${parseInt(num)}A`)
}
exports.cursorDown = function(num) {
process.stdout.write(`\x1B[${parseInt(num)}B`)
}
exports.cursorLeft = function(num) {
process.stdout.write(`\x1B[${parseInt(num)}D`)
}
exports.cursorRight = function(num) {
process.stdout.write(`\x1B[${parseInt(num)}C`)
}
exports.cursorVisible = function(bool) {
process.stdout.write(`\x1B[?25`+(bool?"h":"l"))
}
exports.screenMode = function(mode, reset) {
process.stdout.write(`\x1B[=${parseInt(mode)}${reset?"l":"h"}`)
}
exports.SaveCursorPos = function(isdec) {
switch(isdec){
case true:
process.stdout.write(`\x1B 7`);
break;
case false:
process.stdout.write(`\x1B[s`);
break;
}
}
exports.ReturnToSavedPos = function(isdec){
switch(isdec){
case true:
process.stdout.write(`\x1B 8`);
break;
case false:
process.stdout.write(`\x1B[u`);
break;
}
}
exports.saveScreen = function() {
process.stdout.write(`\x1B[?47h`)
}
exports.restoreScreen = function() {
process.stdout.write(`\x1B[?47l`)
}