Initial commit
[yaffs-website] / node_modules / console-control-strings / index.js
1 'use strict'
2
3 // These tables borrowed from `ansi`
4
5 var prefix = '\x1b['
6
7 exports.up = function up (num) {
8   return prefix + (num || '') + 'A'
9 }
10
11 exports.down = function down (num) {
12   return prefix + (num || '') + 'B'
13 }
14
15 exports.forward = function forward (num) {
16   return prefix + (num || '') + 'C'
17 }
18
19 exports.back = function back (num) {
20   return prefix + (num || '') + 'D'
21 }
22
23 exports.nextLine = function nextLine (num) {
24   return prefix + (num || '') + 'E'
25 }
26
27 exports.previousLine = function previousLine (num) {
28   return prefix + (num || '') + 'F'
29 }
30
31 exports.horizontalAbsolute = function horizontalAbsolute (num) {
32   if (num == null) throw new Error('horizontalAboslute requires a column to position to')
33   return prefix + num + 'G'
34 }
35
36 exports.eraseData = function eraseData () {
37   return prefix + 'J'
38 }
39
40 exports.eraseLine = function eraseLine () {
41   return prefix + 'K'
42 }
43
44 exports.goto = function (x, y) {
45   return prefix + y + ';' + x + 'H'
46 }
47
48 exports.gotoSOL = function () {
49   return '\r'
50 }
51
52 exports.beep = function () {
53   return '\x07'
54 }
55
56 exports.hideCursor = function hideCursor () {
57   return prefix + '?25l'
58 }
59
60 exports.showCursor = function showCursor () {
61   return prefix + '?25h'
62 }
63
64 var colors = {
65   reset: 0,
66 // styles
67   bold: 1,
68   italic: 3,
69   underline: 4,
70   inverse: 7,
71 // resets
72   stopBold: 22,
73   stopItalic: 23,
74   stopUnderline: 24,
75   stopInverse: 27,
76 // colors
77   white: 37,
78   black: 30,
79   blue: 34,
80   cyan: 36,
81   green: 32,
82   magenta: 35,
83   red: 31,
84   yellow: 33,
85   bgWhite: 47,
86   bgBlack: 40,
87   bgBlue: 44,
88   bgCyan: 46,
89   bgGreen: 42,
90   bgMagenta: 45,
91   bgRed: 41,
92   bgYellow: 43,
93
94   grey: 90,
95   brightBlack: 90,
96   brightRed: 91,
97   brightGreen: 92,
98   brightYellow: 93,
99   brightBlue: 94,
100   brightMagenta: 95,
101   brightCyan: 96,
102   brightWhite: 97,
103
104   bgGrey: 100,
105   bgBrightBlack: 100,
106   bgBrightRed: 101,
107   bgBrightGreen: 102,
108   bgBrightYellow: 103,
109   bgBrightBlue: 104,
110   bgBrightMagenta: 105,
111   bgBrightCyan: 106,
112   bgBrightWhite: 107
113 }
114
115 exports.color = function color (colorWith) {
116   if (arguments.length !== 1 || !Array.isArray(colorWith)) {
117     colorWith = Array.prototype.slice.call(arguments)
118   }
119   return prefix + colorWith.map(colorNameToCode).join(';') + 'm'
120 }
121
122 function colorNameToCode (color) {
123   if (colors[color] != null) return colors[color]
124   throw new Error('Unknown color or style name: ' + color)
125 }