index.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.replaceSymbols = exports.fallbackSymbols = exports.mainSymbols = void 0;
  7. // process.env dot-notation access prints:
  8. // Property 'TERM' comes from an index signature, so it must be accessed with ['TERM'].ts(4111)
  9. /* eslint dot-notation: ["off"] */
  10. const node_process_1 = __importDefault(require("node:process"));
  11. // Ported from is-unicode-supported
  12. function isUnicodeSupported() {
  13. if (node_process_1.default.platform !== 'win32') {
  14. return node_process_1.default.env['TERM'] !== 'linux'; // Linux console (kernel)
  15. }
  16. return (Boolean(node_process_1.default.env['WT_SESSION']) || // Windows Terminal
  17. Boolean(node_process_1.default.env['TERMINUS_SUBLIME']) || // Terminus (<0.2.27)
  18. node_process_1.default.env['ConEmuTask'] === '{cmd::Cmder}' || // ConEmu and cmder
  19. node_process_1.default.env['TERM_PROGRAM'] === 'Terminus-Sublime' ||
  20. node_process_1.default.env['TERM_PROGRAM'] === 'vscode' ||
  21. node_process_1.default.env['TERM'] === 'xterm-256color' ||
  22. node_process_1.default.env['TERM'] === 'alacritty' ||
  23. node_process_1.default.env['TERMINAL_EMULATOR'] === 'JetBrains-JediTerm');
  24. }
  25. // Ported from figures
  26. const common = {
  27. circleQuestionMark: '(?)',
  28. questionMarkPrefix: '(?)',
  29. square: '█',
  30. squareDarkShade: '▓',
  31. squareMediumShade: '▒',
  32. squareLightShade: '░',
  33. squareTop: '▀',
  34. squareBottom: '▄',
  35. squareLeft: '▌',
  36. squareRight: '▐',
  37. squareCenter: '■',
  38. bullet: '●',
  39. dot: '․',
  40. ellipsis: '…',
  41. pointerSmall: '›',
  42. triangleUp: '▲',
  43. triangleUpSmall: '▴',
  44. triangleDown: '▼',
  45. triangleDownSmall: '▾',
  46. triangleLeftSmall: '◂',
  47. triangleRightSmall: '▸',
  48. home: '⌂',
  49. heart: '♥',
  50. musicNote: '♪',
  51. musicNoteBeamed: '♫',
  52. arrowUp: '↑',
  53. arrowDown: '↓',
  54. arrowLeft: '←',
  55. arrowRight: '→',
  56. arrowLeftRight: '↔',
  57. arrowUpDown: '↕',
  58. almostEqual: '≈',
  59. notEqual: '≠',
  60. lessOrEqual: '≤',
  61. greaterOrEqual: '≥',
  62. identical: '≡',
  63. infinity: '∞',
  64. subscriptZero: '₀',
  65. subscriptOne: '₁',
  66. subscriptTwo: '₂',
  67. subscriptThree: '₃',
  68. subscriptFour: '₄',
  69. subscriptFive: '₅',
  70. subscriptSix: '₆',
  71. subscriptSeven: '₇',
  72. subscriptEight: '₈',
  73. subscriptNine: '₉',
  74. oneHalf: '½',
  75. oneThird: '⅓',
  76. oneQuarter: '¼',
  77. oneFifth: '⅕',
  78. oneSixth: '⅙',
  79. oneEighth: '⅛',
  80. twoThirds: '⅔',
  81. twoFifths: '⅖',
  82. threeQuarters: '¾',
  83. threeFifths: '⅗',
  84. threeEighths: '⅜',
  85. fourFifths: '⅘',
  86. fiveSixths: '⅚',
  87. fiveEighths: '⅝',
  88. sevenEighths: '⅞',
  89. line: '─',
  90. lineBold: '━',
  91. lineDouble: '═',
  92. lineDashed0: '┄',
  93. lineDashed1: '┅',
  94. lineDashed2: '┈',
  95. lineDashed3: '┉',
  96. lineDashed4: '╌',
  97. lineDashed5: '╍',
  98. lineDashed6: '╴',
  99. lineDashed7: '╶',
  100. lineDashed8: '╸',
  101. lineDashed9: '╺',
  102. lineDashed10: '╼',
  103. lineDashed11: '╾',
  104. lineDashed12: '−',
  105. lineDashed13: '–',
  106. lineDashed14: '‐',
  107. lineDashed15: '⁃',
  108. lineVertical: '│',
  109. lineVerticalBold: '┃',
  110. lineVerticalDouble: '║',
  111. lineVerticalDashed0: '┆',
  112. lineVerticalDashed1: '┇',
  113. lineVerticalDashed2: '┊',
  114. lineVerticalDashed3: '┋',
  115. lineVerticalDashed4: '╎',
  116. lineVerticalDashed5: '╏',
  117. lineVerticalDashed6: '╵',
  118. lineVerticalDashed7: '╷',
  119. lineVerticalDashed8: '╹',
  120. lineVerticalDashed9: '╻',
  121. lineVerticalDashed10: '╽',
  122. lineVerticalDashed11: '╿',
  123. lineDownLeft: '┐',
  124. lineDownLeftArc: '╮',
  125. lineDownBoldLeftBold: '┓',
  126. lineDownBoldLeft: '┒',
  127. lineDownLeftBold: '┑',
  128. lineDownDoubleLeftDouble: '╗',
  129. lineDownDoubleLeft: '╖',
  130. lineDownLeftDouble: '╕',
  131. lineDownRight: '┌',
  132. lineDownRightArc: '╭',
  133. lineDownBoldRightBold: '┏',
  134. lineDownBoldRight: '┎',
  135. lineDownRightBold: '┍',
  136. lineDownDoubleRightDouble: '╔',
  137. lineDownDoubleRight: '╓',
  138. lineDownRightDouble: '╒',
  139. lineUpLeft: '┘',
  140. lineUpLeftArc: '╯',
  141. lineUpBoldLeftBold: '┛',
  142. lineUpBoldLeft: '┚',
  143. lineUpLeftBold: '┙',
  144. lineUpDoubleLeftDouble: '╝',
  145. lineUpDoubleLeft: '╜',
  146. lineUpLeftDouble: '╛',
  147. lineUpRight: '└',
  148. lineUpRightArc: '╰',
  149. lineUpBoldRightBold: '┗',
  150. lineUpBoldRight: '┖',
  151. lineUpRightBold: '┕',
  152. lineUpDoubleRightDouble: '╚',
  153. lineUpDoubleRight: '╙',
  154. lineUpRightDouble: '╘',
  155. lineUpDownLeft: '┤',
  156. lineUpBoldDownBoldLeftBold: '┫',
  157. lineUpBoldDownBoldLeft: '┨',
  158. lineUpDownLeftBold: '┥',
  159. lineUpBoldDownLeftBold: '┩',
  160. lineUpDownBoldLeftBold: '┪',
  161. lineUpDownBoldLeft: '┧',
  162. lineUpBoldDownLeft: '┦',
  163. lineUpDoubleDownDoubleLeftDouble: '╣',
  164. lineUpDoubleDownDoubleLeft: '╢',
  165. lineUpDownLeftDouble: '╡',
  166. lineUpDownRight: '├',
  167. lineUpBoldDownBoldRightBold: '┣',
  168. lineUpBoldDownBoldRight: '┠',
  169. lineUpDownRightBold: '┝',
  170. lineUpBoldDownRightBold: '┡',
  171. lineUpDownBoldRightBold: '┢',
  172. lineUpDownBoldRight: '┟',
  173. lineUpBoldDownRight: '┞',
  174. lineUpDoubleDownDoubleRightDouble: '╠',
  175. lineUpDoubleDownDoubleRight: '╟',
  176. lineUpDownRightDouble: '╞',
  177. lineDownLeftRight: '┬',
  178. lineDownBoldLeftBoldRightBold: '┳',
  179. lineDownLeftBoldRightBold: '┯',
  180. lineDownBoldLeftRight: '┰',
  181. lineDownBoldLeftBoldRight: '┱',
  182. lineDownBoldLeftRightBold: '┲',
  183. lineDownLeftRightBold: '┮',
  184. lineDownLeftBoldRight: '┭',
  185. lineDownDoubleLeftDoubleRightDouble: '╦',
  186. lineDownDoubleLeftRight: '╥',
  187. lineDownLeftDoubleRightDouble: '╤',
  188. lineUpLeftRight: '┴',
  189. lineUpBoldLeftBoldRightBold: '┻',
  190. lineUpLeftBoldRightBold: '┷',
  191. lineUpBoldLeftRight: '┸',
  192. lineUpBoldLeftBoldRight: '┹',
  193. lineUpBoldLeftRightBold: '┺',
  194. lineUpLeftRightBold: '┶',
  195. lineUpLeftBoldRight: '┵',
  196. lineUpDoubleLeftDoubleRightDouble: '╩',
  197. lineUpDoubleLeftRight: '╨',
  198. lineUpLeftDoubleRightDouble: '╧',
  199. lineUpDownLeftRight: '┼',
  200. lineUpBoldDownBoldLeftBoldRightBold: '╋',
  201. lineUpDownBoldLeftBoldRightBold: '╈',
  202. lineUpBoldDownLeftBoldRightBold: '╇',
  203. lineUpBoldDownBoldLeftRightBold: '╊',
  204. lineUpBoldDownBoldLeftBoldRight: '╉',
  205. lineUpBoldDownLeftRight: '╀',
  206. lineUpDownBoldLeftRight: '╁',
  207. lineUpDownLeftBoldRight: '┽',
  208. lineUpDownLeftRightBold: '┾',
  209. lineUpBoldDownBoldLeftRight: '╂',
  210. lineUpDownLeftBoldRightBold: '┿',
  211. lineUpBoldDownLeftBoldRight: '╃',
  212. lineUpBoldDownLeftRightBold: '╄',
  213. lineUpDownBoldLeftBoldRight: '╅',
  214. lineUpDownBoldLeftRightBold: '╆',
  215. lineUpDoubleDownDoubleLeftDoubleRightDouble: '╬',
  216. lineUpDoubleDownDoubleLeftRight: '╫',
  217. lineUpDownLeftDoubleRightDouble: '╪',
  218. lineCross: '╳',
  219. lineBackslash: '╲',
  220. lineSlash: '╱',
  221. };
  222. const specialMainSymbols = {
  223. tick: '✔',
  224. info: 'ℹ',
  225. warning: '⚠',
  226. cross: '✘',
  227. squareSmall: '◻',
  228. squareSmallFilled: '◼',
  229. circle: '◯',
  230. circleFilled: '◉',
  231. circleDotted: '◌',
  232. circleDouble: '◎',
  233. circleCircle: 'ⓞ',
  234. circleCross: 'ⓧ',
  235. circlePipe: 'Ⓘ',
  236. radioOn: '◉',
  237. radioOff: '◯',
  238. checkboxOn: '☒',
  239. checkboxOff: '☐',
  240. checkboxCircleOn: 'ⓧ',
  241. checkboxCircleOff: 'Ⓘ',
  242. pointer: '❯',
  243. triangleUpOutline: '△',
  244. triangleLeft: '◀',
  245. triangleRight: '▶',
  246. lozenge: '◆',
  247. lozengeOutline: '◇',
  248. hamburger: '☰',
  249. smiley: '㋡',
  250. mustache: '෴',
  251. star: '★',
  252. play: '▶',
  253. nodejs: '⬢',
  254. oneSeventh: '⅐',
  255. oneNinth: '⅑',
  256. oneTenth: '⅒',
  257. };
  258. const specialFallbackSymbols = {
  259. tick: '√',
  260. info: 'i',
  261. warning: '‼',
  262. cross: '×',
  263. squareSmall: '□',
  264. squareSmallFilled: '■',
  265. circle: '( )',
  266. circleFilled: '(*)',
  267. circleDotted: '( )',
  268. circleDouble: '( )',
  269. circleCircle: '(○)',
  270. circleCross: '(×)',
  271. circlePipe: '(│)',
  272. radioOn: '(*)',
  273. radioOff: '( )',
  274. checkboxOn: '[×]',
  275. checkboxOff: '[ ]',
  276. checkboxCircleOn: '(×)',
  277. checkboxCircleOff: '( )',
  278. pointer: '>',
  279. triangleUpOutline: '∆',
  280. triangleLeft: '◄',
  281. triangleRight: '►',
  282. lozenge: '♦',
  283. lozengeOutline: '◊',
  284. hamburger: '≡',
  285. smiley: '☺',
  286. mustache: '┌─┐',
  287. star: '✶',
  288. play: '►',
  289. nodejs: '♦',
  290. oneSeventh: '1/7',
  291. oneNinth: '1/9',
  292. oneTenth: '1/10',
  293. };
  294. exports.mainSymbols = { ...common, ...specialMainSymbols };
  295. exports.fallbackSymbols = {
  296. ...common,
  297. ...specialFallbackSymbols,
  298. };
  299. const shouldUseMain = isUnicodeSupported();
  300. const figures = shouldUseMain ? exports.mainSymbols : exports.fallbackSymbols;
  301. exports.default = figures;
  302. const replacements = Object.entries(specialMainSymbols);
  303. // On terminals which do not support Unicode symbols, substitute them to other symbols
  304. const replaceSymbols = (string, { useFallback = !shouldUseMain } = {}) => {
  305. if (useFallback) {
  306. for (const [key, mainSymbol] of replacements) {
  307. const fallbackSymbol = exports.fallbackSymbols[key];
  308. if (!fallbackSymbol) {
  309. throw new Error(`Unable to find fallback for ${key}`);
  310. }
  311. string = string.replaceAll(mainSymbol, fallbackSymbol);
  312. }
  313. }
  314. return string;
  315. };
  316. exports.replaceSymbols = replaceSymbols;