##// END OF EJS Templates
Improve Qt console's placement of text appended before a prompt.
epatters -
Show More
@@ -195,6 +195,7 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
195 195
196 196 # Initialize protected variables. Some variables contain useful state
197 197 # information for subclasses; they should be considered read-only.
198 self._append_before_prompt_pos = 0
198 199 self._ansi_processor = QtAnsiCodeProcessor()
199 200 self._completion_widget = CompletionWidget(self._control)
200 201 self._continuation_prompt = '> '
@@ -727,8 +728,7 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
727 728 # Determine where to insert the content.
728 729 cursor = self._control.textCursor()
729 730 if before_prompt and not self._executing:
730 cursor.setPosition(self._prompt_pos)
731 cursor.movePosition(QtGui.QTextCursor.Left, n=len(self._prompt))
731 cursor.setPosition(self._append_before_prompt_pos)
732 732 else:
733 733 cursor.movePosition(QtGui.QTextCursor.End)
734 734 start_pos = cursor.position()
@@ -739,7 +739,9 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
739 739 # Adjust the prompt position if we have inserted before it. This is safe
740 740 # because buffer truncation is disabled when not executing.
741 741 if before_prompt and not self._executing:
742 self._prompt_pos += cursor.position() - start_pos
742 diff = cursor.position() - start_pos
743 self._append_before_prompt_pos += diff
744 self._prompt_pos += diff
743 745
744 746 return result
745 747
@@ -1726,14 +1728,16 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
1726 1728 If set, a new line will be written before showing the prompt if
1727 1729 there is not already a newline at the end of the buffer.
1728 1730 """
1731 # Save the current end position to support _append*(before_prompt=True).
1732 cursor = self._get_end_cursor()
1733 self._append_before_prompt_pos = cursor.position()
1734
1729 1735 # Insert a preliminary newline, if necessary.
1730 if newline:
1731 cursor = self._get_end_cursor()
1732 if cursor.position() > 0:
1733 cursor.movePosition(QtGui.QTextCursor.Left,
1734 QtGui.QTextCursor.KeepAnchor)
1735 if cursor.selection().toPlainText() != '\n':
1736 self._append_plain_text('\n')
1736 if newline and cursor.position() > 0:
1737 cursor.movePosition(QtGui.QTextCursor.Left,
1738 QtGui.QTextCursor.KeepAnchor)
1739 if cursor.selection().toPlainText() != '\n':
1740 self._append_plain_text('\n')
1737 1741
1738 1742 # Write the prompt.
1739 1743 self._append_plain_text(self._prompt_sep)
@@ -22,8 +22,7 b' from pygments_highlighter import PygmentsHighlighter'
22 22
23 23
24 24 class FrontendHighlighter(PygmentsHighlighter):
25 """ A PygmentsHighlighter that can be turned on and off and that ignores
26 prompts.
25 """ A PygmentsHighlighter that understands and ignores prompts.
27 26 """
28 27
29 28 def __init__(self, frontend):
@@ -50,14 +49,12 b' class FrontendHighlighter(PygmentsHighlighter):'
50 49 else:
51 50 prompt = self._frontend._continuation_prompt
52 51
53 # Don't highlight the part of the string that contains the prompt.
52 # Only highlight if we can identify a prompt, but make sure not to
53 # highlight the prompt.
54 54 if string.startswith(prompt):
55 55 self._current_offset = len(prompt)
56 56 string = string[len(prompt):]
57 else:
58 self._current_offset = 0
59
60 PygmentsHighlighter.highlightBlock(self, string)
57 super(FrontendHighlighter, self).highlightBlock(string)
61 58
62 59 def rehighlightBlock(self, block):
63 60 """ Reimplemented to temporarily enable highlighting if disabled.
@@ -71,7 +68,7 b' class FrontendHighlighter(PygmentsHighlighter):'
71 68 """ Reimplemented to highlight selectively.
72 69 """
73 70 start += self._current_offset
74 PygmentsHighlighter.setFormat(self, start, count, format)
71 super(FrontendHighlighter, self).setFormat(start, count, format)
75 72
76 73
77 74 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):
General Comments 0
You need to be logged in to leave comments. Login now