index.js
2.28 KB
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
'use strict'
// These tables borrowed from `ansi`
var prefix = '\x1b['
exports.up = function up (num) {
return prefix + (num || '') + 'A'
}
exports.down = function down (num) {
return prefix + (num || '') + 'B'
}
exports.forward = function forward (num) {
return prefix + (num || '') + 'C'
}
exports.back = function back (num) {
return prefix + (num || '') + 'D'
}
exports.nextLine = function nextLine (num) {
return prefix + (num || '') + 'E'
}
exports.previousLine = function previousLine (num) {
return prefix + (num || '') + 'F'
}
exports.horizontalAbsolute = function horizontalAbsolute (num) {
if (num == null) throw new Error('horizontalAboslute requires a column to position to')
return prefix + num + 'G'
}
exports.eraseData = function eraseData () {
return prefix + 'J'
}
exports.eraseLine = function eraseLine () {
return prefix + 'K'
}
exports.goto = function (x, y) {
return prefix + y + ';' + x + 'H'
}
exports.gotoSOL = function () {
return '\r'
}
exports.beep = function () {
return '\x07'
}
exports.hideCursor = function hideCursor () {
return prefix + '?25l'
}
exports.showCursor = function showCursor () {
return prefix + '?25h'
}
var colors = {
reset: 0,
// styles
bold: 1,
italic: 3,
underline: 4,
inverse: 7,
// resets
stopBold: 22,
stopItalic: 23,
stopUnderline: 24,
stopInverse: 27,
// colors
white: 37,
black: 30,
blue: 34,
cyan: 36,
green: 32,
magenta: 35,
red: 31,
yellow: 33,
bgWhite: 47,
bgBlack: 40,
bgBlue: 44,
bgCyan: 46,
bgGreen: 42,
bgMagenta: 45,
bgRed: 41,
bgYellow: 43,
grey: 90,
brightBlack: 90,
brightRed: 91,
brightGreen: 92,
brightYellow: 93,
brightBlue: 94,
brightMagenta: 95,
brightCyan: 96,
brightWhite: 97,
bgGrey: 100,
bgBrightBlack: 100,
bgBrightRed: 101,
bgBrightGreen: 102,
bgBrightYellow: 103,
bgBrightBlue: 104,
bgBrightMagenta: 105,
bgBrightCyan: 106,
bgBrightWhite: 107
}
exports.color = function color (colorWith) {
if (arguments.length !== 1 || !Array.isArray(colorWith)) {
colorWith = Array.prototype.slice.call(arguments)
}
return prefix + colorWith.map(colorNameToCode).join(';') + 'm'
}
function colorNameToCode (color) {
if (colors[color] != null) return colors[color]
throw new Error('Unknown color or style name: ' + color)
}