##// END OF EJS Templates
Add support for beep ('\b') character in qtconsole.
Michael Droettboom -
Show More
@@ -29,13 +29,16 b" ScrollAction = namedtuple('ScrollAction', ['action', 'dir', 'unit', 'count'])"
29 # An action for the carriage return character
29 # An action for the carriage return character
30 CarriageReturnAction = namedtuple('CarriageReturnAction', ['action'])
30 CarriageReturnAction = namedtuple('CarriageReturnAction', ['action'])
31
31
32 # An action for the beep character
33 BeepAction = namedtuple('BeepAction', ['action'])
34
32 # Regular expressions.
35 # Regular expressions.
33 CSI_COMMANDS = 'ABCDEFGHJKSTfmnsu'
36 CSI_COMMANDS = 'ABCDEFGHJKSTfmnsu'
34 CSI_SUBPATTERN = '\[(.*?)([%s])' % CSI_COMMANDS
37 CSI_SUBPATTERN = '\[(.*?)([%s])' % CSI_COMMANDS
35 OSC_SUBPATTERN = '\](.*?)[\x07\x1b]'
38 OSC_SUBPATTERN = '\](.*?)[\x07\x1b]'
36 ANSI_PATTERN = ('\x01?\x1b(%s|%s)\x02?' % \
39 ANSI_PATTERN = ('\x01?\x1b(%s|%s)\x02?' % \
37 (CSI_SUBPATTERN, OSC_SUBPATTERN))
40 (CSI_SUBPATTERN, OSC_SUBPATTERN))
38 ANSI_OR_CR_PATTERN = re.compile('(\r)|(?:%s)' % ANSI_PATTERN)
41 ANSI_OR_SPECIAL_PATTERN = re.compile('(\b|\r)|(?:%s)' % ANSI_PATTERN)
39 SPECIAL_PATTERN = re.compile('([\f])')
42 SPECIAL_PATTERN = re.compile('([\f])')
40
43
41 #-----------------------------------------------------------------------------
44 #-----------------------------------------------------------------------------
@@ -80,7 +83,7 b' class AnsiCodeProcessor(object):'
80 self.actions = []
83 self.actions = []
81 start = 0
84 start = 0
82
85
83 for match in ANSI_OR_CR_PATTERN.finditer(string):
86 for match in ANSI_OR_SPECIAL_PATTERN.finditer(string):
84 raw = string[start:match.start()]
87 raw = string[start:match.start()]
85 substring = SPECIAL_PATTERN.sub(self._replace_special, raw)
88 substring = SPECIAL_PATTERN.sub(self._replace_special, raw)
86 if substring or self.actions:
89 if substring or self.actions:
@@ -92,6 +95,9 b' class AnsiCodeProcessor(object):'
92 if groups[0] == '\r':
95 if groups[0] == '\r':
93 self.actions.append(CarriageReturnAction('carriage-return'))
96 self.actions.append(CarriageReturnAction('carriage-return'))
94 yield ''
97 yield ''
98 elif groups[0] == '\b':
99 self.actions.append(BeepAction('beep'))
100 yield ''
95 else:
101 else:
96 params = [ param for param in groups[1].split(';') if param ]
102 params = [ param for param in groups[1].split(';') if param ]
97 if groups[0].startswith('['):
103 if groups[0].startswith('['):
@@ -1517,6 +1517,9 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):'
1517 cursor.movePosition(
1517 cursor.movePosition(
1518 cursor.StartOfLine, cursor.KeepAnchor)
1518 cursor.StartOfLine, cursor.KeepAnchor)
1519
1519
1520 elif act.action == 'beep':
1521 QtGui.qApp.beep()
1522
1520 format = self._ansi_processor.get_format()
1523 format = self._ansi_processor.get_format()
1521 cursor.insertText(substring, format)
1524 cursor.insertText(substring, format)
1522 else:
1525 else:
General Comments 0
You need to be logged in to leave comments. Login now