Skip to content

Commit

Permalink
Add out prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Peter committed Dec 27, 2021
1 parent 82e1074 commit d013603
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
38 changes: 38 additions & 0 deletions spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,44 @@ def test_breakpoint_builtin(ipyconsole, qtbot, tmpdir):
assert 'foo' in control.toPlainText()
assert 'IPdb [1]:' in control.toPlainText()

def test_pdb_out(ipyconsole, qtbot):
"""Test that browsing command history is working while debugging."""
shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)

# Give focus to the widget that's going to receive clicks
control = ipyconsole.get_widget().get_focus_widget()
control.setFocus()

# Enter debugging mode
with qtbot.waitSignal(shell.executed):
shell.execute('%debug print()')

# Generate some output
with qtbot.waitSignal(shell.executed):
shell.pdb_execute('a = 12 + 1; a')

assert "[1]: 13" in control.toPlainText()

# Generate hide output
with qtbot.waitSignal(shell.executed):
shell.pdb_execute('a = 14 + 1; a;')

assert "[2]: 15" not in control.toPlainText()

# Multiline
with qtbot.waitSignal(shell.executed):
shell.pdb_execute('a = 16 + 1\na')

assert "[3]: 17" in control.toPlainText()

with qtbot.waitSignal(shell.executed):
shell.pdb_execute('a = 18 + 1\na;')

assert "[4]: 19" not in control.toPlainText()
assert "IPdb [4]:" in control.toPlainText()


@flaky(max_runs=3)
@pytest.mark.auto_backend
Expand Down
23 changes: 23 additions & 0 deletions spyder/plugins/ipythonconsole/widgets/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,21 @@ def set_pdb_state(self, pdb_state):
if pdb_state is not None and isinstance(pdb_state, dict):
self.refresh_from_pdb(pdb_state)

def show_pdb_output(self, text):
"""Show Pdb output."""
self._append_plain_text(self.output_sep, before_prompt=True)
prompt = self._current_out_prompt()
self._append_html(
'<span class="out-prompt">%s</span>' % prompt,
before_prompt=True
)
# If the repr is multiline, make sure we start on a new line,
# so that its lines are aligned.
if "\n" in text and not self.output_sep.endswith("\n"):
self._append_plain_text('\n', before_prompt=True)
self._append_plain_text(text + self.output_sep2, before_prompt=True)
self._append_plain_text('\n', before_prompt=True)

def get_pdb_last_step(self):
"""Get last pdb step retrieved from a Pdb session."""
fname, lineno = self._pdb_frame_loc
Expand Down Expand Up @@ -471,6 +486,14 @@ def _current_prompt(self):
prompt = "({})".format(prompt)
return prompt + ": "

def _current_out_prompt(self):
"""Get current out prompt."""
prompt = "Out\u00A0\u00A0[{}]".format(self._pdb_history_input_number)
for i in range(self._pdb_in_loop - 1):
# Add recursive debugger prompt
prompt = "({})".format(prompt)
return prompt + ": "

def _handle_kernel_info_reply(self, rep):
"""Handle kernel info replies."""
super(DebuggingWidget, self)._handle_kernel_info_reply(rep)
Expand Down
1 change: 1 addition & 0 deletions spyder/plugins/ipythonconsole/widgets/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def __init__(self, ipyclient, additional_options, interpreter_versions,
handlers.update({
'pdb_state': self.set_pdb_state,
'pdb_execute': self.pdb_execute,
'show_pdb_output': self.show_pdb_output,
'get_pdb_settings': self.get_pdb_settings,
'set_debug_state': self.set_debug_state,
'update_syspath': self.update_syspath,
Expand Down

0 comments on commit d013603

Please sign in to comment.