Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. ##tfunk [![Build Status](https://travis-ci.org/shakyShane/tfunk.svg)](https://travis-ci.org/shakyShane/tfunk)
  2. Multi-colour console output from [Chalk](https://github.com/sindresorhus/chalk#styles) with added awesome.
  3. by [@shakyshane](https://github.com/shakyShane) & [@AydinHassan](https://github.com/AydinHassan)
  4. ![tfunk](http://f.cl.ly/items/15102k441h1U1Z1l253J/Screen%20Shot%202014-09-10%20at%2022.05.15.png)
  5. ##Install
  6. ```bash
  7. npm install tfunk
  8. ```
  9. ##Usage
  10. **Syntax rules:**
  11. `{` `<color>` `:` `YOUR STRING` `}`
  12. **Example**
  13. `{blue:This is a blue line}`
  14. **`}` is optional**
  15. `{blue:This is a blue line` <- Perfectly valid
  16. ##Usage
  17. ```js
  18. var tFunk = require("tfunk");
  19. console.log( tfunk("{cyan:tFunk terminal colours") )
  20. // => tFunk terminal colours
  21. ```
  22. Or get a custom compiler with a set prefix:
  23. ```js
  24. var compiler = require("tfunk").Compiler({
  25. prefix: "[{magenta:tFunk}]"
  26. });
  27. console.log( compiler.compile("tFunk is awesome") );
  28. console.log( compiler.compile("don't you think?") );
  29. // => [tFunk] tFunk is awesome
  30. // => [tFunk] don't you think?
  31. ```
  32. **Define your own syntax**
  33. You can define your own methods, they receive the string section as the first parameter & have access to the compiler
  34. through `this.compile()` keyword.
  35. ```js
  36. var compiler = require("tfunk").Compiler({
  37. "warn": function(string) {
  38. return this.compile("{red:WARNING:" + string);
  39. }
  40. });
  41. ```
  42. Now you can use `warn` anywhere you like.
  43. ```js
  44. console.log( compiler.compile("{warn: Could not file your config file...") );
  45. // => WARNING: Could not file your config file...
  46. ```
  47. ##Examples
  48. Here are some comparisons to chalk, to help you understand how to use tFunk.
  49. ###Single Colours
  50. ```js
  51. // chalk
  52. console.log( chalk.red("This has a single colour") );
  53. // tFunk
  54. console.log( tFunk("{red:This has a single colour") );
  55. ```
  56. ###Single Colour mid string
  57. ```js
  58. // chalk
  59. console.log( "This has a single colour " + chalk.cyan("that begins mid-string") );
  60. // tFunck
  61. console.log( tFunk("This has a single colour {cyan:that begins mid-string") );
  62. ```
  63. ###Single Colour with end point
  64. ```js
  65. // chalk
  66. console.log( chalk.red("This has a single colour with ") + "an endpoint");
  67. // tFunk
  68. console.log( tFunk("{red:This has a single colour with }an endpoint") );
  69. ```
  70. ###Two Colours
  71. ```js
  72. // chalk
  73. console.log( chalk.green("This has ") + chalk.cyan("two colours") );
  74. // tFunk
  75. console.log( tFunk("{green:This has {cyan:two colours") );
  76. ```
  77. ###Nested Colours
  78. ```js
  79. // chalk
  80. console.log( chalk.green("This has a colour " + chalk.cyan("nested inside") + " another colour") );
  81. //tFunk
  82. console.log( tFunk("{green:This has a colour {cyan:nested inside} another colour") );
  83. ```
  84. ###Multiple Nested
  85. ```js
  86. // chalk
  87. console.log( chalk.blue("Multiple " + chalk.cyan("NESTED") + " styles in " + chalk.red("the same string") + " with an ending") );
  88. // tFunk
  89. console.log( tFunk("{blue:Multiple {cyan:NESTED} styles in {red:the same string} with an ending") );
  90. ```
  91. ###Multi line
  92. ```js
  93. var multiline = require("multiline");
  94. var string = multiline(function () {/*
  95. {cyan:This is a multi-line coloured string
  96. With a single {yellow:yellow} word in the center of a line
  97. Pretty cool huh?
  98. */});
  99. console.log( tFunk(string) );
  100. ```
  101. ###Escaping when you need curly braces
  102. ```js
  103. console.log( tFunk("This has a \\{\\{mustache\\}\\}") );
  104. ```
  105. ##TODO
  106. - [x] Colours
  107. - [x] Nested Colours
  108. - [x] Custom syntax
  109. - [x] Prefixed compiler
  110. - [x] Make the chain-able API work like this `"{white.bgRed: White text, red BG"`
  111. - [x] Offer a way of escaping. Right now, ALL instances of `}` will be lost