##// END OF EJS Templates
Merge pull request #9470 from Carreau/t42-ptshell...
Thomas Kluyver -
r22336:ca1df62b merge
parent child Browse files
Show More
@@ -13,7 +13,7 b' from IPython.core.interactiveshell import InteractiveShell'
13 from IPython.utils.py3compat import PY3, cast_unicode_py2, input
13 from IPython.utils.py3compat import PY3, cast_unicode_py2, input
14 from IPython.utils.terminal import toggle_set_term_title, set_term_title
14 from IPython.utils.terminal import toggle_set_term_title, set_term_title
15 from IPython.utils.process import abbrev_cwd
15 from IPython.utils.process import abbrev_cwd
16 from traitlets import Bool, CBool, Unicode, Dict, Integer
16 from traitlets import Bool, CBool, Unicode, Dict, Integer, observe
17
17
18 from prompt_toolkit.completion import Completer, Completion
18 from prompt_toolkit.completion import Completer, Completion
19 from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER, EditingMode
19 from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER, EditingMode
@@ -91,7 +91,7 b' class IPythonPTLexer(Lexer):'
91 class TerminalInteractiveShell(InteractiveShell):
91 class TerminalInteractiveShell(InteractiveShell):
92 colors_force = True
92 colors_force = True
93
93
94 space_for_menu = Integer(6, config=True, help='Number of line at the bottom of the screen '
94 space_for_menu = Integer(6).tag(config=True, help='Number of line at the bottom of the screen '
95 'to reserve for the completion menu')
95 'to reserve for the completion menu')
96
96
97 def _space_for_menu_changed(self, old, new):
97 def _space_for_menu_changed(self, old, new):
@@ -99,47 +99,48 b' class TerminalInteractiveShell(InteractiveShell):'
99
99
100 pt_cli = None
100 pt_cli = None
101
101
102 autoedit_syntax = CBool(False, config=True,
102 autoedit_syntax = CBool(False).tag(config=True,
103 help="auto editing of files with syntax errors.")
103 help="auto editing of files with syntax errors.")
104
104
105 confirm_exit = CBool(True, config=True,
105 confirm_exit = CBool(True).tag(config=True,
106 help="""
106 help="""
107 Set to confirm when you try to exit IPython with an EOF (Control-D
107 Set to confirm when you try to exit IPython with an EOF (Control-D
108 in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
108 in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
109 you can force a direct exit without any confirmation.""",
109 you can force a direct exit without any confirmation.""",
110 )
110 )
111 editing_mode = Unicode('emacs', config=True,
111 editing_mode = Unicode('emacs').tag(config=True,
112 help="Shortcut style to use at the prompt. 'vi' or 'emacs'.",
112 help="Shortcut style to use at the prompt. 'vi' or 'emacs'.",
113 )
113 )
114
114
115 mouse_support = Bool(False, config=True,
115 mouse_support = Bool(False).tag(config=True,
116 help="Enable mouse support in the prompt"
116 help="Enable mouse support in the prompt"
117 )
117 )
118
118
119 highlighting_style = Unicode('default', config=True,
119 highlighting_style = Unicode('default').tag(config=True,
120 help="The name of a Pygments style to use for syntax highlighting: \n %s" % ', '.join(get_all_styles())
120 help="The name of a Pygments style to use for syntax highlighting: \n %s" % ', '.join(get_all_styles())
121 )
121 )
122
122
123 def _highlighting_style_changed(self, old, new):
123 def _highlighting_style_changed(self, old, new):
124 self._style = self._make_style_from_name(self.highlighting_style)
124 self._style = self._make_style_from_name(self.highlighting_style)
125
125
126 highlighting_style_overrides = Dict(config=True,
126 highlighting_style_overrides = Dict().tag(config=True,
127 help="Override highlighting format for specific tokens"
127 help="Override highlighting format for specific tokens"
128 )
128 )
129
129
130 editor = Unicode(get_default_editor(), config=True,
130 editor = Unicode(get_default_editor()).tag(config=True,
131 help="Set the editor used by IPython (default to $EDITOR/vi/notepad)."
131 help="Set the editor used by IPython (default to $EDITOR/vi/notepad)."
132 )
132 )
133
133
134 term_title = Bool(True, config=True,
134 term_title = Bool(True).tag(config=True,
135 help="Automatically set the terminal title"
135 help="Automatically set the terminal title"
136 )
136 )
137
137
138 display_completions_in_columns = Bool(False, config=True,
138 display_completions_in_columns = Bool(False).tag(config=True,
139 help="Display a multi column completion menu.",
139 help="Display a multi column completion menu.",
140 )
140 )
141
141
142 def _term_title_changed(self, name, new_value):
142 @observe('term_title')
143 def _term_title_changed(self, change):
143 self.init_term_title()
144 self.init_term_title()
144
145
145 def init_term_title(self):
146 def init_term_title(self):
@@ -195,11 +196,11 b' class TerminalInteractiveShell(InteractiveShell):'
195 b.insert_text('\n' + (' ' * (indent or 0)))
196 b.insert_text('\n' + (' ' * (indent or 0)))
196
197
197 @kbmanager.registry.add_binding(Keys.ControlC, filter=HasFocus(DEFAULT_BUFFER))
198 @kbmanager.registry.add_binding(Keys.ControlC, filter=HasFocus(DEFAULT_BUFFER))
198 def _(event):
199 def _reset_buffer(event):
199 event.current_buffer.reset()
200 event.current_buffer.reset()
200
201
201 @kbmanager.registry.add_binding(Keys.ControlC, filter=HasFocus(SEARCH_BUFFER))
202 @kbmanager.registry.add_binding(Keys.ControlC, filter=HasFocus(SEARCH_BUFFER))
202 def _(event):
203 def _reset_search_buffer(event):
203 if event.current_buffer.document.text:
204 if event.current_buffer.document.text:
204 event.current_buffer.reset()
205 event.current_buffer.reset()
205 else:
206 else:
@@ -208,7 +209,7 b' class TerminalInteractiveShell(InteractiveShell):'
208 supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP'))
209 supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP'))
209
210
210 @kbmanager.registry.add_binding(Keys.ControlZ, filter=supports_suspend)
211 @kbmanager.registry.add_binding(Keys.ControlZ, filter=supports_suspend)
211 def _(event):
212 def _suspend_to_bg(event):
212 event.cli.suspend_to_background()
213 event.cli.suspend_to_background()
213
214
214 @Condition
215 @Condition
@@ -223,13 +224,13 b' class TerminalInteractiveShell(InteractiveShell):'
223 & insert_mode
224 & insert_mode
224 & cursor_in_leading_ws
225 & cursor_in_leading_ws
225 ))
226 ))
226 def _(event):
227 def _indent_buffer(event):
227 event.current_buffer.insert_text(' ' * 4)
228 event.current_buffer.insert_text(' ' * 4)
228
229
229 # Pre-populate history from IPython's history database
230 # Pre-populate history from IPython's history database
230 history = InMemoryHistory()
231 history = InMemoryHistory()
231 last_cell = u""
232 last_cell = u""
232 for _, _, cell in self.history_manager.get_tail(self.history_load_length,
233 for __, ___, cell in self.history_manager.get_tail(self.history_load_length,
233 include_latest=True):
234 include_latest=True):
234 # Ignore blank lines and consecutive duplicates
235 # Ignore blank lines and consecutive duplicates
235 cell = cell.rstrip()
236 cell = cell.rstrip()
General Comments 0
You need to be logged in to leave comments. Login now