usage.py 8.2 KB

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