index.d.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import {LiteralUnion} from 'type-fest';
  2. import {BoxStyle, Boxes} from 'cli-boxes';
  3. declare namespace boxen {
  4. /**
  5. Characters used for custom border.
  6. @example
  7. ```
  8. // affffb
  9. // e e
  10. // dffffc
  11. const border: CustomBorderStyle = {
  12. topLeft: 'a',
  13. topRight: 'b',
  14. bottomRight: 'c',
  15. bottomLeft: 'd',
  16. vertical: 'e',
  17. horizontal: 'f'
  18. };
  19. ```
  20. */
  21. interface CustomBorderStyle extends BoxStyle {}
  22. /**
  23. Spacing used for `padding` and `margin`.
  24. */
  25. interface Spacing {
  26. readonly top: number;
  27. readonly right: number;
  28. readonly bottom: number;
  29. readonly left: number;
  30. }
  31. interface Options {
  32. /**
  33. Color of the box border.
  34. */
  35. readonly borderColor?: LiteralUnion<
  36. | 'black'
  37. | 'red'
  38. | 'green'
  39. | 'yellow'
  40. | 'blue'
  41. | 'magenta'
  42. | 'cyan'
  43. | 'white'
  44. | 'gray'
  45. | 'grey'
  46. | 'blackBright'
  47. | 'redBright'
  48. | 'greenBright'
  49. | 'yellowBright'
  50. | 'blueBright'
  51. | 'magentaBright'
  52. | 'cyanBright'
  53. | 'whiteBright',
  54. string
  55. >;
  56. /**
  57. Style of the box border.
  58. @default 'single'
  59. */
  60. readonly borderStyle?: keyof Boxes | CustomBorderStyle;
  61. /**
  62. Reduce opacity of the border.
  63. @default false
  64. */
  65. readonly dimBorder?: boolean;
  66. /**
  67. Space between the text and box border.
  68. @default 0
  69. */
  70. readonly padding?: number | Spacing;
  71. /**
  72. Space around the box.
  73. @default 0
  74. */
  75. readonly margin?: number | Spacing;
  76. /**
  77. Float the box on the available terminal screen space.
  78. @default 'left'
  79. */
  80. readonly float?: 'left' | 'right' | 'center';
  81. /**
  82. Color of the background.
  83. */
  84. readonly backgroundColor?: LiteralUnion<
  85. | 'black'
  86. | 'red'
  87. | 'green'
  88. | 'yellow'
  89. | 'blue'
  90. | 'magenta'
  91. | 'cyan'
  92. | 'white'
  93. | 'blackBright'
  94. | 'redBright'
  95. | 'greenBright'
  96. | 'yellowBright'
  97. | 'blueBright'
  98. | 'magentaBright'
  99. | 'cyanBright'
  100. | 'whiteBright',
  101. string
  102. >;
  103. /**
  104. Align the text in the box based on the widest line.
  105. @default 'left'
  106. @deprecated Use `textAlignment` instead.
  107. */
  108. readonly align?: 'left' | 'right' | 'center';
  109. /**
  110. Align the text in the box based on the widest line.
  111. @default 'left'
  112. */
  113. readonly textAlignment?: 'left' | 'right' | 'center';
  114. /**
  115. Display a title at the top of the box.
  116. If needed, the box will horizontally expand to fit the title.
  117. @example
  118. ```
  119. console.log(boxen('foo bar', {title: 'example'}));
  120. // ┌ example ┐
  121. // │foo bar │
  122. // └─────────┘
  123. ```
  124. */
  125. readonly title?: string;
  126. /**
  127. Align the title in the top bar.
  128. @default 'left'
  129. @example
  130. ```
  131. console.log(boxen('foo bar foo bar', {title: 'example', titleAlignment: 'center'}));
  132. // ┌─── example ───┐
  133. // │foo bar foo bar│
  134. // └───────────────┘
  135. console.log(boxen('foo bar foo bar', {title: 'example', titleAlignment: 'right'}));
  136. // ┌────── example ┐
  137. // │foo bar foo bar│
  138. // └───────────────┘
  139. ```
  140. */
  141. readonly titleAlignment?: 'left' | 'right' | 'center';
  142. }
  143. }
  144. /**
  145. Creates a box in the terminal.
  146. @param text - The text inside the box.
  147. @returns The box.
  148. @example
  149. ```
  150. import boxen = require('boxen');
  151. console.log(boxen('unicorn', {padding: 1}));
  152. // ┌─────────────┐
  153. // │ │
  154. // │ unicorn │
  155. // │ │
  156. // └─────────────┘
  157. console.log(boxen('unicorn', {padding: 1, margin: 1, borderStyle: 'double'}));
  158. //
  159. // ╔═════════════╗
  160. // ║ ║
  161. // ║ unicorn ║
  162. // ║ ║
  163. // ╚═════════════╝
  164. //
  165. ```
  166. */
  167. declare const boxen: (text: string, options?: boxen.Options) => string;
  168. export = boxen;