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.

313 lines
9.3 KiB

4 years ago
  1. # Using the Richtext Controls
  2. <p align="center">
  3. <img src="https://github.com/chriskiehl/GooeyImages/raw/images/docs/richtext-controls/richtext-screen.png">
  4. </p>
  5. Gooey has a support for basic terminal control sequences. These let you control weight and color of the output font. For a full runnable example, checkout the code [from the examples repository](https://github.com/chriskiehl/GooeyExamples/blob/master/examples/richtext_demo.py)
  6. You can enable this mode by passing the `richtext_controls` option to the Gooey decorator.
  7. ```python
  8. @Gooey(richtext_controls=True)
  9. def main():
  10. ...
  11. ```
  12. ### Usage
  13. The [colored library](https://pypi.org/project/colored/) provides functions for adding markup controls to your text. Gooey supports the foreground (`fg`) and attributes (`attr`).
  14. ```python
  15. from colored import stylize, attr, fg
  16. ```
  17. You can modify your text's output by wrapping it in the `stylize` function provided by colored.py. For instance, this line will be displayed as bold (`attr(1)`) and red (`fg('red')`) when rendered by Gooey.
  18. ```python
  19. print(stylize('Hello world!', fg('red') + attr('bold')))
  20. ```
  21. > Note that you combine the foreground and attribute functions with the `+` operator.
  22. ### Attributes:
  23. Richtext currently supports the following attributes:
  24. |Code | Description |
  25. |:----|------------------|
  26. | 1 | bold |
  27. | 4 | underlined |
  28. | 0 | reset |
  29. | 21 | res_bold |
  30. | 24 | res_underlined |
  31. These can be used either via their code (`attr(1)`) or their verbose form (`attr('bold')`)
  32. ### Foreground Colors:
  33. Similar to the Attributes, foreground colors can be specified either by their code (`fg(2)`) or verbose form (`fg('green')`)
  34. |Code | Description |
  35. |:----|---------------------|
  36. | 0 | black |
  37. | 1 | red |
  38. | 2 | green |
  39. | 3 | yellow |
  40. | 4 | blue |
  41. | 5 | magenta |
  42. | 6 | cyan |
  43. | 7 | light_gray |
  44. | 8 | dark_gray |
  45. | 9 | light_red |
  46. | 10 | light_green |
  47. | 11 | light_yellow |
  48. | 12 | light_blue |
  49. | 13 | light_magenta |
  50. | 14 | light_cyan |
  51. | 15 | white |
  52. | 16 | grey_0 |
  53. | 17 | navy_blue |
  54. | 18 | dark_blue |
  55. | 19 | blue_3a |
  56. | 20 | blue_3b |
  57. | 21 | blue_1 |
  58. | 22 | dark_green |
  59. | 23 | deep_sky_blue_4a |
  60. | 24 | deep_sky_blue_4b |
  61. | 25 | deep_sky_blue_4c |
  62. | 26 | dodger_blue_3 |
  63. | 27 | dodger_blue_2 |
  64. | 28 | green_4 |
  65. | 29 | spring_green_4 |
  66. | 30 | turquoise_4 |
  67. | 31 | deep_sky_blue_3a |
  68. | 32 | deep_sky_blue_3b |
  69. | 33 | dodger_blue_1 |
  70. | 34 | green_3a |
  71. | 35 | spring_green_3a |
  72. | 36 | dark_cyan |
  73. | 37 | light_sea_green |
  74. | 38 | deep_sky_blue_2 |
  75. | 39 | deep_sky_blue_1 |
  76. | 40 | green_3b |
  77. | 41 | spring_green_3b |
  78. | 42 | spring_green_2a |
  79. | 43 | cyan_3 |
  80. | 44 | dark_turquoise |
  81. | 45 | turquoise_2 |
  82. | 46 | green_1 |
  83. | 47 | spring_green_2b |
  84. | 48 | spring_green_1 |
  85. | 49 | medium_spring_green |
  86. | 50 | cyan_2 |
  87. | 51 | cyan_1 |
  88. | 52 | dark_red_1 |
  89. | 53 | deep_pink_4a |
  90. | 54 | purple_4a |
  91. | 55 | purple_4b |
  92. | 56 | purple_3 |
  93. | 57 | blue_violet |
  94. | 58 | orange_4a |
  95. | 59 | grey_37 |
  96. | 60 | medium_purple_4 |
  97. | 61 | slate_blue_3a |
  98. | 62 | slate_blue_3b |
  99. | 63 | royal_blue_1 |
  100. | 64 | chartreuse_4 |
  101. | 65 | dark_sea_green_4a |
  102. | 66 | pale_turquoise_4 |
  103. | 67 | steel_blue |
  104. | 68 | steel_blue_3 |
  105. | 69 | cornflower_blue |
  106. | 70 | chartreuse_3a |
  107. | 71 | dark_sea_green_4b |
  108. | 72 | cadet_blue_2 |
  109. | 73 | cadet_blue_1 |
  110. | 74 | sky_blue_3 |
  111. | 75 | steel_blue_1a |
  112. | 76 | chartreuse_3b |
  113. | 77 | pale_green_3a |
  114. | 78 | sea_green_3 |
  115. | 79 | aquamarine_3 |
  116. | 80 | medium_turquoise |
  117. | 81 | steel_blue_1b |
  118. | 82 | chartreuse_2a |
  119. | 83 | sea_green_2 |
  120. | 84 | sea_green_1a |
  121. | 85 | sea_green_1b |
  122. | 86 | aquamarine_1a |
  123. | 87 | dark_slate_gray_2 |
  124. | 88 | dark_red_2 |
  125. | 89 | deep_pink_4b |
  126. | 90 | dark_magenta_1 |
  127. | 91 | dark_magenta_2 |
  128. | 92 | dark_violet_1a |
  129. | 93 | purple_1a |
  130. | 94 | orange_4b |
  131. | 95 | light_pink_4 |
  132. | 96 | plum_4 |
  133. | 97 | medium_purple_3a |
  134. | 98 | medium_purple_3b |
  135. | 99 | slate_blue_1 |
  136. | 100 | yellow_4a |
  137. | 101 | wheat_4 |
  138. | 102 | grey_53 |
  139. | 103 | light_slate_grey |
  140. | 104 | medium_purple |
  141. | 105 | light_slate_blue |
  142. | 106 | yellow_4b |
  143. | 107 | dark_olive_green_3a |
  144. | 108 | dark_green_sea |
  145. | 109 | light_sky_blue_3a |
  146. | 110 | light_sky_blue_3b |
  147. | 111 | sky_blue_2 |
  148. | 112 | chartreuse_2b |
  149. | 113 | dark_olive_green_3b |
  150. | 114 | pale_green_3b |
  151. | 115 | dark_sea_green_3a |
  152. | 116 | dark_slate_gray_3 |
  153. | 117 | sky_blue_1 |
  154. | 118 | chartreuse_1 |
  155. | 119 | light_green_2 |
  156. | 120 | light_green_3 |
  157. | 121 | pale_green_1a |
  158. | 122 | aquamarine_1b |
  159. | 123 | dark_slate_gray_1 |
  160. | 124 | red_3a |
  161. | 125 | deep_pink_4c |
  162. | 126 | medium_violet_red |
  163. | 127 | magenta_3a |
  164. | 128 | dark_violet_1b |
  165. | 129 | purple_1b |
  166. | 130 | dark_orange_3a |
  167. | 131 | indian_red_1a |
  168. | 132 | hot_pink_3a |
  169. | 133 | medium_orchid_3 |
  170. | 134 | medium_orchid |
  171. | 135 | medium_purple_2a |
  172. | 136 | dark_goldenrod |
  173. | 137 | light_salmon_3a |
  174. | 138 | rosy_brown |
  175. | 139 | grey_63 |
  176. | 140 | medium_purple_2b |
  177. | 141 | medium_purple_1 |
  178. | 142 | gold_3a |
  179. | 143 | dark_khaki |
  180. | 144 | navajo_white_3 |
  181. | 145 | grey_69 |
  182. | 146 | light_steel_blue_3 |
  183. | 147 | light_steel_blue |
  184. | 148 | yellow_3a |
  185. | 149 | dark_olive_green_3 |
  186. | 150 | dark_sea_green_3b |
  187. | 151 | dark_sea_green_2 |
  188. | 152 | light_cyan_3 |
  189. | 153 | light_sky_blue_1 |
  190. | 154 | green_yellow |
  191. | 155 | dark_olive_green_2 |
  192. | 156 | pale_green_1b |
  193. | 157 | dark_sea_green_5b |
  194. | 158 | dark_sea_green_5a |
  195. | 159 | pale_turquoise_1 |
  196. | 160 | red_3b |
  197. | 161 | deep_pink_3a |
  198. | 162 | deep_pink_3b |
  199. | 163 | magenta_3b |
  200. | 164 | magenta_3c |
  201. | 165 | magenta_2a |
  202. | 166 | dark_orange_3b |
  203. | 167 | indian_red_1b |
  204. | 168 | hot_pink_3b |
  205. | 169 | hot_pink_2 |
  206. | 170 | orchid |
  207. | 171 | medium_orchid_1a |
  208. | 172 | orange_3 |
  209. | 173 | light_salmon_3b |
  210. | 174 | light_pink_3 |
  211. | 175 | pink_3 |
  212. | 176 | plum_3 |
  213. | 177 | violet |
  214. | 178 | gold_3b |
  215. | 179 | light_goldenrod_3 |
  216. | 180 | tan |
  217. | 181 | misty_rose_3 |
  218. | 182 | thistle_3 |
  219. | 183 | plum_2 |
  220. | 184 | yellow_3b |
  221. | 185 | khaki_3 |
  222. | 186 | light_goldenrod_2a |
  223. | 187 | light_yellow_3 |
  224. | 188 | grey_84 |
  225. | 189 | light_steel_blue_1 |
  226. | 190 | yellow_2 |
  227. | 191 | dark_olive_green_1a |
  228. | 192 | dark_olive_green_1b |
  229. | 193 | dark_sea_green_1 |
  230. | 194 | honeydew_2 |
  231. | 195 | light_cyan_1 |
  232. | 196 | red_1 |
  233. | 197 | deep_pink_2 |
  234. | 198 | deep_pink_1a |
  235. | 199 | deep_pink_1b |
  236. | 200 | magenta_2b |
  237. | 201 | magenta_1 |
  238. | 202 | orange_red_1 |
  239. | 203 | indian_red_1c |
  240. | 204 | indian_red_1d |
  241. | 205 | hot_pink_1a |
  242. | 206 | hot_pink_1b |
  243. | 207 | medium_orchid_1b |
  244. | 208 | dark_orange |
  245. | 209 | salmon_1 |
  246. | 210 | light_coral |
  247. | 211 | pale_violet_red_1 |
  248. | 212 | orchid_2 |
  249. | 213 | orchid_1 |
  250. | 214 | orange_1 |
  251. | 215 | sandy_brown |
  252. | 216 | light_salmon_1 |
  253. | 217 | light_pink_1 |
  254. | 218 | pink_1 |
  255. | 219 | plum_1 |
  256. | 220 | gold_1 |
  257. | 221 | light_goldenrod_2b |
  258. | 222 | light_goldenrod_2c |
  259. | 223 | navajo_white_1 |
  260. | 224 | misty_rose1 |
  261. | 225 | thistle_1 |
  262. | 226 | yellow_1 |
  263. | 227 | light_goldenrod_1 |
  264. | 228 | khaki_1 |
  265. | 229 | wheat_1 |
  266. | 230 | cornsilk_1 |
  267. | 231 | grey_100 |
  268. | 232 | grey_3 |
  269. | 233 | grey_7 |
  270. | 234 | grey_11 |
  271. | 235 | grey_15 |
  272. | 236 | grey_19 |
  273. | 237 | grey_23 |
  274. | 238 | grey_27 |
  275. | 239 | grey_30 |
  276. | 240 | grey_35 |
  277. | 241 | grey_39 |
  278. | 242 | grey_42 |
  279. | 243 | grey_46 |
  280. | 244 | grey_50 |
  281. | 245 | grey_54 |
  282. | 246 | grey_58 |
  283. | 247 | grey_62 |
  284. | 248 | grey_66 |
  285. | 249 | grey_70 |
  286. | 250 | grey_74 |
  287. | 251 | grey_78 |
  288. | 252 | grey_82 |
  289. | 253 | grey_85 |
  290. | 254 | grey_89 |
  291. | 255 | grey_93 |
  292. | 256 | default |