1"""
2Usage information for QtConsole
3"""
4
5# Copyright (c) Jupyter Development Team.
6# Distributed under the terms of the Modified BSD License.
7
8
9gui_reference = """\
10=====================
11The Jupyter QtConsole
12=====================
13
14This console is designed to emulate the look, feel and workflow of a terminal
15environment. Beyond this basic design, the console also implements
16functionality not currently found in most terminal emulators. Some examples of
17these console enhancements are inline syntax highlighting, multiline editing,
18inline graphics, and others.
19
20This quick reference document contains the basic information you'll need to
21know to make the most efficient use of it.  For the various command line
22options available at startup, type ``jupyter qtconsole --help`` at the command
23line.
24
25
26Multiline editing
27=================
28
29The graphical console is capable of true multiline editing, but it also tries
30to behave intuitively like a terminal when possible.  If you are used to
31IPython's old terminal behavior, you should find the transition painless. If
32you learn to use a few basic keybindings, the console provides even greater
33efficiency.
34
35For single expressions or indented blocks, the console behaves almost like the
36IPython terminal: single expressions are immediately evaluated, and indented
37blocks are evaluated once a single blank line is entered::
38
39    In [1]: print ("Hello Jupyter!")  # Enter was pressed at the end of the line
40    Hello Jupyter!
41
42    In [2]: for num in range(10):
43       ...:     print(num)
44       ...:
45    0 1 2 3 4 5 6 7 8 9
46
47If you want to enter more than one expression in a single input block
48(something not possible in the terminal), you can use ``Control-Enter`` at the
49end of your first line instead of ``Enter``.  At that point the console goes
50into 'cell mode' and even if your inputs are not indented, it will continue
51accepting lines until either you enter an extra blank line or
52you hit ``Shift-Enter`` (the key binding that forces execution).  When a
53multiline cell is entered, the console analyzes it and executes its code producing
54an ``Out[n]`` prompt only for the last expression in it, while the rest of the
55cell is executed as if it was a script.  An example should clarify this::
56
57    In [3]: x=1  # Hit Ctrl-Enter here
58       ...: y=2  # from now on, regular Enter is sufficient
59       ...: z=3
60       ...: x**2  # This does *not* produce an Out[] value
61       ...: x+y+z  # Only the last expression does
62       ...:
63    Out[3]: 6
64
65The behavior where an extra blank line forces execution is only active if you
66are actually typing at the keyboard each line, and is meant to make it mimic
67the IPython terminal behavior.  If you paste a long chunk of input (for example
68a long script copied form an editor or web browser), it can contain arbitrarily
69many intermediate blank lines and they won't cause any problems.  As always,
70you can then make it execute by appending a blank line *at the end* or hitting
71``Shift-Enter`` anywhere within the cell.
72
73With the up arrow key, you can retrieve previous blocks of input that contain
74multiple lines.  You can move inside of a multiline cell like you would in any
75text editor.  When you want it executed, the simplest thing to do is to hit the
76force execution key, ``Shift-Enter`` (though you can also navigate to the end
77and append a blank line by using ``Enter`` twice).
78
79If you are editing a multiline cell and accidentally navigate out of it using the
80up or down arrow keys, the console clears the cell and replaces it with the
81contents of the cell which the up or down arrow key stopped on.  If you wish to
82to undo this action,  perhaps because of an accidental keypress, use the Undo
83keybinding, ``Control-z``, to restore the original cell.
84
85
86Key bindings
87============
88
89The Jupyter QtConsole supports most of the basic Emacs line-oriented keybindings,
90in addition to some of its own.
91
92The keybindings themselves are:
93
94- ``Enter``: insert new line (may cause execution, see above).
95- ``Ctrl-Enter``: *force* new line, *never* causes execution.
96- ``Shift-Enter``: *force* execution regardless of where cursor is, no newline added.
97- ``Up``: step backwards through the history.
98- ``Down``: step forwards through the history.
99- ``Shift-Up``: search backwards through the history (like ``Control-r`` in bash).
100- ``Shift-Down``: search forwards through the history.
101- ``Control-c``: copy highlighted text to clipboard (prompts are automatically stripped).
102- ``Control-Shift-c``: copy highlighted text to clipboard (prompts are not stripped).
103- ``Control-v``: paste text from clipboard.
104- ``Control-z``: undo (retrieves lost text if you move out of a cell with the arrows).
105- ``Control-Shift-z``: redo.
106- ``Control-o``: move to 'other' area, between pager and terminal.
107- ``Control-l``: clear terminal.
108- ``Control-a``: go to beginning of line.
109- ``Control-e``: go to end of line.
110- ``Control-u``: kill from cursor to the begining of the line.
111- ``Control-k``: kill from cursor to the end of the line.
112- ``Control-y``: yank (paste)
113- ``Control-p``: previous line (like up arrow)
114- ``Control-n``: next line (like down arrow)
115- ``Control-f``: forward (like right arrow)
116- ``Control-b``: back (like left arrow)
117- ``Control-d``: delete next character, or exits if input is empty
118- ``Alt-<``: move to the beginning of the input region.
119- ``alt->``: move to the end of the input region.
120- ``Alt-d``: delete next word.
121- ``Alt-Backspace``: delete previous word.
122- ``Control-.``: force a kernel restart (a confirmation dialog appears).
123- ``Control-+``: increase font size.
124- ``Control--``: decrease font size.
125- ``Control-Alt-Space``: toggle full screen. (Command-Control-Space on Mac OS X)
126
127The pager
128=========
129
130The Jupyter QtConsole will show long blocks of text from many sources using a
131built-in pager. You can control where this pager appears with the ``--paging``
132command-line flag:
133
134- ``inside`` [default]: the pager is overlaid on top of the main terminal. You
135  must quit the pager to get back to the terminal (similar to how a pager such
136  as ``less`` or ``more`` pagers behave).
137
138- ``vsplit``: the console is made double height, and the pager appears on the
139  bottom area when needed.  You can view its contents while using the terminal.
140
141- ``hsplit``: the console is made double width, and the pager appears on the
142  right area when needed.  You can view its contents while using the terminal.
143
144- ``none``: the console displays output without paging.
145
146If you use the vertical or horizontal paging modes, you can navigate between
147terminal and pager as follows:
148
149- Tab key: goes from pager to terminal (but not the other way around).
150- Control-o: goes from one to another always.
151- Mouse: click on either.
152
153In all cases, the ``q`` or ``Escape`` keys quit the pager (when used with the
154focus on the pager area).
155
156Running subprocesses
157====================
158
159When running a subprocess from the kernel, you can not interact with it as if
160it was running in a terminal.  So anything that invokes a pager or expects
161you to type input into it will block and hang (you can kill it with ``Control-C``).
162
163The console can use magics provided by the IPython kernel. These magics include
164``%less`` to page files (aliased to ``%more``),
165``%clear`` to clear the terminal, and ``%man`` on Linux/OSX.  These cover the
166most common commands you'd want to call in your subshell and that would cause
167problems if invoked via ``!cmd``, but you need to be aware of this limitation.
168
169Display
170=======
171
172For example, if using the IPython kernel, there are functions available for
173object display:
174
175
176    In [4]: from IPython.display import display
177
178    In [5]: from IPython.display import display_png, display_svg
179
180Python objects can simply be passed to these functions and the appropriate
181representations will be displayed in the console as long as the objects know
182how to compute those representations. The easiest way of teaching objects how
183to format themselves in various representations is to define special methods
184such as: ``_repr_svg_`` and ``_repr_png_``. IPython's display formatters
185can also be given custom formatter functions for various types::
186
187    In [6]: ip = get_ipython()
188
189    In [7]: png_formatter = ip.display_formatter.formatters['image/png']
190
191    In [8]: png_formatter.for_type(Foo, foo_to_png)
192
193For further details, see ``IPython.core.formatters``.
194"""
195