You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 3.7KB

4 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. # boxen [![Build Status](https://travis-ci.org/sindresorhus/boxen.svg?branch=master)](https://travis-ci.org/sindresorhus/boxen)
  2. > Create boxes in the terminal
  3. ![](screenshot.png)
  4. ## Install
  5. ```
  6. $ npm install boxen
  7. ```
  8. ## Usage
  9. ```js
  10. const boxen = require('boxen');
  11. console.log(boxen('unicorn', {padding: 1}));
  12. /*
  13. ┌─────────────┐
  14. │ │
  15. │ unicorn │
  16. │ │
  17. └─────────────┘
  18. */
  19. console.log(boxen('unicorn', {padding: 1, margin: 1, borderStyle: 'double'}));
  20. /*
  21. ╔═════════════╗
  22. ║ ║
  23. ║ unicorn ║
  24. ║ ║
  25. ╚═════════════╝
  26. */
  27. ```
  28. ## API
  29. ### boxen(text, options?)
  30. #### text
  31. Type: `string`
  32. Text inside the box.
  33. #### options
  34. Type: `object`
  35. ##### borderColor
  36. Type: `string`\
  37. Values: `'black'` `'red'` `'green'` `'yellow'` `'blue'` `'magenta'` `'cyan'` `'white'` `'gray'` or a hex value like `'#ff0000'`
  38. Color of the box border.
  39. ##### borderStyle
  40. Type: `string | object`\
  41. Default: `'single'`\
  42. Values:
  43. - `'single'`
  44. ```
  45. ┌───┐
  46. │foo│
  47. └───┘
  48. ```
  49. - `'double'`
  50. ```
  51. ╔═══╗
  52. ║foo║
  53. ╚═══╝
  54. ```
  55. - `'round'` (`'single'` sides with round corners)
  56. ```
  57. ╭───╮
  58. │foo│
  59. ╰───╯
  60. ```
  61. - `'bold'`
  62. ```
  63. ┏━━━┓
  64. ┃foo┃
  65. ┗━━━┛
  66. ```
  67. - `'singleDouble'` (`'single'` on top and bottom, `'double'` on right and left)
  68. ```
  69. ╓───╖
  70. ║foo║
  71. ╙───╜
  72. ```
  73. - `'doubleSingle'` (`'double'` on top and bottom, `'single'` on right and left)
  74. ```
  75. ╒═══╕
  76. │foo│
  77. ╘═══╛
  78. ```
  79. - `'classic'`
  80. ```
  81. +---+
  82. |foo|
  83. +---+
  84. ```
  85. Style of the box border.
  86. Can be any of the above predefined styles or an object with the following keys:
  87. ```js
  88. {
  89. topLeft: '+',
  90. topRight: '+',
  91. bottomLeft: '+',
  92. bottomRight: '+',
  93. horizontal: '-',
  94. vertical: '|'
  95. }
  96. ```
  97. ##### dimBorder
  98. Type: `boolean`\
  99. Default: `false`
  100. Reduce opacity of the border.
  101. ##### padding
  102. Type: `number | object`\
  103. Default: `0`
  104. Space between the text and box border.
  105. Accepts a number or an object with any of the `top`, `right`, `bottom`, `left` properties. When a number is specified, the left/right padding is 3 times the top/bottom to make it look nice.
  106. ##### margin
  107. Type: `number | object`\
  108. Default: `0`
  109. Space around the box.
  110. Accepts a number or an object with any of the `top`, `right`, `bottom`, `left` properties. When a number is specified, the left/right margin is 3 times the top/bottom to make it look nice.
  111. ##### float
  112. Type: `string`\
  113. Default: `'left'`\
  114. Values: `'right'` `'center'` `'left'`
  115. Float the box on the available terminal screen space.
  116. ##### backgroundColor
  117. Type: `string`\
  118. Values: `'black'` `'red'` `'green'` `'yellow'` `'blue'` `'magenta'` `'cyan'` `'white'` `'gray'` or a hex value like `'#ff0000'`
  119. Color of the background.
  120. ##### align
  121. Type: `string`\
  122. Default: `'left'`\
  123. Values: `'left'` `'center'` `'right'`
  124. Align the text in the box based on the widest line.
  125. ## Related
  126. - [boxen-cli](https://github.com/sindresorhus/boxen-cli) - CLI for this module
  127. - [cli-boxes](https://github.com/sindresorhus/cli-boxes) - Boxes for use in the terminal
  128. - [ink-box](https://github.com/sindresorhus/ink-box) - Box component for Ink that uses this package
  129. ---
  130. <div align="center">
  131. <b>
  132. <a href="https://tidelift.com/subscription/pkg/npm-boxen?utm_source=npm-boxen&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
  133. </b>
  134. <br>
  135. <sub>
  136. Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
  137. </sub>
  138. </div>