README.md~ 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # Console Control Strings
  2. A library of cross-platform tested terminal/console command strings for
  3. doing things like color and cursor positioning. This is a subset of both
  4. ansi and vt100. All control codes included work on both Windows & Unix-like
  5. OSes, except where noted.
  6. ## Usage
  7. ```js
  8. var consoleControl = require('console-control-strings')
  9. console.log(consoleControl.color('blue','bgRed', 'bold') + 'hi there' + consoleControl.color('reset'))
  10. process.stdout.write(consoleControl.goto(75, 10))
  11. ```
  12. ## Why Another?
  13. There are tons of libraries similar to this one. I wanted one that was:
  14. 1. Very clear about compatibility goals.
  15. 2. Could emit, for instance, a start color code without an end one.
  16. 3. Returned strings w/o writing to streams.
  17. 4. Was not weighed down with other unrelated baggage.
  18. ## Functions
  19. ### var code = consoleControl.up(_num = 1_)
  20. Returns the escape sequence to move _num_ lines up.
  21. ### var code = consoleControl.down(_num = 1_)
  22. Returns the escape sequence to move _num_ lines down.
  23. ### var code = consoleControl.forward(_num = 1_)
  24. Returns the escape sequence to move _num_ lines righ.
  25. ### var code = consoleControl.back(_num = 1_)
  26. Returns the escape sequence to move _num_ lines left.
  27. ### var code = consoleControl.nextLine(_num = 1_)
  28. Returns the escape sequence to move _num_ lines down and to the beginning of
  29. the line.
  30. ### var code = consoleControl.previousLine(_num = 1_)
  31. Returns the escape sequence to move _num_ lines up and to the beginning of
  32. the line.
  33. ### var code = consoleControl.eraseData()
  34. Returns the escape sequence to erase everything from the current cursor
  35. position to the bottom right of the screen. This is line based, so it
  36. erases the remainder of the current line and all following lines.
  37. ### var code = consoleControl.eraseLine()
  38. Returns the escape sequence to erase to the end of the current line.
  39. ### var code = consoleControl.goto(_x_, _y_)
  40. Returns the escape sequence to move the cursor to the designated position.
  41. Note that the origin is _1, 1_ not _0, 0_.
  42. ### var code = consoleControl.gotoSOL()
  43. Returns the escape sequence to move the cursor to the beginning of the
  44. current line. (That is, it returns a carriage return, `\r`.)
  45. ### var code = consoleControl.hideCursor()
  46. Returns the escape sequence to hide the cursor.
  47. ### var code = consoleControl.showCursor()
  48. Returns the escape sequence to show the cursor.
  49. ### var code = consoleControl.color(_colors = []_)
  50. ### var code = consoleControl.color(_color1_, _color2_, _…_, _colorn_)
  51. Returns the escape sequence to set the current terminal display attributes
  52. (mostly colors). Arguments can either be a list of attributes or an array
  53. of attributes. The difference between passing in an array or list of colors
  54. and calling `.color` separately for each one, is that in the former case a
  55. single escape sequence will be produced where as in the latter each change
  56. will have its own distinct escape sequence. Each attribute can be one of:
  57. * Reset:
  58. * **reset** – Reset all attributes to the terminal default.
  59. * Styles:
  60. * **bold** – Display text as bold. In some terminals this means using a
  61. bold font, in others this means changing the color. In some it means
  62. both.
  63. * **italic** – Display text as italic. This is not available in most Windows terminals.
  64. * **underline** – Underline text. This is not available in most Windows Terminals.
  65. * **inverse** – Invert the foreground and background colors.
  66. * **stopBold** – Do not display text as bold.
  67. * **stopItalic** – Do not display text as italic.
  68. * **stopUnderline** – Do not underline text.
  69. * **stopInverse** – Do not invert foreground and background.
  70. * Colors:
  71. * **white**
  72. * **black**
  73. * **blue**
  74. * **cyan**
  75. * **green**
  76. * **magenta**
  77. * **red**
  78. * **yellow**
  79. * **grey** / **brightBlack**
  80. * **brightRed**
  81. * **brightGreen**
  82. * **brightYellow**
  83. * **brightBlue**
  84. * **brightMagenta**
  85. * **brightCyan**
  86. * **brightWhite**
  87. * Background Colors:
  88. * **bgWhite**
  89. * **bgBlack**
  90. * **bgBlue**
  91. * **bgCyan**
  92. * **bgGreen**
  93. * **bgMagenta**
  94. * **bgRed**
  95. * **bgYellow**
  96. * **bgGrey** / **bgBrightBlack**
  97. * **bgBrightRed**
  98. * **bgBrightGreen**
  99. * **bgBrightYellow**
  100. * **bgBrightBlue**
  101. * **bgBrightMagenta**
  102. * **bgBrightCyan**
  103. * **bgBrightWhite**