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.

416 lines
14KB

  1. Metadata-Version: 2.1
  2. Name: colorama
  3. Version: 0.4.4
  4. Summary: Cross-platform colored terminal text.
  5. Home-page: https://github.com/tartley/colorama
  6. Author: Jonathan Hartley
  7. Author-email: tartley@tartley.com
  8. Maintainer: Arnon Yaari
  9. License: BSD
  10. Keywords: color colour terminal text ansi windows crossplatform xplatform
  11. Platform: UNKNOWN
  12. Classifier: Development Status :: 5 - Production/Stable
  13. Classifier: Environment :: Console
  14. Classifier: Intended Audience :: Developers
  15. Classifier: License :: OSI Approved :: BSD License
  16. Classifier: Operating System :: OS Independent
  17. Classifier: Programming Language :: Python
  18. Classifier: Programming Language :: Python :: 2
  19. Classifier: Programming Language :: Python :: 2.7
  20. Classifier: Programming Language :: Python :: 3
  21. Classifier: Programming Language :: Python :: 3.5
  22. Classifier: Programming Language :: Python :: 3.6
  23. Classifier: Programming Language :: Python :: 3.7
  24. Classifier: Programming Language :: Python :: 3.8
  25. Classifier: Programming Language :: Python :: Implementation :: CPython
  26. Classifier: Programming Language :: Python :: Implementation :: PyPy
  27. Classifier: Topic :: Terminals
  28. Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
  29. .. image:: https://img.shields.io/pypi/v/colorama.svg
  30. :target: https://pypi.org/project/colorama/
  31. :alt: Latest Version
  32. .. image:: https://img.shields.io/pypi/pyversions/colorama.svg
  33. :target: https://pypi.org/project/colorama/
  34. :alt: Supported Python versions
  35. .. image:: https://travis-ci.org/tartley/colorama.svg?branch=master
  36. :target: https://travis-ci.org/tartley/colorama
  37. :alt: Build Status
  38. Colorama
  39. ========
  40. Makes ANSI escape character sequences (for producing colored terminal text and
  41. cursor positioning) work under MS Windows.
  42. .. |donate| image:: https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif
  43. :target: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=2MZ9D2GMLYCUJ&item_name=Colorama&currency_code=USD
  44. :alt: Donate with Paypal
  45. `PyPI for releases <https://pypi.org/project/colorama/>`_ ·
  46. `Github for source <https://github.com/tartley/colorama>`_ ·
  47. `Colorama for enterprise on Tidelift <https://github.com/tartley/colorama/blob/master/ENTERPRISE.md>`_
  48. If you find Colorama useful, please |donate| to the authors. Thank you!
  49. Installation
  50. ------------
  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.init()``.
  68. An alternative approach is to install ``ansi.sys`` on Windows machines, which
  69. provides the same behaviour for all applications running in terminals. Colorama
  70. is intended for situations where that isn't easy (e.g., maybe your app doesn't
  71. have an installer.)
  72. Demo scripts in the source code repository print some colored text using
  73. ANSI sequences. Compare their output under Gnome-terminal's built in ANSI
  74. handling, versus on Windows Command-Prompt using Colorama:
  75. .. image:: https://github.com/tartley/colorama/raw/master/screenshots/ubuntu-demo.png
  76. :width: 661
  77. :height: 357
  78. :alt: ANSI sequences on Ubuntu under gnome-terminal.
  79. .. image:: https://github.com/tartley/colorama/raw/master/screenshots/windows-demo.png
  80. :width: 668
  81. :height: 325
  82. :alt: Same ANSI sequences on Windows, using Colorama.
  83. These screenshots show that, on Windows, Colorama does not support ANSI 'dim
  84. text'; it looks the same as 'normal text'.
  85. Usage
  86. -----
  87. Initialisation
  88. ..............
  89. Applications should initialise Colorama using:
  90. .. code-block:: python
  91. from colorama import init
  92. init()
  93. On Windows, calling ``init()`` will filter ANSI escape sequences out of any
  94. text sent to ``stdout`` or ``stderr``, and replace them with equivalent Win32
  95. calls.
  96. On other platforms, calling ``init()`` has no effect (unless you request other
  97. optional functionality; see "Init Keyword Args", below). By design, this permits
  98. applications to call ``init()`` unconditionally on all platforms, after which
  99. ANSI output should just work.
  100. To stop using Colorama before your program exits, simply call ``deinit()``.
  101. This will restore ``stdout`` and ``stderr`` to their original values, so that
  102. Colorama is disabled. To resume using Colorama again, call ``reinit()``; it is
  103. cheaper than calling ``init()`` again (but does the same thing).
  104. Colored Output
  105. ..............
  106. Cross-platform printing of colored text can then be done using Colorama's
  107. constant shorthand for ANSI escape sequences:
  108. .. code-block:: python
  109. from colorama import Fore, Back, Style
  110. print(Fore.RED + 'some red text')
  111. print(Back.GREEN + 'and with a green background')
  112. print(Style.DIM + 'and in dim text')
  113. print(Style.RESET_ALL)
  114. print('back to normal now')
  115. ...or simply by manually printing ANSI sequences from your own code:
  116. .. code-block:: python
  117. print('\033[31m' + 'some red text')
  118. print('\033[39m') # and reset to default color
  119. ...or, Colorama can be used in conjunction with existing ANSI libraries
  120. such as the venerable `Termcolor <https://pypi.org/project/termcolor/>`_
  121. or the fabulous `Blessings <https://pypi.org/project/blessings/>`_.
  122. This is highly recommended for anything more than trivial coloring:
  123. .. code-block:: python
  124. from colorama import init
  125. from termcolor import colored
  126. # use Colorama to make Termcolor work on Windows too
  127. init()
  128. # then use Termcolor for all colored text output
  129. print(colored('Hello, World!', 'green', 'on_red'))
  130. Available formatting constants are::
  131. Fore: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
  132. Back: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
  133. Style: DIM, NORMAL, BRIGHT, RESET_ALL
  134. ``Style.RESET_ALL`` resets foreground, background, and brightness. Colorama will
  135. perform this reset automatically on program exit.
  136. Cursor Positioning
  137. ..................
  138. ANSI codes to reposition the cursor are supported. See ``demos/demo06.py`` for
  139. an example of how to generate them.
  140. Init Keyword Args
  141. .................
  142. ``init()`` accepts some ``**kwargs`` to override default behaviour.
  143. init(autoreset=False):
  144. If you find yourself repeatedly sending reset sequences to turn off color
  145. changes at the end of every print, then ``init(autoreset=True)`` will
  146. automate that:
  147. .. code-block:: python
  148. from colorama import init
  149. init(autoreset=True)
  150. print(Fore.RED + 'some red text')
  151. print('automatically back to default color again')
  152. init(strip=None):
  153. Pass ``True`` or ``False`` to override whether ANSI codes should be
  154. stripped from the output. The default behaviour is to strip if on Windows
  155. or if output is redirected (not a tty).
  156. init(convert=None):
  157. Pass ``True`` or ``False`` to override whether to convert ANSI codes in the
  158. output into win32 calls. The default behaviour is to convert if on Windows
  159. and output is to a tty (terminal).
  160. init(wrap=True):
  161. On Windows, Colorama works by replacing ``sys.stdout`` and ``sys.stderr``
  162. with proxy objects, which override the ``.write()`` method to do their work.
  163. If this wrapping causes you problems, then this can be disabled by passing
  164. ``init(wrap=False)``. The default behaviour is to wrap if ``autoreset`` or
  165. ``strip`` or ``convert`` are True.
  166. When wrapping is disabled, colored printing on non-Windows platforms will
  167. continue to work as normal. To do cross-platform colored output, you can
  168. use Colorama's ``AnsiToWin32`` proxy directly:
  169. .. code-block:: python
  170. import sys
  171. from colorama import init, AnsiToWin32
  172. init(wrap=False)
  173. stream = AnsiToWin32(sys.stderr).stream
  174. # Python 2
  175. print >>stream, Fore.BLUE + 'blue text on stderr'
  176. # Python 3
  177. print(Fore.BLUE + 'blue text on stderr', file=stream)
  178. Recognised ANSI Sequences
  179. .........................
  180. ANSI sequences generally take the form::
  181. ESC [ <param> ; <param> ... <command>
  182. Where ``<param>`` is an integer, and ``<command>`` is a single letter. Zero or
  183. more params are passed to a ``<command>``. If no params are passed, it is
  184. generally synonymous with passing a single zero. No spaces exist in the
  185. sequence; they have been inserted here simply to read more easily.
  186. The only ANSI sequences that Colorama converts into win32 calls are::
  187. ESC [ 0 m # reset all (colors and brightness)
  188. ESC [ 1 m # bright
  189. ESC [ 2 m # dim (looks same as normal brightness)
  190. ESC [ 22 m # normal brightness
  191. # FOREGROUND:
  192. ESC [ 30 m # black
  193. ESC [ 31 m # red
  194. ESC [ 32 m # green
  195. ESC [ 33 m # yellow
  196. ESC [ 34 m # blue
  197. ESC [ 35 m # magenta
  198. ESC [ 36 m # cyan
  199. ESC [ 37 m # white
  200. ESC [ 39 m # reset
  201. # BACKGROUND
  202. ESC [ 40 m # black
  203. ESC [ 41 m # red
  204. ESC [ 42 m # green
  205. ESC [ 43 m # yellow
  206. ESC [ 44 m # blue
  207. ESC [ 45 m # magenta
  208. ESC [ 46 m # cyan
  209. ESC [ 47 m # white
  210. ESC [ 49 m # reset
  211. # cursor positioning
  212. ESC [ y;x H # position cursor at x across, y down
  213. ESC [ y;x f # position cursor at x across, y down
  214. ESC [ n A # move cursor n lines up
  215. ESC [ n B # move cursor n lines down
  216. ESC [ n C # move cursor n characters forward
  217. ESC [ n D # move cursor n characters backward
  218. # clear the screen
  219. ESC [ mode J # clear the screen
  220. # clear the line
  221. ESC [ mode K # clear the line
  222. Multiple numeric params to the ``'m'`` command can be combined into a single
  223. sequence::
  224. ESC [ 36 ; 45 ; 1 m # bright cyan text on magenta background
  225. All other ANSI sequences of the form ``ESC [ <param> ; <param> ... <command>``
  226. are silently stripped from the output on Windows.
  227. Any other form of ANSI sequence, such as single-character codes or alternative
  228. initial characters, are not recognised or stripped. It would be cool to add
  229. them though. Let me know if it would be useful for you, via the Issues on
  230. GitHub.
  231. Status & Known Problems
  232. -----------------------
  233. I've personally only tested it on Windows XP (CMD, Console2), Ubuntu
  234. (gnome-terminal, xterm), and OS X.
  235. Some presumably valid ANSI sequences aren't recognised (see details below),
  236. but to my knowledge nobody has yet complained about this. Puzzling.
  237. See outstanding issues and wish-list:
  238. https://github.com/tartley/colorama/issues
  239. If anything doesn't work for you, or doesn't do what you expected or hoped for,
  240. I'd love to hear about it on that issues list, would be delighted by patches,
  241. and would be happy to grant commit access to anyone who submits a working patch
  242. or two.
  243. License
  244. -------
  245. Copyright Jonathan Hartley & Arnon Yaari, 2013-2020. BSD 3-Clause license; see
  246. LICENSE file.
  247. Development
  248. -----------
  249. Help and fixes welcome!
  250. Tested on CPython 2.7, 3.5, 3.6, 3.7 and 3.8.
  251. No requirements other than the standard library.
  252. Development requirements are captured in requirements-dev.txt.
  253. To create and populate a virtual environment::
  254. ./bootstrap.ps1 # Windows
  255. make bootstrap # Linux
  256. To run tests::
  257. ./test.ps1 # Windows
  258. make test # Linux
  259. If you use nose to run the tests, you must pass the ``-s`` flag; otherwise,
  260. ``nosetests`` applies its own proxy to ``stdout``, which confuses the unit
  261. tests.
  262. Professional support
  263. --------------------
  264. .. |tideliftlogo| image:: https://cdn2.hubspot.net/hubfs/4008838/website/logos/logos_for_download/Tidelift_primary-shorthand-logo.png
  265. :alt: Tidelift
  266. :target: https://tidelift.com/subscription/pkg/pypi-colorama?utm_source=pypi-colorama&utm_medium=referral&utm_campaign=readme
  267. .. list-table::
  268. :widths: 10 100
  269. * - |tideliftlogo|
  270. - Professional support for colorama is available as part of the
  271. `Tidelift Subscription`_.
  272. Tidelift gives software development teams a single source for purchasing
  273. and maintaining their software, with professional grade assurances from
  274. the experts who know it best, while seamlessly integrating with existing
  275. tools.
  276. .. _Tidelift Subscription: https://tidelift.com/subscription/pkg/pypi-colorama?utm_source=pypi-colorama&utm_medium=referral&utm_campaign=readme
  277. Thanks
  278. ------
  279. * Marc Schlaich (schlamar) for a ``setup.py`` fix for Python2.5.
  280. * Marc Abramowitz, reported & fixed a crash on exit with closed ``stdout``,
  281. providing a solution to issue #7's setuptools/distutils debate,
  282. and other fixes.
  283. * User 'eryksun', for guidance on correctly instantiating ``ctypes.windll``.
  284. * Matthew McCormick for politely pointing out a longstanding crash on non-Win.
  285. * Ben Hoyt, for a magnificent fix under 64-bit Windows.
  286. * Jesse at Empty Square for submitting a fix for examples in the README.
  287. * User 'jamessp', an observant documentation fix for cursor positioning.
  288. * User 'vaal1239', Dave Mckee & Lackner Kristof for a tiny but much-needed Win7
  289. fix.
  290. * Julien Stuyck, for wisely suggesting Python3 compatible updates to README.
  291. * Daniel Griffith for multiple fabulous patches.
  292. * Oscar Lesta for a valuable fix to stop ANSI chars being sent to non-tty
  293. output.
  294. * Roger Binns, for many suggestions, valuable feedback, & bug reports.
  295. * Tim Golden for thought and much appreciated feedback on the initial idea.
  296. * User 'Zearin' for updates to the README file.
  297. * John Szakmeister for adding support for light colors
  298. * Charles Merriam for adding documentation to demos
  299. * Jurko for a fix on 64-bit Windows CPython2.5 w/o ctypes
  300. * Florian Bruhin for a fix when stdout or stderr are None
  301. * Thomas Weininger for fixing ValueError on Windows
  302. * Remi Rampin for better Github integration and fixes to the README file
  303. * Simeon Visser for closing a file handle using 'with' and updating classifiers
  304. to include Python 3.3 and 3.4
  305. * Andy Neff for fixing RESET of LIGHT_EX colors.
  306. * Jonathan Hartley for the initial idea and implementation.