市场夺宝奇兵
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.

337 lines
18 KiB

  1. # figures
  2. > Unicode symbols with fallbacks for older terminals
  3. [![](screenshot.png)](index.js)
  4. [*and more...*](index.js)
  5. Terminals such as Windows Console Host (and CMD) only support a [limited character set](http://en.wikipedia.org/wiki/Code_page_437).
  6. ## Install
  7. ```sh
  8. npm install figures
  9. ```
  10. ## Usage
  11. ```js
  12. import figures, {mainSymbols, fallbackSymbols, replaceSymbols} from 'figures';
  13. console.log(figures.tick);
  14. // On terminals with Unicode symbols: ✔
  15. // On other terminals: √
  16. console.log(mainSymbols.tick);
  17. // On all terminals: ✔
  18. console.log(fallbackSymbols.tick);
  19. // On all terminals: √
  20. console.log(replaceSymbols('✔ check'));
  21. // On terminals with Unicode symbols: ✔ check
  22. // On other terminals: √ check
  23. ```
  24. ## API
  25. ### figures (default export)
  26. Type: `object`
  27. Symbols to use on any terminal.
  28. ### mainSymbols
  29. Symbols to use when the terminal supports Unicode symbols.
  30. ### fallbackSymbols
  31. Symbols to use when the terminal does not support Unicode symbols.
  32. ### replaceSymbols(string, options?)
  33. Returns the input with replaced fallback symbols if the terminal has poor Unicode support.
  34. All the below [figures](#figures) are attached to the default export as shown in the example above.
  35. #### string
  36. Type: `string`
  37. String where the Unicode symbols will be replaced with fallback symbols depending on the terminal.
  38. #### options
  39. Type: `object`
  40. ##### useFallback
  41. Type: `boolean`\
  42. Default: `true` if the terminal has poor Unicode support
  43. Whether to replace symbols with fallbacks.
  44. This can be set to `true` to always use fallback symbols, whether the terminal has poor Unicode support or not.
  45. ```js
  46. import {replaceSymbols} from 'figures';
  47. console.log(replaceSymbols('✔ check', {useFallback: true}));
  48. // On terminals with Unicode symbols: √ check
  49. // On other terminals: √ check
  50. ```
  51. ## Figures
  52. `Fallback` characters are only shown when they differ from the `Main` ones.
  53. | Name | Main | Fallback |
  54. | ------------------------------------------- | :--: | :------: |
  55. | tick | `✔` | `√` |
  56. | info | `ℹ` | `i` |
  57. | warning | `⚠` | `‼` |
  58. | cross | `✘` | `×` |
  59. | square | `█` | |
  60. | squareSmall | `◻` | `□` |
  61. | squareSmallFilled | `◼` | `■` |
  62. | squareDarkShade | `▓` | |
  63. | squareMediumShade | `▒` | |
  64. | squareLightShade | `░` | |
  65. | squareTop | `▀` | |
  66. | squareBottom | `▄` | |
  67. | squareLeft | `▌` | |
  68. | squareRight | `▐` | |
  69. | squareCenter | `■` | |
  70. | circle | `◯` | `( )` |
  71. | circleFilled | `◉` | `(*)` |
  72. | circleDotted | `◌` | `( )` |
  73. | circleDouble | `◎` | `( )` |
  74. | circleCircle | `ⓞ` | `(○)` |
  75. | circleCross | `ⓧ` | `(×)` |
  76. | circlePipe | `Ⓘ` | `(│)` |
  77. | circleQuestionMark | `?⃝ ` | `(?)` |
  78. | radioOn | `◉` | `(*)` |
  79. | radioOff | `◯` | `( )` |
  80. | checkboxOn | `☒` | `[×]` |
  81. | checkboxOff | `☐` | `[ ]` |
  82. | checkboxCircleOn | `ⓧ` | `(×)` |
  83. | checkboxCircleOff | `Ⓘ` | `( )` |
  84. | questionMarkPrefix | `?⃝ ` | `?` |
  85. | bullet | `●` | |
  86. | dot | `․` | |
  87. | ellipsis | `…` | |
  88. | pointer | `❯` | `>` |
  89. | pointerSmall | `›` | `›` |
  90. | triangleUp | `▲` | |
  91. | triangleUpSmall | `▴` | |
  92. | triangleUpOutline | `△` | `∆` |
  93. | triangleDown | `▼` | |
  94. | triangleDownSmall | `▾` | |
  95. | triangleLeft | `◀` | `◄` |
  96. | triangleLeftSmall | `◂` | |
  97. | triangleRight | `▶` | `►` |
  98. | triangleRightSmall | `▸` | |
  99. | lozenge | `◆` | `♦` |
  100. | lozengeOutline | `◇` | `◊` |
  101. | home | `⌂` | |
  102. | hamburger | `☰` | `≡` |
  103. | smiley | `㋡` | `☺` |
  104. | mustache | `෴` | `┌─┐` |
  105. | heart | `♥` | |
  106. | star | `★` | `✶` |
  107. | play | `▶` | `►` |
  108. | musicNote | `♪` | |
  109. | musicNoteBeamed | `♫` | |
  110. | nodejs | `⬢` | `♦` |
  111. | arrowUp | `↑` | |
  112. | arrowDown | `↓` | |
  113. | arrowLeft | `←` | |
  114. | arrowRight | `→` | |
  115. | arrowLeftRight | `↔` | |
  116. | arrowUpDown | `↕` | |
  117. | almostEqual | `≈` | |
  118. | notEqual | `≠` | |
  119. | lessOrEqual | `≤` | |
  120. | greaterOrEqual | `≥` | |
  121. | identical | `≡` | |
  122. | infinity | `∞` | |
  123. | subscriptZero | `₀` | |
  124. | subscriptOne | `₁` | |
  125. | subscriptTwo | `₂` | |
  126. | subscriptThree | `₃` | |
  127. | subscriptFour | `₄` | |
  128. | subscriptFive | `₅` | |
  129. | subscriptSix | `₆` | |
  130. | subscriptSeven | `₇` | |
  131. | subscriptEight | `₈` | |
  132. | subscriptNine | `₉` | |
  133. | oneHalf | `½` | |
  134. | oneThird | `⅓` | |
  135. | oneQuarter | `¼` | |
  136. | oneFifth | `⅕` | |
  137. | oneSixth | `⅙` | |
  138. | oneSeventh | `⅐` | `1/7` |
  139. | oneEighth | `⅛` | |
  140. | oneNinth | `⅑` | `1/9` |
  141. | oneTenth | `⅒` | `1/10` |
  142. | twoThirds | `⅔` | |
  143. | twoFifths | `⅖` | |
  144. | threeQuarters | `¾` | |
  145. | threeFifths | `⅗` | |
  146. | threeEighths | `⅜` | |
  147. | fourFifths | `⅘` | |
  148. | fiveSixths | `⅚` | |
  149. | fiveEighths | `⅝` | |
  150. | sevenEighths | `⅞` | |
  151. | line | `─` | |
  152. | lineBold | `━` | |
  153. | lineDouble | `═` | |
  154. | lineDashed0 | `┄` | |
  155. | lineDashed1 | `┅` | |
  156. | lineDashed2 | `┈` | |
  157. | lineDashed3 | `┉` | |
  158. | lineDashed4 | `╌` | |
  159. | lineDashed5 | `╍` | |
  160. | lineDashed6 | `╴` | |
  161. | lineDashed7 | `╶` | |
  162. | lineDashed8 | `╸` | |
  163. | lineDashed9 | `╺` | |
  164. | lineDashed10 | `╼` | |
  165. | lineDashed11 | `╾` | |
  166. | lineDashed12 | `−` | |
  167. | lineDashed13 | `–` | |
  168. | lineDashed14 | `‐` | |
  169. | lineDashed15 | `⁃` | |
  170. | lineVertical | `│` | |
  171. | lineVerticalBold | `┃` | |
  172. | lineVerticalDouble | `║` | |
  173. | lineVerticalDashed0 | `┆` | |
  174. | lineVerticalDashed1 | `┇` | |
  175. | lineVerticalDashed2 | `┊` | |
  176. | lineVerticalDashed3 | `┋` | |
  177. | lineVerticalDashed4 | `╎` | |
  178. | lineVerticalDashed5 | `╏` | |
  179. | lineVerticalDashed6 | `╵` | |
  180. | lineVerticalDashed7 | `╷` | |
  181. | lineVerticalDashed8 | `╹` | |
  182. | lineVerticalDashed9 | `╻` | |
  183. | lineVerticalDashed10 | `╽` | |
  184. | lineVerticalDashed11 | `╿` | |
  185. | lineDownLeft | `┐` | |
  186. | lineDownLeftArc | `╮` | |
  187. | lineDownBoldLeftBold | `┓` | |
  188. | lineDownBoldLeft | `┒` | |
  189. | lineDownLeftBold | `┑` | |
  190. | lineDownDoubleLeftDouble | `╗` | |
  191. | lineDownDoubleLeft | `╖` | |
  192. | lineDownLeftDouble | `╕` | |
  193. | lineDownRight | `┌` | |
  194. | lineDownRightArc | `╭` | |
  195. | lineDownBoldRightBold | `┏` | |
  196. | lineDownBoldRight | `┎` | |
  197. | lineDownRightBold | `┍` | |
  198. | lineDownDoubleRightDouble | `╔` | |
  199. | lineDownDoubleRight | `╓` | |
  200. | lineDownRightDouble | `╒` | |
  201. | lineUpLeft | `┘` | |
  202. | lineUpLeftArc | `╯` | |
  203. | lineUpBoldLeftBold | `┛` | |
  204. | lineUpBoldLeft | `┚` | |
  205. | lineUpLeftBold | `┙` | |
  206. | lineUpDoubleLeftDouble | `╝` | |
  207. | lineUpDoubleLeft | `╜` | |
  208. | lineUpLeftDouble | `╛` | |
  209. | lineUpRight | `└` | |
  210. | lineUpRightArc | `╰` | |
  211. | lineUpBoldRightBold | `┗` | |
  212. | lineUpBoldRight | `┖` | |
  213. | lineUpRightBold | `┕` | |
  214. | lineUpDoubleRightDouble | `╚` | |
  215. | lineUpDoubleRight | `╙` | |
  216. | lineUpRightDouble | `╘` | |
  217. | lineUpDownLeft | `┤` | |
  218. | lineUpBoldDownBoldLeftBold | `┫` | |
  219. | lineUpBoldDownBoldLeft | `┨` | |
  220. | lineUpDownLeftBold | `┥` | |
  221. | lineUpBoldDownLeftBold | `┩` | |
  222. | lineUpDownBoldLeftBold | `┪` | |
  223. | lineUpDownBoldLeft | `┧` | |
  224. | lineUpBoldDownLeft | `┦` | |
  225. | lineUpDoubleDownDoubleLeftDouble | `╣` | |
  226. | lineUpDoubleDownDoubleLeft | `╢` | |
  227. | lineUpDownLeftDouble | `╡` | |
  228. | lineUpDownRight | `├` | |
  229. | lineUpBoldDownBoldRightBold | `┣` | |
  230. | lineUpBoldDownBoldRight | `┠` | |
  231. | lineUpDownRightBold | `┝` | |
  232. | lineUpBoldDownRightBold | `┡` | |
  233. | lineUpDownBoldRightBold | `┢` | |
  234. | lineUpDownBoldRight | `┟` | |
  235. | lineUpBoldDownRight | `┞` | |
  236. | lineUpDoubleDownDoubleRightDouble | `╠` | |
  237. | lineUpDoubleDownDoubleRight | `╟` | |
  238. | lineUpDownRightDouble | `╞` | |
  239. | lineDownLeftRight | `┬` | |
  240. | lineDownBoldLeftBoldRightBold | `┳` | |
  241. | lineDownLeftBoldRightBold | `┯` | |
  242. | lineDownBoldLeftRight | `┰` | |
  243. | lineDownBoldLeftBoldRight | `┱` | |
  244. | lineDownBoldLeftRightBold | `┲` | |
  245. | lineDownLeftRightBold | `┮` | |
  246. | lineDownLeftBoldRight | `┭` | |
  247. | lineDownDoubleLeftDoubleRightDouble | `╦` | |
  248. | lineDownDoubleLeftRight | `╥` | |
  249. | lineDownLeftDoubleRightDouble | `╤` | |
  250. | lineUpLeftRight | `┴` | |
  251. | lineUpBoldLeftBoldRightBold | `┻` | |
  252. | lineUpLeftBoldRightBold | `┷` | |
  253. | lineUpBoldLeftRight | `┸` | |
  254. | lineUpBoldLeftBoldRight | `┹` | |
  255. | lineUpBoldLeftRightBold | `┺` | |
  256. | lineUpLeftRightBold | `┶` | |
  257. | lineUpLeftBoldRight | `┵` | |
  258. | lineUpDoubleLeftDoubleRightDouble | `╩` | |
  259. | lineUpDoubleLeftRight | `╨` | |
  260. | lineUpLeftDoubleRightDouble | `╧` | |
  261. | lineUpDownLeftRight | `┼` | |
  262. | lineUpBoldDownBoldLeftBoldRightBold | `╋` | |
  263. | lineUpDownBoldLeftBoldRightBold | `╈` | |
  264. | lineUpBoldDownLeftBoldRightBold | `╇` | |
  265. | lineUpBoldDownBoldLeftRightBold | `╊` | |
  266. | lineUpBoldDownBoldLeftBoldRight | `╉` | |
  267. | lineUpBoldDownLeftRight | `╀` | |
  268. | lineUpDownBoldLeftRight | `╁` | |
  269. | lineUpDownLeftBoldRight | `┽` | |
  270. | lineUpDownLeftRightBold | `┾` | |
  271. | lineUpBoldDownBoldLeftRight | `╂` | |
  272. | lineUpDownLeftBoldRightBold | `┿` | |
  273. | lineUpBoldDownLeftBoldRight | `╃` | |
  274. | lineUpBoldDownLeftRightBold | `╄` | |
  275. | lineUpDownBoldLeftBoldRight | `╅` | |
  276. | lineUpDownBoldLeftRightBold | `╆` | |
  277. | lineUpDoubleDownDoubleLeftDoubleRightDouble | `╬` | |
  278. | lineUpDoubleDownDoubleLeftRight | `╫` | |
  279. | lineUpDownLeftDoubleRightDouble | `╪` | |
  280. | lineCross | `╳` | |
  281. | lineBackslash | `╲` | |
  282. | lineSlash | `╱` | |
  283. ## Other characters
  284. If you cannot find the character you're looking for in the table above, please look at this full list of [cross-platform terminal characters](https://github.com/ehmicky/cross-platform-terminal-characters).
  285. ## Unsupported terminals
  286. The following terminals are not officially supported:
  287. - xterm
  288. - Linux Terminal (kernel)
  289. - cmder
  290. They can display most but not all of the symbols listed above.
  291. ## Related
  292. - [log-symbols](https://github.com/sindresorhus/log-symbols) - Colored symbols for various log levels