##// END OF EJS Templates
Merge pull request #9677 from takluyver/docs-5-polish...
Min RK -
r22617:771e4b92 merge
parent child Browse files
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -250,7 +250,7 b' class InteractiveShell(SingletonConfigurable):'
250 ).tag(config=True)
250 ).tag(config=True)
251 colors = CaselessStrEnum(('Neutral', 'NoColor','LightBG','Linux'),
251 colors = CaselessStrEnum(('Neutral', 'NoColor','LightBG','Linux'),
252 default_value='Neutral',
252 default_value='Neutral',
253 help="Set the color scheme (NoColor, Linux, or LightBG)."
253 help="Set the color scheme (NoColor, Neutral, Linux, or LightBG)."
254 ).tag(config=True)
254 ).tag(config=True)
255 colors_force = Bool(False, help=
255 colors_force = Bool(False, help=
256 """
256 """
@@ -15,6 +15,12 b' backends = ['
15 'osx',
15 'osx',
16 ]
16 ]
17
17
18 registered = {}
19
20 def register(name, inputhook):
21 """Register the function *inputhook* as an event loop integration."""
22 registered[name] = inputhook
23
18 class UnknownBackend(KeyError):
24 class UnknownBackend(KeyError):
19 def __init__(self, name):
25 def __init__(self, name):
20 self.name = name
26 self.name = name
@@ -22,9 +28,12 b' class UnknownBackend(KeyError):'
22 def __str__(self):
28 def __str__(self):
23 return ("No event loop integration for {!r}. "
29 return ("No event loop integration for {!r}. "
24 "Supported event loops are: {}").format(self.name,
30 "Supported event loops are: {}").format(self.name,
25 ', '.join(backends))
31 ', '.join(backends + sorted(registered)))
26
32
27 def get_inputhook_func(gui):
33 def get_inputhook_func(gui):
34 if gui in registered:
35 return registered[gui]
36
28 if gui not in backends:
37 if gui not in backends:
29 raise UnknownBackend(gui)
38 raise UnknownBackend(gui)
30
39
@@ -11,7 +11,8 b" generated = join(options, 'config-generated.txt')"
11
11
12
12
13 def write_doc(name, title, app, preamble=None):
13 def write_doc(name, title, app, preamble=None):
14 with open(generated, 'a') as f:
14 filename = join(options, name+'.rst')
15 with open(filename, 'w') as f:
15 f.write(title + '\n')
16 f.write(title + '\n')
16 f.write(('=' * len(title)) + '\n')
17 f.write(('=' * len(title)) + '\n')
17 f.write('\n')
18 f.write('\n')
@@ -21,7 +22,7 b' def write_doc(name, title, app, preamble=None):'
21
22
22
23
23 if __name__ == '__main__':
24 if __name__ == '__main__':
24 # create empty file
25 # Touch this file for the make target
25 with open(generated, 'w'):
26 with open(generated, 'w'):
26 pass
27 pass
27
28
@@ -2,89 +2,85 b''
2 Specific config details
2 Specific config details
3 =======================
3 =======================
4
4
5 .. _custom_prompts:
6
7 Custom Prompts
8 ==============
9
10 .. versionchanged:: 5.0
11
12 From IPython 5, prompts are produced as a list of Pygments tokens, which are
13 tuples of (token_type, text). You can customise prompts by writing a method
14 which generates a list of tokens.
15
16 There are four kinds of prompt:
17
18 * The **in** prompt is shown before the first line of input
19 (default like ``In [1]:``).
20 * The **continuation** prompt is shown before further lines of input
21 (default like ``...:``).
22 * The **rewrite** prompt is shown to highlight how special syntax has been
23 interpreted (default like ``----->``).
24 * The **out** prompt is shown before the result from evaluating the input
25 (default like ``Out[1]:``).
26
27 Custom prompts are supplied together as a class. If you want to customise only
28 some of the prompts, inherit from :class:`IPython.terminal.prompts.Prompts`,
29 which defines the defaults. The required interface is like this:
30
31 .. class:: MyPrompts(shell)
32
33 Prompt style definition. *shell* is a reference to the
34 :class:`~.TerminalInteractiveShell` instance.
35
36 .. method:: in_prompt_tokens(cli=None)
37 continuation_prompt_tokens(self, cli=None, width=None)
38 rewrite_prompt_tokens()
39 out_prompt_tokens()
40
41 Return the respective prompts as lists of ``(token_type, text)`` tuples.
42
43 For continuation prompts, *width* is an integer representing the width of
44 the prompt area in terminal columns.
45
46 *cli*, where used, is the prompt_toolkit ``CommandLineInterface`` instance.
47 This is mainly for compatibility with the API prompt_toolkit expects.
48
49 Inside IPython or in a startup script, you can use a custom prompts class
50 by setting ``get_ipython().prompts`` to an *instance* of the class.
51 In configuration, ``TerminalInteractiveShell.prompts_class`` may be set to
52 either the class object, or a string of its full importable name.
53
5 .. _termcolour:
54 .. _termcolour:
6
55
7 Terminal Colors
56 Terminal Colors
8 ===============
57 ===============
9
58
10 The default IPython configuration has most bells and whistles turned on
59 .. versionchanged:: 5.0
11 (they're pretty safe). But there's one that may cause problems on some
60
12 systems: the use of color on screen for displaying information. This is
61 There are two main configuration options controlling colours.
13 very useful, since IPython can show prompts and exception tracebacks
62
14 with various colors, display syntax-highlighted source code, and in
63 ``InteractiveShell.colors`` sets the colour of tracebacks and object info (the
15 general make it easier to visually parse information.
64 output from e.g. ``zip?``). It may also affect other things if the option below
16
65 is set to ``'legacy'``. It has four case-insensitive values:
17 The following terminals seem to handle the color sequences fine:
66 ``'nocolor', 'neutral', 'linux', 'lightbg'``. The default is *neutral*, which
18
67 should be legible on either dark or light terminal backgrounds. *linux* is
19 * Linux main text console, KDE Konsole, Gnome Terminal, E-term,
68 optimised for dark backgrounds and *lightbg* for light ones.
20 rxvt, xterm.
69
21 * CDE terminal (tested under Solaris). This one boldfaces light colors.
70 ``TerminalInteractiveShell.highlight_style`` determines prompt colours and syntax
22 * (X)Emacs buffers. See the :ref:`emacs` section for more details on
71 highlighting. It takes the name of a Pygments style as a string, or the special
23 using IPython with (X)Emacs.
72 value ``'legacy'`` to pick a style in accordance with ``InteractiveShell.colors``.
24 * A Windows (XP/2k) CygWin shell. Although some users have reported
25 problems; it is not clear whether there is an issue for everyone
26 or only under specific configurations. If you have full color
27 support under cygwin, please post to the IPython mailing list so
28 this issue can be resolved for all users.
29
30 These have shown problems:
31
32 * Windows command prompt in WinXP/2k logged into a Linux machine via
33 telnet or ssh.
34 * Windows native command prompt in WinXP/2k, without Gary Bishop's
35 extensions. Once Gary's readline library is installed, the normal
36 WinXP/2k command prompt works perfectly.
37
38 IPython uses colors for various groups of things that may be
39 controlled by different configuration options: prompts, tracebacks, "as
40 you type" in the terminal, and the object introspection system which
41 passes large sets of data through a pager. There are various way to
42 change the colors.
43
44 We can distinguish the coloration into 2 main categories:
45
46 - The one that affects only the terminal client.
47 - The ones that also affect clients connected through the Jupyter
48 protocol.
49
50 Traceback, debugger, and pager are highlighted kernel-side so they fall
51 into the second category. For historical reasons they are often
52 governed by a ``colors`` attribute or configuration option that can
53 take one of 3 case insensitive values: ``NoColors``, ``Linux`` and
54 ``LightBG``.
55
56 Colors that affect only the terminal client are governed mainly by
57 ``TerminalInteractiveShell.highlight_style`` taking the name of a
58 ``Pygments`` style.
59
60 As of IPython 5.0 the color configuration works as follows:
61
62 - by default, ``TerminalInteractiveShell.highlight_style`` is set to
63 ``legacy`` which **trys to** emulate the colors of IPython pre 5.0
64 and respect the ``.color`` configuration option.
65 The emulation is an approximation of the current version of Pygments
66 (2.1) and only supports extended ANSI escape sequence, hence the
67 theme cannot adapt to your terminal custom mapping if you have
68 one.
69
70 The last extra difference being that the "as you type" coloration
71 is present using the theme "default" if `color` is `LightBG`, and
72 using the theme "monokai" if `Linux`.
73
74 - if ``TerminalInteractiveShell.highlight_style`` is set to any other
75 themes, this theme is used for "as you type" highlighting. The
76 prompt highlighting is then governed by
77 ``--TerminalInteractiveShell.highlighting_style_overrides``
78
79 As a summary, by default IPython 5.0 should mostly behave unchanged
80 from IPython 4.x and before. Use
81 ``TerminalInteractiveShell.highlight_style`` and
82 ``--TerminalInteractiveShell.highlighting_style_overrides`` for extra
83 flexibility.
84
85 With default configuration `--colors=[nocolors|linux|ightbg]` as well
86 as the `%colors` magic should behave identically as before.
87
73
74 You can see the Pygments styles available on your system by running::
75
76 import pygments
77 list(pygments.styles.get_all_styles())
78
79 Additionally, ``TerminalInteractiveShell.highlight_style_overrides`` can override
80 specific styles in the highlighting. It should be a dictionary mapping Pygments
81 token types to strings defining the style. See `Pygments' documentation
82 <http://pygments.org/docs/styles/#creating-own-styles>`__ for the language used
83 to define styles.
88
84
89 Colors in the pager
85 Colors in the pager
90 -------------------
86 -------------------
@@ -98,9 +94,6 b' To configure your default pager to allow these:'
98 properly interpret control sequences, which is how color
94 properly interpret control sequences, which is how color
99 information is given to your terminal.
95 information is given to your terminal.
100
96
101
102
103
104 .. _editors:
97 .. _editors:
105
98
106 Editor configuration
99 Editor configuration
@@ -13,47 +13,39 b' so different steps are needed to integrate with each.'
13 Event loops in the terminal
13 Event loops in the terminal
14 ---------------------------
14 ---------------------------
15
15
16 In the terminal, IPython uses a blocking Python function to wait for user input.
16 .. versionchanged:: 5.0
17 However, the Python C API provides a hook, :c:func:`PyOS_InputHook`, which is
17
18 called frequently while waiting for input. This can be set to a function which
18 There is a new API for event loop integration using prompt_toolkit.
19 briefly runs the event loop and then returns.
19
20
20 In the terminal, IPython uses prompt_toolkit to prompt the user for input.
21 IPython provides Python level wrappers for setting and resetting this hook. To
21 prompt_toolkit provides hooks to integrate with an external event loop.
22 use them, subclass :class:`IPython.lib.inputhook.InputHookBase`, and define
22
23 an ``enable(app=None)`` method, which initialises the event loop and calls
23 To integrate an event loop, define a function which runs the GUI event loop
24 ``self.manager.set_inputhook(f)`` with a function which will briefly run the
24 until there is input waiting for prompt_toolkit to process. There are two ways
25 event loop before exiting. Decorate the class with a call to
25 to detect this condition::
26 :func:`IPython.lib.inputhook.register`::
26
27
27 # Polling for input.
28 from IPython.lib.inputhook import register, InputHookBase
28 def inputhook(context):
29
29 while not context.input_is_ready():
30 @register('clutter')
30 # Replace this with the appropriate call for the event loop:
31 class ClutterInputHook(InputHookBase):
31 iterate_loop_once()
32 def enable(self, app=None):
32
33 self.manager.set_inputhook(inputhook_clutter)
33 # Using a file descriptor to notify the event loop to stop.
34
34 def inputhook2(context):
35 You can also optionally define a ``disable()`` method, taking no arguments, if
35 fd = context.fileno()
36 there are extra steps needed to clean up. IPython will take care of resetting
36 # Replace the functions below with those for the event loop.
37 the hook, whether or not you provide a disable method.
37 add_file_reader(fd, callback=stop_the_loop)
38
38 run_the_loop()
39 The simplest way to define the hook function is just to run one iteration of the
39
40 event loop, or to run until no events are pending. Most event loops provide some
40 Once you have defined this function, register it with IPython:
41 mechanism to do one of these things. However, the GUI may lag slightly,
41
42 because the hook is only called every 0.1 seconds. Alternatively, the hook can
42 .. currentmodule:: IPython.terminal.pt_inputhooks
43 keep running the event loop until there is input ready on stdin. IPython
43
44 provides a function to facilitate this:
44 .. function:: register(name, inputhook)
45
45
46 .. currentmodule:: IPython.lib.inputhook
46 Register the function *inputhook* as the event loop integration for the
47
47 GUI *name*. If ``name='foo'``, then the user can enable this integration
48 .. function:: stdin_ready()
48 by running ``%gui foo``.
49
50 Returns True if there is something ready to read on stdin.
51
52 If this is the case, the hook function should return immediately.
53
54 This is implemented for Windows and POSIX systems - on other platforms, it
55 always returns True, so that the hook always gives Python a chance to check
56 for input.
57
49
58
50
59 Event loops in the kernel
51 Event loops in the kernel
@@ -6,4 +6,7 b' Any of the options listed here can be set in config files, at the'
6 command line, or from inside IPython. See :ref:`setting_config` for
6 command line, or from inside IPython. See :ref:`setting_config` for
7 details.
7 details.
8
8
9 .. include:: config-generated.txt
9 .. toctree::
10
11 terminal
12 kernel
@@ -5,71 +5,72 b''
5 IPython 5.0
5 IPython 5.0
6 ===========
6 ===========
7
7
8 Released June, 2016
8 Released July, 2016
9
9
10 IPython 5.0 now uses ``prompt-toolkit`` for the command line interface, thus
10 New terminal interface
11 allowing real multi-line editing and syntactic coloration as you type.
11 ----------------------
12
12
13 IPython 5 features a major upgrade to the terminal interface, bringing live
14 syntax highlighting as you type, proper multiline editing and multiline paste,
15 and tab completions that don't clutter up your history.
13
16
14 When using IPython as a subprocess, like for emacs inferior-shell, IPython can
17 .. image:: ../_images/ptshell_features.png
15 be started with a ``--simple-prompt`` flag, which will bypass the prompt_toolkit
18 :alt: New terminal interface features
16 input layer. In this mode, prompt color and many other features are
19 :align: center
17 disabled.
20 :target: ../_images/ptshell_features.png
18
21
19 Backwards incompatible changes
22 These features are provided by the Python library `prompt_toolkit
20 ------------------------------
23 <http://python-prompt-toolkit.readthedocs.io/en/stable/>`__, which replaces
21
24 ``readline`` throughout our terminal interface.
22
23 The `install_ext magic` function which was deprecated since 4.0 has now been deleted.
24 You can still distribute and install extensions as packages on PyPI.
25
26 Update IPython event triggering to ensure callback registration and
27 unregistration will only affect the set of callbacks the *next* time that event is
28 triggered. See :ghissue:`9447` and :ghpull:`9453`.
29
30 This is a change to the existing semantics, wherein one callback registering a
31 second callback when triggered for an event would previously be invoked for
32 that same event.
33
34 Integration with pydb has been removed since pydb development has been stopped
35 since 2012, and pydb is not installable from PyPI.
36
37
38
39 Replacement of readline in TerminalInteractiveShell and PDB
40 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41
25
42 IPython 5.0 now uses ``prompt_toolkit``. The
26 Relying on this pure-Python, cross platform module also makes it simpler to
43 ``IPython.terminal.interactiveshell.TerminalInteractiveShell`` now uses
27 install IPython. We have removed dependencies on ``pyreadline`` for Windows and
44 ``prompt_toolkit``. It is an almost complete rewrite, so many settings have
28 ``gnureadline`` for Mac.
45 thus changed or disappeared. The class keep the same name to avoid breaking
46 user configuration for the options with names that are unchanged.
47
29
48 The usage of ``prompt_toolkit`` is accompanied by a complete removal of all
30 Backwards incompatible changes
49 code, using ``readline``. A particular effect of not using `readline` anymore
31 ------------------------------
50 is that `.inputrc` settings are note effective anymore. Options having similar
51 effects have likely been replaced by a configuration option on IPython itself
52 (e.g: vi input mode).
53
54 The `PromptManager` class have been removed, and the prompt machinery simplified.
55 See `TerminalInteractiveShell.prompts` configurable for how to setup your prompts.
56
57 .. note::
58
59 During development and beta cycle, ``TerminalInteractiveShell`` was
60 temporarly moved to ``IPython.terminal.ptshell``.
61
62
63 Most of the above remarks also affect `IPython.core.debugger.Pdb`, the `%debug`
64 and `%pdb` magic which do not use readline anymore either.
65
32
66 The color handling has been slightly changed and is now exposed,
33 - The ``%install_ext`` magic function, deprecated since 4.0, has now been deleted.
67 in particular the colors of prompts and as you type
34 You can distribute and install extensions as packages on PyPI.
68 highlighting can be affected by :
35 - Callbacks registered while an event is being handled will now only be called
69 ``TerminalInteractiveShell.highlight_style``. With default
36 for subsequent events; previously they could be called for the current event.
70 configuration the ``--colors`` flag and ``%colors`` magic behavior
37 Similarly, callbacks removed while handling an event *will* always get that
71 should be mostly unchanged. See the `colors <termcolour>`_ section of
38 event. See :ghissue:`9447` and :ghpull:`9453`.
72 our documentation
39 - Integration with pydb has been removed since pydb development has been stopped
40 since 2012, and pydb is not installable from PyPI.
41 - The ``autoedit_syntax`` option has apparently been broken for many years.
42 It has been removed.
43
44 New terminal interface
45 ~~~~~~~~~~~~~~~~~~~~~~
46
47 The overhaul of the terminal interface will probably cause a range of minor
48 issues for existing users.
49 This is inevitable for such a significant change, and we've done our best to
50 minimise these issues.
51 Some changes that we're aware of, with suggestions on how to handle them:
52
53 IPython no longer uses readline configuration (``~/.inputrc``). We hope that
54 the functionality you want (e.g. vi input mode) will be available by configuring
55 IPython directly (see :doc:`/config/options/terminal`).
56 If something's missing, please file an issue.
57
58 The ``PromptManager`` class has been removed, and the prompt machinery simplified.
59 See :ref:`custom_prompts` to customise prompts with the new machinery.
60
61 :mod:`IPython.core.debugger` now provides a plainer interface.
62 :mod:`IPython.terminal.debugger` contains the terminal debugger using
63 prompt_toolkit.
64
65 There are new options to configure the colours used in syntax highlighting.
66 We have tried to integrate them with our classic ``--colors`` option and
67 ``%colors`` magic, but there's a mismatch in possibilities, so some configurations
68 may produce unexpected results. See :ref:`termcolour` for more information.
69
70 The new interface is not compatible with Emacs 'inferior-shell' feature. To
71 continue using this, add the ``--simple-prompt`` flag to the command Emacs
72 runs. This flag disables most IPython features, relying on Emacs to provide
73 things like tab completion.
73
74
74 Provisional Changes
75 Provisional Changes
75 -------------------
76 -------------------
@@ -116,12 +117,6 b' widgets... As stated above this is nightly experimental feature with a lot of'
116 it.
117 it.
117
118
118
119
119 Removed Feature
120 ---------------
121
122 - ``TerminalInteractiveShell.autoedit_syntax`` Has been broken for many years now
123 apparently. It has been removed.
124
125
120
126 Deprecated Features
121 Deprecated Features
127 -------------------
122 -------------------
General Comments 0
You need to be logged in to leave comments. Login now