Show More
@@ -26,12 +26,16 b" MoveAction = namedtuple('MoveAction', ['action', 'dir', 'unit', 'count'])" | |||||
26 | # An action for scroll requests (SU and ST) and form feeds. |
|
26 | # An action for scroll requests (SU and ST) and form feeds. | |
27 | ScrollAction = namedtuple('ScrollAction', ['action', 'dir', 'unit', 'count']) |
|
27 | ScrollAction = namedtuple('ScrollAction', ['action', 'dir', 'unit', 'count']) | |
28 |
|
28 | |||
|
29 | # An action for the carriage return character | |||
|
30 | CarriageReturnAction = namedtuple('CarriageReturnAction', ['action']) | |||
|
31 | ||||
29 | # Regular expressions. |
|
32 | # Regular expressions. | |
30 | CSI_COMMANDS = 'ABCDEFGHJKSTfmnsu' |
|
33 | CSI_COMMANDS = 'ABCDEFGHJKSTfmnsu' | |
31 | CSI_SUBPATTERN = '\[(.*?)([%s])' % CSI_COMMANDS |
|
34 | CSI_SUBPATTERN = '\[(.*?)([%s])' % CSI_COMMANDS | |
32 | OSC_SUBPATTERN = '\](.*?)[\x07\x1b]' |
|
35 | OSC_SUBPATTERN = '\](.*?)[\x07\x1b]' | |
33 |
ANSI_PATTERN = |
|
36 | ANSI_PATTERN = ('\x01?\x1b(%s|%s)\x02?' % \ | |
34 |
|
|
37 | (CSI_SUBPATTERN, OSC_SUBPATTERN)) | |
|
38 | ANSI_OR_CR_PATTERN = re.compile('(\r)|(?:%s)' % ANSI_PATTERN) | |||
35 | SPECIAL_PATTERN = re.compile('([\f])') |
|
39 | SPECIAL_PATTERN = re.compile('([\f])') | |
36 |
|
40 | |||
37 | #----------------------------------------------------------------------------- |
|
41 | #----------------------------------------------------------------------------- | |
@@ -76,7 +80,7 b' class AnsiCodeProcessor(object):' | |||||
76 | self.actions = [] |
|
80 | self.actions = [] | |
77 | start = 0 |
|
81 | start = 0 | |
78 |
|
82 | |||
79 | for match in ANSI_PATTERN.finditer(string): |
|
83 | for match in ANSI_OR_CR_PATTERN.finditer(string): | |
80 | raw = string[start:match.start()] |
|
84 | raw = string[start:match.start()] | |
81 | substring = SPECIAL_PATTERN.sub(self._replace_special, raw) |
|
85 | substring = SPECIAL_PATTERN.sub(self._replace_special, raw) | |
82 | if substring or self.actions: |
|
86 | if substring or self.actions: | |
@@ -85,20 +89,24 b' class AnsiCodeProcessor(object):' | |||||
85 |
|
89 | |||
86 | self.actions = [] |
|
90 | self.actions = [] | |
87 | groups = filter(lambda x: x is not None, match.groups()) |
|
91 | groups = filter(lambda x: x is not None, match.groups()) | |
88 | params = [ param for param in groups[1].split(';') if param ] |
|
92 | if groups[0] == '\r': | |
89 | if groups[0].startswith('['): |
|
93 | self.actions.append(CarriageReturnAction('carriage-return')) | |
90 | # Case 1: CSI code. |
|
94 | yield '' | |
91 |
|
|
95 | else: | |
92 | params = map(int, params) |
|
96 | params = [ param for param in groups[1].split(';') if param ] | |
93 | except ValueError: |
|
97 | if groups[0].startswith('['): | |
94 | # Silently discard badly formed codes. |
|
98 | # Case 1: CSI code. | |
95 |
|
|
99 | try: | |
96 | else: |
|
100 | params = map(int, params) | |
97 | self.set_csi_code(groups[2], params) |
|
101 | except ValueError: | |
98 |
|
102 | # Silently discard badly formed codes. | ||
99 | elif groups[0].startswith(']'): |
|
103 | pass | |
100 |
|
|
104 | else: | |
101 |
self.set_ |
|
105 | self.set_csi_code(groups[2], params) | |
|
106 | ||||
|
107 | elif groups[0].startswith(']'): | |||
|
108 | # Case 2: OSC code. | |||
|
109 | self.set_osc_code(params) | |||
102 |
|
110 | |||
103 | raw = string[start:] |
|
111 | raw = string[start:] | |
104 | substring = SPECIAL_PATTERN.sub(self._replace_special, raw) |
|
112 | substring = SPECIAL_PATTERN.sub(self._replace_special, raw) |
@@ -1513,6 +1513,10 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||||
1513 | cursor.joinPreviousEditBlock() |
|
1513 | cursor.joinPreviousEditBlock() | |
1514 | cursor.deletePreviousChar() |
|
1514 | cursor.deletePreviousChar() | |
1515 |
|
1515 | |||
|
1516 | elif act.action == 'carriage-return': | |||
|
1517 | cursor.movePosition( | |||
|
1518 | cursor.StartOfLine, cursor.KeepAnchor) | |||
|
1519 | ||||
1516 | format = self._ansi_processor.get_format() |
|
1520 | format = self._ansi_processor.get_format() | |
1517 | cursor.insertText(substring, format) |
|
1521 | cursor.insertText(substring, format) | |
1518 | else: |
|
1522 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now