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