|
1 |
| -this is a readme file |
| 1 | +/* |
| 2 | + * consolelog.node.js |
| 3 | + * |
| 4 | + * This is a collection of two node.js modules: |
| 5 | + * termcolor.js - terminal color output and cursor positioning manipulation |
| 6 | + * consolelog.js - console log output stylization and customization (uses termcolor module) |
| 7 | + * |
| 8 | + * Please note: I am not a terminal emulation expert. This may not work in every terminal |
| 9 | + * emulator. Your mileage may vary. |
| 10 | + * |
| 11 | + * by Chad Etzel - December 11, 2009 |
| 12 | + * |
| 13 | + * Hacker License: |
| 14 | + * Feel free to hack at will |
| 15 | + */ |
| 16 | + |
| 17 | +================================== |
| 18 | += = |
| 19 | += example.js = |
| 20 | += = |
| 21 | +================================== |
| 22 | + |
| 23 | +An example node.js script which demonstrates some of the functionality |
| 24 | +of the two included modules. |
| 25 | + |
| 26 | +To run, issue the following at a command prompt: |
| 27 | +node example.js |
| 28 | + |
| 29 | +================================== |
| 30 | += = |
| 31 | += termcolor.js = |
| 32 | += = |
| 33 | +================================== |
| 34 | + |
| 35 | +terminal color output and cursor positioning module. |
| 36 | + |
| 37 | +example usage: |
| 38 | + |
| 39 | +var tc = require("./termcolor"); |
| 40 | + |
| 41 | +PUBLIC FUNCTIONS: |
| 42 | + |
| 43 | +cursorPosition(row,col); |
| 44 | + Overview: |
| 45 | + Positions the terminal cursor at the row and column specified. |
| 46 | + Parameter: |
| 47 | + row - (number) value of the row to which the cursor will move. |
| 48 | + col - (number) value of the column to which the cursor will move. |
| 49 | + |
| 50 | +cursorUp(i); |
| 51 | + Overview: |
| 52 | + Moves the cursor up the specified number of rows |
| 53 | + Parameter: |
| 54 | + i - (number) OPTIONAL - number of rows to move cursor up. If unspecified the value defaults to 1. |
| 55 | + |
| 56 | +cursorDown(i); |
| 57 | + Overview: |
| 58 | + Moves the cursor down the specified number of rows |
| 59 | + Parameter: |
| 60 | + i - (number) OPTIONAL - number of rows to move cursor down. If unspecified the value defaults to 1. |
| 61 | + |
| 62 | +cursorForward(i); |
| 63 | + Overview: |
| 64 | + Moves the cursor forward the specified number of columns |
| 65 | + Parameter: |
| 66 | + i - (number) OPTIONAL - number of columns to move cursor forward. If unspecified the value defaults to 1. |
| 67 | + |
| 68 | +cursorBack(i); |
| 69 | + Overview: |
| 70 | + Moves the cursor back the specified number of columns |
| 71 | + Parameter: |
| 72 | + i - (number) OPTIONAL - number of columns to move cursor back. If unspecified the value defaults to 1. |
| 73 | + |
| 74 | +terminalFontReset(); |
| 75 | + Overview: |
| 76 | + Resets the terminal "font" (color, background, attributes) to the terminal defaults. |
| 77 | + Parameter: |
| 78 | + none; |
| 79 | + |
| 80 | +terminalSetFont(color, bg, attr); |
| 81 | + Overview: |
| 82 | + Sets the terminal "font" (color, background, attributes) to the specified values. |
| 83 | + Parameter: |
| 84 | + color - (number) value of the color to use (use the colors map) |
| 85 | + bg - (number) value of the background to use (use the colors map) |
| 86 | + attr - (number) value of the attribute to use (use the attrs map) |
| 87 | + |
| 88 | +terminalSetFontColor(color); |
| 89 | + Overview: |
| 90 | + Sets the terminal "font" color to the specified value. |
| 91 | + Parameter: |
| 92 | + color - (number) value of the color to use (use the colors map) |
| 93 | + |
| 94 | +terminalSetFontBG(bg); |
| 95 | + Overview: |
| 96 | + Sets the terminal "font" background to the specified value. |
| 97 | + Parameter: |
| 98 | + bg - (number) value of the color to use (use the colors map) |
| 99 | + |
| 100 | +terminalSetFontAttr(attr); |
| 101 | + Overview: |
| 102 | + Sets the terminal "font" attribute to the specified value. |
| 103 | + Parameter: |
| 104 | + attr - (number) value of the color to use (use the attrs map) |
| 105 | + |
| 106 | +resetTerminal; |
| 107 | + Overview: |
| 108 | + Resets the terminal by clearing the screen and reseting the font |
| 109 | + to the terminal default |
| 110 | + Parameter: |
| 111 | + none; |
| 112 | + |
| 113 | +test; |
| 114 | + Overview: |
| 115 | + Run the test method of the termcolor module to see different output |
| 116 | + formats in action. |
| 117 | + Parameter: |
| 118 | + none; |
| 119 | + |
| 120 | + |
| 121 | +PUBLIC VARIABLES: |
| 122 | + |
| 123 | +colors; |
| 124 | + Overview: |
| 125 | + Basically a hashmap of standard terminal color values, used in |
| 126 | + setting parameters for several termcolor functions |
| 127 | + |
| 128 | +attrs; |
| 129 | + Overview: |
| 130 | + Basically a hashmap of standard terminal display attribute values, |
| 131 | + (such as bright, underlined, dim, reverse, ...) used in setting |
| 132 | + parameters for several termcolor functions |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | +================================== |
| 139 | += = |
| 140 | += consolelog.js = |
| 141 | += = |
| 142 | +================================== |
| 143 | + |
| 144 | +terminal console logging module |
| 145 | + |
| 146 | +example usage: |
| 147 | + |
| 148 | +var cl = require("./consolelog"); |
| 149 | + |
| 150 | +PUBLIC FUNCTIONS: |
| 151 | + |
| 152 | +log(msg); |
| 153 | + Overview: |
| 154 | + writes a message to the console screen. |
| 155 | + default output format is to use the terminal default settings. |
| 156 | + Parameters: |
| 157 | + msg - the message to display to the console. |
| 158 | + |
| 159 | +info(msg); |
| 160 | + Overview: |
| 161 | + writes a message to the console screen. |
| 162 | + default output format is GREEN with BRIGHT attribute |
| 163 | + Parameters: |
| 164 | + msg - the message to display to the console. |
| 165 | + |
| 166 | +warn(msg); |
| 167 | + Overview: |
| 168 | + writes a message to the console screen. |
| 169 | + default output format is YELLOW with BRIGHT attribute |
| 170 | + Parameters: |
| 171 | + msg - the message to display to the console. |
| 172 | + |
| 173 | +error(msg); |
| 174 | + Overview: |
| 175 | + writes a message to the console screen. |
| 176 | + default output format is RED with BRIGHT attribute |
| 177 | + Parameters: |
| 178 | + msg - the message to display to the console. |
| 179 | + |
| 180 | +puts(msg); |
| 181 | + Overview: |
| 182 | + an alias of the consolelog.log function for convenience |
| 183 | + |
| 184 | +setLogColor(color); |
| 185 | + Overview: |
| 186 | + Sets the output color for standard log messages |
| 187 | + Parameters: |
| 188 | + color - (number or string) the termcolor.colors map value or the |
| 189 | + upper-cased string name of the color it represents |
| 190 | + |
| 191 | +setInfoColor(color); |
| 192 | + Overview: |
| 193 | + Sets the output color for info log messages |
| 194 | + Parameters: |
| 195 | + color - (number or string) the termcolor.colors map value or the |
| 196 | + upper-cased string name of the color it represents |
| 197 | + |
| 198 | +setWarnColor(color); |
| 199 | + Overview: |
| 200 | + Sets the output color for warning messages |
| 201 | + Parameters: |
| 202 | + color - (number or string) the termcolor.colors map value or the |
| 203 | + upper-cased string name of the color it represents |
| 204 | + |
| 205 | +setErrorColor(color); |
| 206 | + Overview: |
| 207 | + Sets the output color for error messages |
| 208 | + Parameters: |
| 209 | + color - (number or string) the termcolor.colors map value or the |
| 210 | + upper-cased string name of the color it represents |
| 211 | + |
| 212 | +setLogPrefix(prefix); |
| 213 | + Overview: |
| 214 | + Sets the prefix string for standard messages |
| 215 | + Parameters: |
| 216 | + prefix - (string or function) the prefix to print before each message. |
| 217 | + if it is a string, just the string will be printed. |
| 218 | + if it is a function, it should return a string. the function |
| 219 | + will be evaluated for each message and the returned string |
| 220 | + will be printed |
| 221 | + |
| 222 | +setInfoPrefix(prefix); |
| 223 | + Overview: |
| 224 | + Sets the prefix string for info messages |
| 225 | + Parameters: |
| 226 | + prefix - (string or function) the prefix to print before each message. |
| 227 | + if it is a string, just the string will be printed. |
| 228 | + if it is a function, it should return a string. the function |
| 229 | + will be evaluated for each message and the returned string |
| 230 | + will be printed |
| 231 | + |
| 232 | +setWarnPrefix(prefix); |
| 233 | + Overview: |
| 234 | + Sets the prefix string for warning messages |
| 235 | + Parameters: |
| 236 | + prefix - (string or function) the prefix to print before each message. |
| 237 | + if it is a string, just the string will be printed. |
| 238 | + if it is a function, it should return a string. the function |
| 239 | + will be evaluated for each message and the returned string |
| 240 | + will be printed |
| 241 | + |
| 242 | + |
| 243 | +setErrorPrefix(prefix); |
| 244 | + Overview: |
| 245 | + Sets the prefix string for error messages |
| 246 | + Parameters: |
| 247 | + prefix - (string or function) the prefix to print before each message. |
| 248 | + if it is a string, just the string will be printed. |
| 249 | + if it is a function, it should return a string. the function |
| 250 | + will be evaluated for each message and the returned string |
| 251 | + will be printed |
| 252 | + |
| 253 | +setAllPrefix(prefix); |
| 254 | + Overview: |
| 255 | + Sets the prefix string for all messages |
| 256 | + Parameters: |
| 257 | + prefix - (string or function) the prefix to print before each message. |
| 258 | + if it is a string, just the string will be printed. |
| 259 | + if it is a function, it should return a string. the function |
| 260 | + will be evaluated for each message and the returned string |
| 261 | + will be printed |
| 262 | + |
| 263 | +setLogPostfix(prefix); |
| 264 | + Overview: |
| 265 | + Sets the postfix string for standard messages |
| 266 | + Parameters: |
| 267 | + postfix - (string or function) the postfix to print before each message. |
| 268 | + if it is a string, just the string will be printed. |
| 269 | + if it is a function, it should return a string. the function |
| 270 | + will be evaluated for each message and the returned string |
| 271 | + will be printed |
| 272 | + |
| 273 | +setInfoPostfix(postfix); |
| 274 | + Overview: |
| 275 | + Sets the postfix string for info messages |
| 276 | + Parameters: |
| 277 | + postfix - (string or function) the postfix to print before each message. |
| 278 | + if it is a string, just the string will be printed. |
| 279 | + if it is a function, it should return a string. the function |
| 280 | + will be evaluated for each message and the returned string |
| 281 | + will be printed |
| 282 | + |
| 283 | +setWarnPostfix(postfix); |
| 284 | + Overview: |
| 285 | + Sets the postfix string for warning messages |
| 286 | + Parameters: |
| 287 | + postfix - (string or function) the postfix to print before each message. |
| 288 | + if it is a string, just the string will be printed. |
| 289 | + if it is a function, it should return a string. the function |
| 290 | + will be evaluated for each message and the returned string |
| 291 | + will be printed |
| 292 | + |
| 293 | +setErrorPostfix(postfix); |
| 294 | + Overview: |
| 295 | + Sets the postfix string for error messages |
| 296 | + Parameters: |
| 297 | + postfix - (string or function) the postfix to print before each message. |
| 298 | + if it is a string, just the string will be printed. |
| 299 | + if it is a function, it should return a string. the function |
| 300 | + will be evaluated for each message and the returned string |
| 301 | + will be printed |
| 302 | + |
| 303 | +setAllPostfix(postfix); |
| 304 | + Overview: |
| 305 | + Sets the postfix string for all messages |
| 306 | + Parameters: |
| 307 | + postfix - (string or function) the postfix to print before each message. |
| 308 | + if it is a string, just the string will be printed. |
| 309 | + if it is a function, it should return a string. the function |
| 310 | + will be evaluated for each message and the returned string |
| 311 | + will be printed |
| 312 | + |
| 313 | +restoreDefaultColors(); |
| 314 | + Overview: |
| 315 | + restores the default colors for all message types: |
| 316 | + log - terminal default |
| 317 | + info - GREEN and BRIGHT |
| 318 | + warn - YELLOW and BRIGHT |
| 319 | + log - RED and BRIGHT |
| 320 | + |
| 321 | +restoreDefaultPrefixes; |
| 322 | + Overview: |
| 323 | + restores the default prefixes for all message types: |
| 324 | + log - >>> |
| 325 | + info - iii |
| 326 | + warn - *** |
| 327 | + log - !!! |
| 328 | + |
| 329 | +restoreDefaultPostfixes; |
| 330 | + Overview: |
| 331 | + restores the default postfixes for all message types (all empty strings) |
| 332 | + |
| 333 | +restoreDefaultPreAndPostfixes; |
| 334 | + Overview: |
| 335 | + restores the default prefixes and postfixes for all message types |
| 336 | + |
| 337 | +restoreDefaults; |
| 338 | + Overview: |
| 339 | + restores the default colors, prefixes, and postfixes for all message types |
| 340 | + |
| 341 | +test; |
| 342 | + Overview: |
| 343 | + a test function which will display most of the capabilities of the consolelog module. |
| 344 | + |
| 345 | +PUBLIC VARIABLES: |
| 346 | + |
| 347 | +tc; |
| 348 | + Overview: |
| 349 | + an instance of the internal termcolor object |
| 350 | + |
| 351 | +disableDoubleNewlines; |
| 352 | + Overview: |
| 353 | + boolean which determines whether double trailing |
| 354 | + newlines are removed when a message is logged to |
| 355 | + the console. Useful for when your message is coming |
| 356 | + from an outside source (such as a network socket). |
| 357 | + Default value is true. |
| 358 | + |
| 359 | + |
| 360 | +================================== |
| 361 | += = |
| 362 | += CHANGE LOG = |
| 363 | += = |
| 364 | +================================== |
| 365 | + |
| 366 | +v 0.1.0 (December 11, 2009) |
| 367 | + - Initial checkin of termcolor and consolelog modules. |
0 commit comments