forked from workshopper/workshopper
-
Notifications
You must be signed in to change notification settings - Fork 5
/
term-util.js
43 lines (37 loc) · 865 Bytes
/
term-util.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
function repeat (ch, sz) {
return new Array(sz + 1).join(ch)
}
function wrap (s_, n) {
var s = String(s_)
return s + repeat(' ', Math.max(0, n + 1 - s.length))
}
function center (width, s) {
var n = (width - s.length) / 2
return ' ##'
+ repeat(' ', Math.floor(n))
+ yellow(bold(s))
+ repeat(' ', Math.ceil(n))
+ '##'
}
function cfn (sc, ec) {
return function (s) {
return sc + s + ec
}
}
var bold = cfn('\x1B[1m', '\x1B[22m')
, italic = cfn('\x1B[3m', '\x1B[23m')
, red = cfn('\x1B[31m', '\x1B[39m')
, green = cfn('\x1B[32m', '\x1B[39m')
, yellow = cfn('\x1B[33m', '\x1B[39m')
, blue = cfn('\x1B[34m', '\x1B[39m')
module.exports = {
repeat : repeat
, wrap : wrap
, center : center
, bold : bold
, italic : italic
, red : red
, green : green
, yellow : yellow
, blue : blue
}