@@ -4,31 +4,51 @@ Python Prompt Toolkit
44|Build Status | |PyPI |
55
66``prompt_toolkit `` is a Library for building powerful interactive command lines
7- in Python. It ships with a nice interactive Python shell (called ``ptpython ``)
8- built on top of the library.
7+ in Python.
98
10- ``prompt_toolkit `` could be a replacement for ``readline ``, but it can be much
9+ Looking for ptpython, the Python REPL?
10+ **************************************
11+
12+ Are you looking for the interactive Python Shell? We moved the ``ptpython ``
13+ source code in a separate repository This way we are sure not to pollute the
14+ ``prompt_toolkit `` library with any ``ptpython `` specific stuff and
15+ ``ptpython `` can be developed independently. You will now have to install it
16+ through::
17+
18+ pip install ptpython
19+
20+ `Go to ptpython... <http://github.com/jonathanslenders/ptpython/ >`_
21+
22+ .. image :: docs/images/ptpython.png
23+
24+ prompt-toolkit features
25+ ***********************
26+
27+ ``prompt_toolkit `` could be a replacement for `GNU readline
28+ <http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html> `_, but it can be much
1129more than that.
1230
13- Features :
31+ Some features :
1432
1533- Pure Python.
1634- Syntax highlighting of the input while typing. (For instance, with a Pygments lexer.)
1735- Multi-line input editing.
1836- Advanced code completion.
1937- Both Emacs and Vi key bindings. (Similar to readline.)
2038- Reverse and forward incremental search.
21- - Both Python 3 and Python 2.7 support .
39+ - Runs on all Python versions from 2.6 up to 3.4 .
2240- Works well with Unicode double width characters. (Chinese input.)
2341- Selecting text for copy/paste. (Both Emacs and Vi style.)
42+ - Multiple input buffers.
2443- No global state.
44+ - Lightweight, the only dependencies are Pygments, six and wcwidth.
2545- Code written with love.
2646- Runs on Linux, OS X, OpenBSD and Windows systems.
2747
28-
2948Feel free to create tickets for bugs and feature requests, and create pull
3049requests if you have nice patches that you would like to share with others.
3150
51+
3252About Windows support
3353*********************
3454
@@ -38,11 +58,8 @@ different event loop (``WaitForMultipleObjects`` instead of ``select``), and
3858another input and output system. (Win32 APIs instead of pseudo-terminals and
3959VT100.)
4060
41- .. image :: docs/images/ptpython-windows.png
42-
43-
4461That should work fine, however the library is currently much more tested on
45- Linux and Mac os X systems. So, if you find any bugs in the Windows
62+ Linux and Mac OS X systems. So, if you find any bugs in the Windows
4663implementation, or you have an idea how to make the experience better, please
4764create a Github issue.
4865
@@ -59,129 +76,57 @@ Installation
5976 pip install prompt-toolkit
6077
6178
62- The Python repl
79+ Getting started
6380---------------
6481
65- Run ``ptpython `` to get an interactive Python prompt with syntax highlighting,
66- code completion, etc...
67-
68- .. image :: docs/images/ptpython-screenshot.png
69-
70- If you prefer to have Vi key bindings (which currently are more completely
71- implemented than the Emacs bindings), run ``ptpython --vi ``.
72-
73- If you want to embed the REPL inside your application at one point, do:
82+ The most simple example of the library would look like this:
7483
7584.. code :: python
7685
77- from prompt_toolkit.contrib.repl import embed
78- embed(globals (), locals (), vi_mode = False , history_filename = None )
79-
80- Autocompletion
81- **************
82-
83- ``Tab `` and ``shift+tab `` complete the input. (Thanks to the `Jedi
84- <http://jedi.jedidjah.ch/en/latest/> `_ autocompletion library.)
85- In Vi-mode, you can also use ``Ctrl+N `` and ``Ctrl+P ``.
86-
87- .. image :: docs/images/ptpython-complete-menu.png
88-
89-
90- Multiline editing
91- *****************
92-
93- Usually, multi-line editing mode will automatically turn on when you press enter
94- after a colon, however you can always turn it on by pressing ``F7 ``.
95-
96- To execute the input in multi-line mode, you can either press ``Alt+Enter ``, or
97- ``Esc `` followed by ``Enter ``. (If you want the first to work in the OS X
98- terminal, you have to check the "Use option as meta key" checkbox in your
99- terminal settings. For iTerm2, you have to check "Left option acts as +Esc" in
100- the options.)
86+ from prompt_toolkit.contrib.shortcuts import get_input
10187
102- Other features
103- ***************
104-
105- Running system commands: Press ``Meta-! `` in Emacs mode or just ``! `` in Vi
106- navigation mode to see the "Shell command" prompt. There you can enter system
107- commands without leaving the REPL.
108-
109- Selecting text: Press ``Control+Space `` in Emacs mode on ``V `` (major V) in Vi
110- navigation mode.
111-
112- You love IPython?
113- *****************
114-
115- Run ``ptipython `` (prompt_toolkit - IPython), to get a nice interactive shell
116- with all the power that IPython has to offer, like magic functions and shell
117- integration. Make sure that IPython has been installed. (``pip install
118- ipython ``)
119-
120- .. image :: docs/images/ipython-integration.png
121-
122- You are using Django?
123- *********************
124-
125- `django-extensions <https://github.com/django-extensions/django-extensions >`_
126- has a ``shell_plus `` management command. When ``prompt_toolkit `` has been
127- installed, it will by default use ``ptpython `` or ``ptipython ``.
128-
129-
130- Using as a library
131- ------------------
132-
133- This is a library which allows you to build highly customizable input prompts.
134- Every step (key bindings, layout, etc..) can be customized.
135-
136- Note that this is work in progress. Many things work, but code is still
137- refactored a lot and APIs can change (they will become even better), so be
138- prepared to handle these changes.
139-
140- Certainly look in the ``examples `` directory to see what is possible.
141-
142- A very simple example:
143-
144- .. code :: python
145-
146- from prompt_toolkit import CommandLineInterface, AbortAction
147- from prompt_toolkit import Exit
88+ if __name__ == ' __main__' :
89+ answer = get_input(' Give me some input: ' )
90+ print (' You said: %s ' % answer)
14891
149- def main ():
150- cli = CommandLineInterface()
92+ For more complex examples, have a look in the examples directory. All examples
93+ are choosen to demonstrate only one thing. Also, don't be afraid to look at the
94+ source code. The implementation of the ``get_input `` function could be a good
95+ start.
15196
152- try :
153- while True :
154- code_obj = cli.read_input(on_exit = AbortAction.RAISE_EXCEPTION )
155- print (' You said: ' + code_obj.text)
15697
157- except Exit: # Quit on Ctrl-D keypress
158- return
98+ Projects using prompt-toolkit
99+ ------------------------------
159100
160- if __name__ == ' __main__' :
161- main()
101+ - `ptpython <http://github.com/jonathanslenders/ptpython/ >`_: Python REPL
102+ - `ptpdb <http://github.com/jonathanslenders/ptpdb/ >`_: Python debugger (pdb replacement)
103+ - `pgcli <http://pgcli.com/ >`_: Postgres Shell
162104
105+ (Want you own project to be listed here? Please create a GitHub issue.)
163106
164- FAQ
165- ---
166107
167- Q
168- The ``Ctrl-S `` forward search doesn't work and freezes my terminal.
169- A
170- Try to run ``stty -ixon `` in your terminal to disable flow control.
108+ Philosophy
109+ ---------
171110
172- Q
173- The ``Meta ``-key doesn't work.
174- A
175- For some terminals you have to enable the Alt-key to act as meta key, but you
176- can also type ``Escape `` before any key instead.
111+ The source code of ``prompt_toolkit `` should be readable, concise and
112+ efficient. We prefer short functions focussing each on one task and for which
113+ the input and output types are clearly specified. We mostly prefer composition
114+ over inheritance, because inheritance can result in too much functionality in
115+ the same object. We prefer immutable objects where possible (objects don't
116+ change after initialisation). Reusability is important. We absolutely refrain
117+ from having a changing global state, it should be possible to have multiple
118+ independent instances of the same code in the same process. The architecture
119+ should be layered: the lower levels operate on primitive operations and data
120+ structures giving -- when correctly combined -- all the possible flexibility;
121+ while at the higher level, there should be a simpler API, ready-to-use and
122+ sufficient for most use cases. Thinking about algorithms and efficiency is
123+ important, but avoid premature optimization.
177124
178125
179126Special thanks to
180127-----------------
181128
182129- `Pygments <http://pygments.org/ >`_: Syntax highlighter.
183- - `Jedi <http://jedi.jedidjah.ch/en/latest/ >`_: Autocompletion library.
184- - `Docopt <http://docopt.org/ >`_: Command-line interface description language.
185130- `wcwidth <https://github.com/jquast/wcwidth >`_: Determine columns needed for a wide characters.
186131
187132.. |Build Status | image :: https://api.travis-ci.org/jonathanslenders/python-prompt-toolkit.svg?branch=master
0 commit comments