index.d.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import {LiteralUnion} from 'type-fest';
  2. import cliBoxes, {BoxStyle} 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 BorderStyle.Single
  59. */
  60. readonly borderStyle?: BorderStyle | 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. */
  107. readonly align?: 'left' | 'right' | 'center';
  108. }
  109. }
  110. declare const enum BorderStyle {
  111. Single = 'single',
  112. Double = 'double',
  113. Round = 'round',
  114. Bold = 'bold',
  115. SingleDouble = 'singleDouble',
  116. DoubleSingle = 'doubleSingle',
  117. Classic = 'classic'
  118. }
  119. declare const boxen: {
  120. /**
  121. Creates a box in the terminal.
  122. @param text - The text inside the box.
  123. @returns The box.
  124. @example
  125. ```
  126. import boxen = require('boxen');
  127. console.log(boxen('unicorn', {padding: 1}));
  128. // ┌─────────────┐
  129. // │ │
  130. // │ unicorn │
  131. // │ │
  132. // └─────────────┘
  133. console.log(boxen('unicorn', {padding: 1, margin: 1, borderStyle: 'double'}));
  134. //
  135. // ╔═════════════╗
  136. // ║ ║
  137. // ║ unicorn ║
  138. // ║ ║
  139. // ╚═════════════╝
  140. //
  141. ```
  142. */
  143. (text: string, options?: boxen.Options): string;
  144. /**
  145. Border styles from [`cli-boxes`](https://github.com/sindresorhus/cli-boxes).
  146. */
  147. BorderStyle: typeof BorderStyle;
  148. };
  149. export = boxen;