-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME
More file actions
367 lines (302 loc) · 11.3 KB
/
README
File metadata and controls
367 lines (302 loc) · 11.3 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*
* consolelog.node.js
*
* This is a collection of two node.js modules:
* termcolor.js - terminal color output and cursor positioning manipulation
* consolelog.js - console log output stylization and customization (uses termcolor module)
*
* Please note: I am not a terminal emulation expert. This may not work in every terminal
* emulator. Your mileage may vary.
*
* by Chad Etzel - December 11, 2009
*
* Hacker License:
* Feel free to hack at will
*/
==================================
= =
= example.js =
= =
==================================
An example node.js script which demonstrates some of the functionality
of the two included modules.
To run, issue the following at a command prompt:
node example.js
==================================
= =
= termcolor.js =
= =
==================================
terminal color output and cursor positioning module.
example usage:
var tc = require("./termcolor");
PUBLIC FUNCTIONS:
cursorPosition(row,col);
Overview:
Positions the terminal cursor at the row and column specified.
Parameter:
row - (number) value of the row to which the cursor will move.
col - (number) value of the column to which the cursor will move.
cursorUp(i);
Overview:
Moves the cursor up the specified number of rows
Parameter:
i - (number) OPTIONAL - number of rows to move cursor up. If unspecified the value defaults to 1.
cursorDown(i);
Overview:
Moves the cursor down the specified number of rows
Parameter:
i - (number) OPTIONAL - number of rows to move cursor down. If unspecified the value defaults to 1.
cursorForward(i);
Overview:
Moves the cursor forward the specified number of columns
Parameter:
i - (number) OPTIONAL - number of columns to move cursor forward. If unspecified the value defaults to 1.
cursorBack(i);
Overview:
Moves the cursor back the specified number of columns
Parameter:
i - (number) OPTIONAL - number of columns to move cursor back. If unspecified the value defaults to 1.
terminalFontReset();
Overview:
Resets the terminal "font" (color, background, attributes) to the terminal defaults.
Parameter:
none;
terminalSetFont(color, bg, attr);
Overview:
Sets the terminal "font" (color, background, attributes) to the specified values.
Parameter:
color - (number) value of the color to use (use the colors map)
bg - (number) value of the background to use (use the colors map)
attr - (number) value of the attribute to use (use the attrs map)
terminalSetFontColor(color);
Overview:
Sets the terminal "font" color to the specified value.
Parameter:
color - (number) value of the color to use (use the colors map)
terminalSetFontBG(bg);
Overview:
Sets the terminal "font" background to the specified value.
Parameter:
bg - (number) value of the color to use (use the colors map)
terminalSetFontAttr(attr);
Overview:
Sets the terminal "font" attribute to the specified value.
Parameter:
attr - (number) value of the color to use (use the attrs map)
resetTerminal;
Overview:
Resets the terminal by clearing the screen and reseting the font
to the terminal default
Parameter:
none;
test;
Overview:
Run the test method of the termcolor module to see different output
formats in action.
Parameter:
none;
PUBLIC VARIABLES:
colors;
Overview:
Basically a hashmap of standard terminal color values, used in
setting parameters for several termcolor functions
attrs;
Overview:
Basically a hashmap of standard terminal display attribute values,
(such as bright, underlined, dim, reverse, ...) used in setting
parameters for several termcolor functions
==================================
= =
= consolelog.js =
= =
==================================
terminal console logging module
example usage:
var cl = require("./consolelog");
PUBLIC FUNCTIONS:
log(msg);
Overview:
writes a message to the console screen.
default output format is to use the terminal default settings.
Parameters:
msg - the message to display to the console.
info(msg);
Overview:
writes a message to the console screen.
default output format is GREEN with BRIGHT attribute
Parameters:
msg - the message to display to the console.
warn(msg);
Overview:
writes a message to the console screen.
default output format is YELLOW with BRIGHT attribute
Parameters:
msg - the message to display to the console.
error(msg);
Overview:
writes a message to the console screen.
default output format is RED with BRIGHT attribute
Parameters:
msg - the message to display to the console.
puts(msg);
Overview:
an alias of the consolelog.log function for convenience
setLogColor(color);
Overview:
Sets the output color for standard log messages
Parameters:
color - (number or string) the termcolor.colors map value or the
upper-cased string name of the color it represents
setInfoColor(color);
Overview:
Sets the output color for info log messages
Parameters:
color - (number or string) the termcolor.colors map value or the
upper-cased string name of the color it represents
setWarnColor(color);
Overview:
Sets the output color for warning messages
Parameters:
color - (number or string) the termcolor.colors map value or the
upper-cased string name of the color it represents
setErrorColor(color);
Overview:
Sets the output color for error messages
Parameters:
color - (number or string) the termcolor.colors map value or the
upper-cased string name of the color it represents
setLogPrefix(prefix);
Overview:
Sets the prefix string for standard messages
Parameters:
prefix - (string or function) the prefix to print before each message.
if it is a string, just the string will be printed.
if it is a function, it should return a string. the function
will be evaluated for each message and the returned string
will be printed
setInfoPrefix(prefix);
Overview:
Sets the prefix string for info messages
Parameters:
prefix - (string or function) the prefix to print before each message.
if it is a string, just the string will be printed.
if it is a function, it should return a string. the function
will be evaluated for each message and the returned string
will be printed
setWarnPrefix(prefix);
Overview:
Sets the prefix string for warning messages
Parameters:
prefix - (string or function) the prefix to print before each message.
if it is a string, just the string will be printed.
if it is a function, it should return a string. the function
will be evaluated for each message and the returned string
will be printed
setErrorPrefix(prefix);
Overview:
Sets the prefix string for error messages
Parameters:
prefix - (string or function) the prefix to print before each message.
if it is a string, just the string will be printed.
if it is a function, it should return a string. the function
will be evaluated for each message and the returned string
will be printed
setAllPrefix(prefix);
Overview:
Sets the prefix string for all messages
Parameters:
prefix - (string or function) the prefix to print before each message.
if it is a string, just the string will be printed.
if it is a function, it should return a string. the function
will be evaluated for each message and the returned string
will be printed
setLogPostfix(prefix);
Overview:
Sets the postfix string for standard messages
Parameters:
postfix - (string or function) the postfix to print before each message.
if it is a string, just the string will be printed.
if it is a function, it should return a string. the function
will be evaluated for each message and the returned string
will be printed
setInfoPostfix(postfix);
Overview:
Sets the postfix string for info messages
Parameters:
postfix - (string or function) the postfix to print before each message.
if it is a string, just the string will be printed.
if it is a function, it should return a string. the function
will be evaluated for each message and the returned string
will be printed
setWarnPostfix(postfix);
Overview:
Sets the postfix string for warning messages
Parameters:
postfix - (string or function) the postfix to print before each message.
if it is a string, just the string will be printed.
if it is a function, it should return a string. the function
will be evaluated for each message and the returned string
will be printed
setErrorPostfix(postfix);
Overview:
Sets the postfix string for error messages
Parameters:
postfix - (string or function) the postfix to print before each message.
if it is a string, just the string will be printed.
if it is a function, it should return a string. the function
will be evaluated for each message and the returned string
will be printed
setAllPostfix(postfix);
Overview:
Sets the postfix string for all messages
Parameters:
postfix - (string or function) the postfix to print before each message.
if it is a string, just the string will be printed.
if it is a function, it should return a string. the function
will be evaluated for each message and the returned string
will be printed
restoreDefaultColors();
Overview:
restores the default colors for all message types:
log - terminal default
info - GREEN and BRIGHT
warn - YELLOW and BRIGHT
log - RED and BRIGHT
restoreDefaultPrefixes;
Overview:
restores the default prefixes for all message types:
log - >>>
info - iii
warn - ***
log - !!!
restoreDefaultPostfixes;
Overview:
restores the default postfixes for all message types (all empty strings)
restoreDefaultPreAndPostfixes;
Overview:
restores the default prefixes and postfixes for all message types
restoreDefaults;
Overview:
restores the default colors, prefixes, and postfixes for all message types
test;
Overview:
a test function which will display most of the capabilities of the consolelog module.
PUBLIC VARIABLES:
tc;
Overview:
an instance of the internal termcolor object
disableDoubleNewlines;
Overview:
boolean which determines whether double trailing
newlines are removed when a message is logged to
the console. Useful for when your message is coming
from an outside source (such as a network socket).
Default value is true.
==================================
= =
= CHANGE LOG =
= =
==================================
v 0.1.0 (December 11, 2009)
- Initial checkin of termcolor and consolelog modules.