README.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. Python Prompt Toolkit
  2. =====================
  3. |Build Status| |AppVeyor| |PyPI| |RTD| |License| |Codecov|
  4. .. image :: https://github.com/prompt-toolkit/python-prompt-toolkit/raw/master/docs/images/logo_400px.png
  5. ``prompt_toolkit`` *is a library for building powerful interactive command line applications in Python.*
  6. Read the `documentation on readthedocs
  7. <http://python-prompt-toolkit.readthedocs.io/en/stable/>`_.
  8. NOTICE: prompt_toolkit 3.0
  9. **************************
  10. Please notice that this branch is the ``prompt_toolkit`` **3.0** branch. For most
  11. users, it should be compatible with ``prompt_toolkit`` **2.0**, but it requires at
  12. least **Python 3.6**. On the plus side, ``prompt_toolkit`` **3.0** is completely type
  13. annotated and uses asyncio natively.
  14. Gallery
  15. *******
  16. `ptpython <http://github.com/prompt-toolkit/ptpython/>`_ is an interactive
  17. Python Shell, build on top of ``prompt_toolkit``.
  18. .. image :: https://github.com/prompt-toolkit/python-prompt-toolkit/raw/master/docs/images/ptpython.png
  19. `More examples <https://python-prompt-toolkit.readthedocs.io/en/stable/pages/gallery.html>`_
  20. prompt_toolkit features
  21. ***********************
  22. ``prompt_toolkit`` could be a replacement for `GNU readline
  23. <https://tiswww.case.edu/php/chet/readline/rltop.html>`_, but it can be much
  24. more than that.
  25. Some features:
  26. - **Pure Python**.
  27. - Syntax highlighting of the input while typing. (For instance, with a Pygments lexer.)
  28. - Multi-line input editing.
  29. - Advanced code completion.
  30. - Both Emacs and Vi key bindings. (Similar to readline.)
  31. - Even some advanced Vi functionality, like named registers and digraphs.
  32. - Reverse and forward incremental search.
  33. - Works well with Unicode double width characters. (Chinese input.)
  34. - Selecting text for copy/paste. (Both Emacs and Vi style.)
  35. - Support for `bracketed paste <https://cirw.in/blog/bracketed-paste>`_.
  36. - Mouse support for cursor positioning and scrolling.
  37. - Auto suggestions. (Like `fish shell <http://fishshell.com/>`_.)
  38. - Multiple input buffers.
  39. - No global state.
  40. - Lightweight, the only dependencies are Pygments and wcwidth.
  41. - Runs on Linux, OS X, FreeBSD, OpenBSD and Windows systems.
  42. - And much more...
  43. Feel free to create tickets for bugs and feature requests, and create pull
  44. requests if you have nice patches that you would like to share with others.
  45. Installation
  46. ************
  47. ::
  48. pip install prompt_toolkit
  49. For Conda, do:
  50. ::
  51. conda install -c https://conda.anaconda.org/conda-forge prompt_toolkit
  52. About Windows support
  53. *********************
  54. ``prompt_toolkit`` is cross platform, and everything that you build on top
  55. should run fine on both Unix and Windows systems. Windows support is best on
  56. recent Windows 10 builds, for which the command line window supports vt100
  57. escape sequences. (If not supported, we fall back to using Win32 APIs for color
  58. and cursor movements).
  59. It's worth noting that the implementation is a "best effort of what is
  60. possible". Both Unix and Windows terminals have their limitations. But in
  61. general, the Unix experience will still be a little better.
  62. For Windows, it's recommended to use either `cmder
  63. <http://cmder.net/>`_ or `conemu <https://conemu.github.io/>`_.
  64. Getting started
  65. ***************
  66. The most simple example of the library would look like this:
  67. .. code:: python
  68. from prompt_toolkit import prompt
  69. if __name__ == '__main__':
  70. answer = prompt('Give me some input: ')
  71. print('You said: %s' % answer)
  72. For more complex examples, have a look in the ``examples`` directory. All
  73. examples are chosen to demonstrate only one thing. Also, don't be afraid to
  74. look at the source code. The implementation of the ``prompt`` function could be
  75. a good start.
  76. Philosophy
  77. **********
  78. The source code of ``prompt_toolkit`` should be **readable**, **concise** and
  79. **efficient**. We prefer short functions focusing each on one task and for which
  80. the input and output types are clearly specified. We mostly prefer composition
  81. over inheritance, because inheritance can result in too much functionality in
  82. the same object. We prefer immutable objects where possible (objects don't
  83. change after initialization). Reusability is important. We absolutely refrain
  84. from having a changing global state, it should be possible to have multiple
  85. independent instances of the same code in the same process. The architecture
  86. should be layered: the lower levels operate on primitive operations and data
  87. structures giving -- when correctly combined -- all the possible flexibility;
  88. while at the higher level, there should be a simpler API, ready-to-use and
  89. sufficient for most use cases. Thinking about algorithms and efficiency is
  90. important, but avoid premature optimization.
  91. `Projects using prompt_toolkit <PROJECTS.rst>`_
  92. ***********************************************
  93. Special thanks to
  94. *****************
  95. - `Pygments <http://pygments.org/>`_: Syntax highlighter.
  96. - `wcwidth <https://github.com/jquast/wcwidth>`_: Determine columns needed for a wide characters.
  97. .. |Build Status| image:: https://api.travis-ci.org/prompt-toolkit/python-prompt-toolkit.svg?branch=master
  98. :target: https://travis-ci.org/prompt-toolkit/python-prompt-toolkit#
  99. .. |PyPI| image:: https://img.shields.io/pypi/v/prompt_toolkit.svg
  100. :target: https://pypi.python.org/pypi/prompt-toolkit/
  101. :alt: Latest Version
  102. .. |AppVeyor| image:: https://ci.appveyor.com/api/projects/status/32r7s2skrgm9ubva?svg=true
  103. :target: https://ci.appveyor.com/project/prompt-toolkit/python-prompt-toolkit/
  104. .. |RTD| image:: https://readthedocs.org/projects/python-prompt-toolkit/badge/
  105. :target: https://python-prompt-toolkit.readthedocs.io/en/master/
  106. .. |License| image:: https://img.shields.io/github/license/prompt-toolkit/python-prompt-toolkit.svg
  107. :target: https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/LICENSE
  108. .. |Codecov| image:: https://codecov.io/gh/prompt-toolkit/python-prompt-toolkit/branch/master/graphs/badge.svg?style=flat
  109. :target: https://codecov.io/gh/prompt-toolkit/python-prompt-toolkit/