README.rst 5.4 KB

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