Skip to content

Commit 2997809

Browse files
Moving ptpython code out of the prompt-toolkit repository.
We have a separate ptpython repository now.
1 parent 10ee932 commit 2997809

25 files changed

+77
-2489
lines changed

README.rst

Lines changed: 54 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,45 @@ 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
11-
more than that.
9+
Looking for ptpython, the Python REPL??
10+
***************************************
1211

13-
Features:
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``, but it can be
28+
much more than that.
29+
30+
Some features:
1431

1532
- Pure Python.
1633
- Syntax highlighting of the input while typing. (For instance, with a Pygments lexer.)
1734
- Multi-line input editing.
1835
- Advanced code completion.
1936
- Both Emacs and Vi key bindings. (Similar to readline.)
2037
- Reverse and forward incremental search.
21-
- Both Python 3 and Python 2.7 support.
38+
- Runs on all Python versions from 2.6 up to 3.4.
2239
- Works well with Unicode double width characters. (Chinese input.)
2340
- Selecting text for copy/paste. (Both Emacs and Vi style.)
41+
- Multiple input buffers.
2442
- No global state.
2543
- Code written with love.
2644
- Runs on Linux, OS X, OpenBSD and Windows systems.
45+
- Lightweight, the only dependencies are Pygments, six and wcwidth.
2746

2847

2948
Feel free to create tickets for bugs and feature requests, and create pull
@@ -38,9 +57,6 @@ different event loop (``WaitForMultipleObjects`` instead of ``select``), and
3857
another input and output system. (Win32 APIs instead of pseudo-terminals and
3958
VT100.)
4059

41-
.. image :: docs/images/ptpython-windows.png
42-
43-
4460
That should work fine, however the library is currently much more tested on
4561
Linux and Mac os X systems. So, if you find any bugs in the Windows
4662
implementation, or you have an idea how to make the experience better, please
@@ -59,129 +75,54 @@ Installation
5975
pip install prompt-toolkit
6076

6177

62-
The Python repl
63-
---------------
64-
65-
Run ``ptpython`` to get an interactive Python prompt with syntax highlighting,
66-
code completion, etc...
67-
68-
.. image :: docs/images/ptpython-screenshot.png
78+
Example
79+
-------
6980

70-
If you prefer to have Vi key bindings (which currently are more completely
71-
implemented than the Emacs bindings), run ``ptpython --vi``.
81+
The most simple example of the library would look like this. For more complex
82+
examples, see the example directory.
7283

73-
If you want to embed the REPL inside your application at one point, do:
7484

7585
.. code:: python
7686
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.)
101-
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.
87+
from prompt_toolkit.contrib.shortcuts import get_input
10888
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
148-
149-
def main():
150-
cli = CommandLineInterface()
89+
if __name__ == '__main__':
90+
answer = get_input('Give me some input: ')
91+
print('You said: %s' % answer)
15192
152-
try:
153-
while True:
154-
code_obj = cli.read_input(on_exit=AbortAction.RAISE_EXCEPTION)
155-
print('You said: ' + code_obj.text)
15693
157-
except Exit: # Quit on Ctrl-D keypress
158-
return
94+
Projects using prompt-toolkit
95+
------------------------------
15996

160-
if __name__ == '__main__':
161-
main()
97+
- `ptpython <http://github.com/jonathanslenders/ptpython/>`_: Python REPL
98+
- `ptpdb <http://github.com/jonathanslenders/ptpdb/>`_: Python debugger (pdb replacement)
99+
- `pgcli <http://pgcli.com/>`_: Postgres Shell
162100

101+
(Want you own project to be listed here? Please create a GitHub issue.)
163102

164-
FAQ
165-
---
166103

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.
104+
Philosophy
105+
---------
171106

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.
107+
The source code of ``prompt_toolkit`` should be readable, concise and
108+
efficient. We prefer short functions focussing each on one task and for which
109+
the input and output types are clearly specified. We mostly prefer composition
110+
over inheritance, because inheritance can result in too much functionality in
111+
the same object. We prefer immutable objects where possible (objects don't
112+
change after initialisation). Reusability is important. We absolutely refrain
113+
from having a changing global state, it should be possible to have multiple
114+
independent instances of the same code in the same process. The architecture
115+
should be layered: the lower levels operate on primitive operations and data
116+
structures giving -- when correctly combined -- all the possible flexibility;
117+
while at the higher level, there should be a simpler API, ready-to-use and
118+
sufficient for most use cases. Thinking about algorithms and efficiency is
119+
important, but avoid premature optimization.
177120

178121

179122
Special thanks to
180123
-----------------
181124

182125
- `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.
185126
- `wcwidth <https://github.com/jquast/wcwidth>`_: Determine columns needed for a wide characters.
186127

187128
.. |Build Status| image:: https://api.travis-ci.org/jonathanslenders/python-prompt-toolkit.svg?branch=master
-42.2 KB
Binary file not shown.
-20.6 KB
Binary file not shown.

docs/images/ptpython-windows.png

-13.8 KB
Binary file not shown.

docs/images/ptpython.png

26.5 KB
Loading

examples/pdb-example.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

examples/python-embed.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

examples/python-input.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

prompt_toolkit/contrib/entry_points/__init__.py

Whitespace-only changes.

prompt_toolkit/contrib/entry_points/ptipython.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)