METADATA 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. Metadata-Version: 2.1
  2. Name: colorama
  3. Version: 0.4.6
  4. Summary: Cross-platform colored terminal text.
  5. Project-URL: Homepage, https://github.com/tartley/colorama
  6. Author-email: Jonathan Hartley <tartley@tartley.com>
  7. License-File: LICENSE.txt
  8. Keywords: ansi,color,colour,crossplatform,terminal,text,windows,xplatform
  9. Classifier: Development Status :: 5 - Production/Stable
  10. Classifier: Environment :: Console
  11. Classifier: Intended Audience :: Developers
  12. Classifier: License :: OSI Approved :: BSD License
  13. Classifier: Operating System :: OS Independent
  14. Classifier: Programming Language :: Python
  15. Classifier: Programming Language :: Python :: 2
  16. Classifier: Programming Language :: Python :: 2.7
  17. Classifier: Programming Language :: Python :: 3
  18. Classifier: Programming Language :: Python :: 3.7
  19. Classifier: Programming Language :: Python :: 3.8
  20. Classifier: Programming Language :: Python :: 3.9
  21. Classifier: Programming Language :: Python :: 3.10
  22. Classifier: Programming Language :: Python :: Implementation :: CPython
  23. Classifier: Programming Language :: Python :: Implementation :: PyPy
  24. Classifier: Topic :: Terminals
  25. Requires-Python: !=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7
  26. Description-Content-Type: text/x-rst
  27. .. image:: https://img.shields.io/pypi/v/colorama.svg
  28. :target: https://pypi.org/project/colorama/
  29. :alt: Latest Version
  30. .. image:: https://img.shields.io/pypi/pyversions/colorama.svg
  31. :target: https://pypi.org/project/colorama/
  32. :alt: Supported Python versions
  33. .. image:: https://github.com/tartley/colorama/actions/workflows/test.yml/badge.svg
  34. :target: https://github.com/tartley/colorama/actions/workflows/test.yml
  35. :alt: Build Status
  36. Colorama
  37. ========
  38. Makes ANSI escape character sequences (for producing colored terminal text and
  39. cursor positioning) work under MS Windows.
  40. .. |donate| image:: https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif
  41. :target: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=2MZ9D2GMLYCUJ&item_name=Colorama&currency_code=USD
  42. :alt: Donate with Paypal
  43. `PyPI for releases <https://pypi.org/project/colorama/>`_ |
  44. `Github for source <https://github.com/tartley/colorama>`_ |
  45. `Colorama for enterprise on Tidelift <https://github.com/tartley/colorama/blob/master/ENTERPRISE.md>`_
  46. If you find Colorama useful, please |donate| to the authors. Thank you!
  47. Installation
  48. ------------
  49. Tested on CPython 2.7, 3.7, 3.8, 3.9 and 3.10 and Pypy 2.7 and 3.8.
  50. No requirements other than the standard library.
  51. .. code-block:: bash
  52. pip install colorama
  53. # or
  54. conda install -c anaconda colorama
  55. Description
  56. -----------
  57. ANSI escape character sequences have long been used to produce colored terminal
  58. text and cursor positioning on Unix and Macs. Colorama makes this work on
  59. Windows, too, by wrapping ``stdout``, stripping ANSI sequences it finds (which
  60. would appear as gobbledygook in the output), and converting them into the
  61. appropriate win32 calls to modify the state of the terminal. On other platforms,
  62. Colorama does nothing.
  63. This has the upshot of providing a simple cross-platform API for printing
  64. colored terminal text from Python, and has the happy side-effect that existing
  65. applications or libraries which use ANSI sequences to produce colored output on
  66. Linux or Macs can now also work on Windows, simply by calling
  67. ``colorama.just_fix_windows_console()`` (since v0.4.6) or ``colorama.init()``
  68. (all versions, but may have other side-effects – see below).
  69. An alternative approach is to install ``ansi.sys`` on Windows machines, which
  70. provides the same behaviour for all applications running in terminals. Colorama
  71. is intended for situations where that isn't easy (e.g., maybe your app doesn't
  72. have an installer.)
  73. Demo scripts in the source code repository print some colored text using
  74. ANSI sequences. Compare their output under Gnome-terminal's built in ANSI
  75. handling, versus on Windows Command-Prompt using Colorama:
  76. .. image:: https://github.com/tartley/colorama/raw/master/screenshots/ubuntu-demo.png
  77. :width: 661
  78. :height: 357
  79. :alt: ANSI sequences on Ubuntu under gnome-terminal.
  80. .. image:: https://github.com/tartley/colorama/raw/master/screenshots/windows-demo.png
  81. :width: 668
  82. :height: 325
  83. :alt: Same ANSI sequences on Windows, using Colorama.
  84. These screenshots show that, on Windows, Colorama does not support ANSI 'dim
  85. text'; it looks the same as 'normal text'.
  86. Usage
  87. -----
  88. Initialisation
  89. ..............
  90. If the only thing you want from Colorama is to get ANSI escapes to work on
  91. Windows, then run:
  92. .. code-block:: python
  93. from colorama import just_fix_windows_console
  94. just_fix_windows_console()
  95. If you're on a recent version of Windows 10 or better, and your stdout/stderr
  96. are pointing to a Windows console, then this will flip the magic configuration
  97. switch to enable Windows' built-in ANSI support.
  98. If you're on an older version of Windows, and your stdout/stderr are pointing to
  99. a Windows console, then this will wrap ``sys.stdout`` and/or ``sys.stderr`` in a
  100. magic file object that intercepts ANSI escape sequences and issues the
  101. appropriate Win32 calls to emulate them.
  102. In all other circumstances, it does nothing whatsoever. Basically the idea is
  103. that this makes Windows act like Unix with respect to ANSI escape handling.
  104. It's safe to call this function multiple times. It's safe to call this function
  105. on non-Windows platforms, but it won't do anything. It's safe to call this
  106. function when one or both of your stdout/stderr are redirected to a file – it
  107. won't do anything to those streams.
  108. Alternatively, you can use the older interface with more features (but also more
  109. potential footguns):
  110. .. code-block:: python
  111. from colorama import init
  112. init()
  113. This does the same thing as ``just_fix_windows_console``, except for the
  114. following differences:
  115. - It's not safe to call ``init`` multiple times; you can end up with multiple
  116. layers of wrapping and broken ANSI support.
  117. - Colorama will apply a heuristic to guess whether stdout/stderr support ANSI,
  118. and if it thinks they don't, then it will wrap ``sys.stdout`` and
  119. ``sys.stderr`` in a magic file object that strips out ANSI escape sequences
  120. before printing them. This happens on all platforms, and can be convenient if
  121. you want to write your code to emit ANSI escape sequences unconditionally, and
  122. let Colorama decide whether they should actually be output. But note that
  123. Colorama's heuristic is not particularly clever.
  124. - ``init`` also accepts explicit keyword args to enable/disable various
  125. functionality – see below.
  126. To stop using Colorama before your program exits, simply call ``deinit()``.
  127. This will restore ``stdout`` and ``stderr`` to their original values, so that
  128. Colorama is disabled. To resume using Colorama again, call ``reinit()``; it is
  129. cheaper than calling ``init()`` again (but does the same thing).
  130. Most users should depend on ``colorama >= 0.4.6``, and use
  131. ``just_fix_windows_console``. The old ``init`` interface will be supported
  132. indefinitely for backwards compatibility, but we don't plan to fix any issues
  133. with it, also for backwards compatibility.
  134. Colored Output
  135. ..............
  136. Cross-platform printing of colored text can then be done using Colorama's
  137. constant shorthand for ANSI escape sequences. These are deliberately
  138. rudimentary, see below.
  139. .. code-block:: python
  140. from colorama import Fore, Back, Style
  141. print(Fore.RED + 'some red text')
  142. print(Back.GREEN + 'and with a green background')
  143. print(Style.DIM + 'and in dim text')
  144. print(Style.RESET_ALL)
  145. print('back to normal now')
  146. ...or simply by manually printing ANSI sequences from your own code:
  147. .. code-block:: python
  148. print('\033[31m' + 'some red text')
  149. print('\033[39m') # and reset to default color
  150. ...or, Colorama can be used in conjunction with existing ANSI libraries
  151. such as the venerable `Termcolor <https://pypi.org/project/termcolor/>`_
  152. the fabulous `Blessings <https://pypi.org/project/blessings/>`_,
  153. or the incredible `_Rich <https://pypi.org/project/rich/>`_.
  154. If you wish Colorama's Fore, Back and Style constants were more capable,
  155. then consider using one of the above highly capable libraries to generate
  156. colors, etc, and use Colorama just for its primary purpose: to convert
  157. those ANSI sequences to also work on Windows:
  158. SIMILARLY, do not send PRs adding the generation of new ANSI types to Colorama.
  159. We are only interested in converting ANSI codes to win32 API calls, not
  160. shortcuts like the above to generate ANSI characters.
  161. .. code-block:: python
  162. from colorama import just_fix_windows_console
  163. from termcolor import colored
  164. # use Colorama to make Termcolor work on Windows too
  165. just_fix_windows_console()
  166. # then use Termcolor for all colored text output
  167. print(colored('Hello, World!', 'green', 'on_red'))
  168. Available formatting constants are::
  169. Fore: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
  170. Back: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
  171. Style: DIM, NORMAL, BRIGHT, RESET_ALL
  172. ``Style.RESET_ALL`` resets foreground, background, and brightness. Colorama will
  173. perform this reset automatically on program exit.
  174. These are fairly well supported, but not part of the standard::
  175. Fore: LIGHTBLACK_EX, LIGHTRED_EX, LIGHTGREEN_EX, LIGHTYELLOW_EX, LIGHTBLUE_EX, LIGHTMAGENTA_EX, LIGHTCYAN_EX, LIGHTWHITE_EX
  176. Back: LIGHTBLACK_EX, LIGHTRED_EX, LIGHTGREEN_EX, LIGHTYELLOW_EX, LIGHTBLUE_EX, LIGHTMAGENTA_EX, LIGHTCYAN_EX, LIGHTWHITE_EX
  177. Cursor Positioning
  178. ..................
  179. ANSI codes to reposition the cursor are supported. See ``demos/demo06.py`` for
  180. an example of how to generate them.
  181. Init Keyword Args
  182. .................
  183. ``init()`` accepts some ``**kwargs`` to override default behaviour.
  184. init(autoreset=False):
  185. If you find yourself repeatedly sending reset sequences to turn off color
  186. changes at the end of every print, then ``init(autoreset=True)`` will
  187. automate that:
  188. .. code-block:: python
  189. from colorama import init
  190. init(autoreset=True)
  191. print(Fore.RED + 'some red text')
  192. print('automatically back to default color again')
  193. init(strip=None):
  194. Pass ``True`` or ``False`` to override whether ANSI codes should be
  195. stripped from the output. The default behaviour is to strip if on Windows
  196. or if output is redirected (not a tty).
  197. init(convert=None):
  198. Pass ``True`` or ``False`` to override whether to convert ANSI codes in the
  199. output into win32 calls. The default behaviour is to convert if on Windows
  200. and output is to a tty (terminal).
  201. init(wrap=True):
  202. On Windows, Colorama works by replacing ``sys.stdout`` and ``sys.stderr``
  203. with proxy objects, which override the ``.write()`` method to do their work.
  204. If this wrapping causes you problems, then this can be disabled by passing
  205. ``init(wrap=False)``. The default behaviour is to wrap if ``autoreset`` or
  206. ``strip`` or ``convert`` are True.
  207. When wrapping is disabled, colored printing on non-Windows platforms will
  208. continue to work as normal. To do cross-platform colored output, you can
  209. use Colorama's ``AnsiToWin32`` proxy directly:
  210. .. code-block:: python
  211. import sys
  212. from colorama import init, AnsiToWin32
  213. init(wrap=False)
  214. stream = AnsiToWin32(sys.stderr).stream
  215. # Python 2
  216. print >>stream, Fore.BLUE + 'blue text on stderr'
  217. # Python 3
  218. print(Fore.BLUE + 'blue text on stderr', file=stream)
  219. Recognised ANSI Sequences
  220. .........................
  221. ANSI sequences generally take the form::
  222. ESC [ <param> ; <param> ... <command>
  223. Where ``<param>`` is an integer, and ``<command>`` is a single letter. Zero or
  224. more params are passed to a ``<command>``. If no params are passed, it is
  225. generally synonymous with passing a single zero. No spaces exist in the
  226. sequence; they have been inserted here simply to read more easily.
  227. The only ANSI sequences that Colorama converts into win32 calls are::
  228. ESC [ 0 m # reset all (colors and brightness)
  229. ESC [ 1 m # bright
  230. ESC [ 2 m # dim (looks same as normal brightness)
  231. ESC [ 22 m # normal brightness
  232. # FOREGROUND:
  233. ESC [ 30 m # black
  234. ESC [ 31 m # red
  235. ESC [ 32 m # green
  236. ESC [ 33 m # yellow
  237. ESC [ 34 m # blue
  238. ESC [ 35 m # magenta
  239. ESC [ 36 m # cyan
  240. ESC [ 37 m # white
  241. ESC [ 39 m # reset
  242. # BACKGROUND
  243. ESC [ 40 m # black
  244. ESC [ 41 m # red
  245. ESC [ 42 m # green
  246. ESC [ 43 m # yellow
  247. ESC [ 44 m # blue
  248. ESC [ 45 m # magenta
  249. ESC [ 46 m # cyan
  250. ESC [ 47 m # white
  251. ESC [ 49 m # reset
  252. # cursor positioning
  253. ESC [ y;x H # position cursor at x across, y down
  254. ESC [ y;x f # position cursor at x across, y down
  255. ESC [ n A # move cursor n lines up
  256. ESC [ n B # move cursor n lines down
  257. ESC [ n C # move cursor n characters forward
  258. ESC [ n D # move cursor n characters backward
  259. # clear the screen
  260. ESC [ mode J # clear the screen
  261. # clear the line
  262. ESC [ mode K # clear the line
  263. Multiple numeric params to the ``'m'`` command can be combined into a single
  264. sequence::
  265. ESC [ 36 ; 45 ; 1 m # bright cyan text on magenta background
  266. All other ANSI sequences of the form ``ESC [ <param> ; <param> ... <command>``
  267. are silently stripped from the output on Windows.
  268. Any other form of ANSI sequence, such as single-character codes or alternative
  269. initial characters, are not recognised or stripped. It would be cool to add
  270. them though. Let me know if it would be useful for you, via the Issues on
  271. GitHub.
  272. Status & Known Problems
  273. -----------------------
  274. I've personally only tested it on Windows XP (CMD, Console2), Ubuntu
  275. (gnome-terminal, xterm), and OS X.
  276. Some valid ANSI sequences aren't recognised.
  277. If you're hacking on the code, see `README-hacking.md`_. ESPECIALLY, see the
  278. explanation there of why we do not want PRs that allow Colorama to generate new
  279. types of ANSI codes.
  280. See outstanding issues and wish-list:
  281. https://github.com/tartley/colorama/issues
  282. If anything doesn't work for you, or doesn't do what you expected or hoped for,
  283. I'd love to hear about it on that issues list, would be delighted by patches,
  284. and would be happy to grant commit access to anyone who submits a working patch
  285. or two.
  286. .. _README-hacking.md: README-hacking.md
  287. License
  288. -------
  289. Copyright Jonathan Hartley & Arnon Yaari, 2013-2020. BSD 3-Clause license; see
  290. LICENSE file.
  291. Professional support
  292. --------------------
  293. .. |tideliftlogo| image:: https://cdn2.hubspot.net/hubfs/4008838/website/logos/logos_for_download/Tidelift_primary-shorthand-logo.png
  294. :alt: Tidelift
  295. :target: https://tidelift.com/subscription/pkg/pypi-colorama?utm_source=pypi-colorama&utm_medium=referral&utm_campaign=readme
  296. .. list-table::
  297. :widths: 10 100
  298. * - |tideliftlogo|
  299. - Professional support for colorama is available as part of the
  300. `Tidelift Subscription`_.
  301. Tidelift gives software development teams a single source for purchasing
  302. and maintaining their software, with professional grade assurances from
  303. the experts who know it best, while seamlessly integrating with existing
  304. tools.
  305. .. _Tidelift Subscription: https://tidelift.com/subscription/pkg/pypi-colorama?utm_source=pypi-colorama&utm_medium=referral&utm_campaign=readme
  306. Thanks
  307. ------
  308. See the CHANGELOG for more thanks!
  309. * Marc Schlaich (schlamar) for a ``setup.py`` fix for Python2.5.
  310. * Marc Abramowitz, reported & fixed a crash on exit with closed ``stdout``,
  311. providing a solution to issue #7's setuptools/distutils debate,
  312. and other fixes.
  313. * User 'eryksun', for guidance on correctly instantiating ``ctypes.windll``.
  314. * Matthew McCormick for politely pointing out a longstanding crash on non-Win.
  315. * Ben Hoyt, for a magnificent fix under 64-bit Windows.
  316. * Jesse at Empty Square for submitting a fix for examples in the README.
  317. * User 'jamessp', an observant documentation fix for cursor positioning.
  318. * User 'vaal1239', Dave Mckee & Lackner Kristof for a tiny but much-needed Win7
  319. fix.
  320. * Julien Stuyck, for wisely suggesting Python3 compatible updates to README.
  321. * Daniel Griffith for multiple fabulous patches.
  322. * Oscar Lesta for a valuable fix to stop ANSI chars being sent to non-tty
  323. output.
  324. * Roger Binns, for many suggestions, valuable feedback, & bug reports.
  325. * Tim Golden for thought and much appreciated feedback on the initial idea.
  326. * User 'Zearin' for updates to the README file.
  327. * John Szakmeister for adding support for light colors
  328. * Charles Merriam for adding documentation to demos
  329. * Jurko for a fix on 64-bit Windows CPython2.5 w/o ctypes
  330. * Florian Bruhin for a fix when stdout or stderr are None
  331. * Thomas Weininger for fixing ValueError on Windows
  332. * Remi Rampin for better Github integration and fixes to the README file
  333. * Simeon Visser for closing a file handle using 'with' and updating classifiers
  334. to include Python 3.3 and 3.4
  335. * Andy Neff for fixing RESET of LIGHT_EX colors.
  336. * Jonathan Hartley for the initial idea and implementation.