From 8eb8d564daf396cd6c5e340a696257188207da23 2011-12-02 16:22:03 From: Michael Droettboom Date: 2011-12-02 16:22:03 Subject: [PATCH] Add support for beep ('\b') character in qtconsole. --- diff --git a/IPython/frontend/qt/console/ansi_code_processor.py b/IPython/frontend/qt/console/ansi_code_processor.py index ac47fd8..f027ccf 100644 --- a/IPython/frontend/qt/console/ansi_code_processor.py +++ b/IPython/frontend/qt/console/ansi_code_processor.py @@ -29,13 +29,16 @@ ScrollAction = namedtuple('ScrollAction', ['action', 'dir', 'unit', 'count']) # An action for the carriage return character CarriageReturnAction = namedtuple('CarriageReturnAction', ['action']) +# An action for the beep character +BeepAction = namedtuple('BeepAction', ['action']) + # Regular expressions. CSI_COMMANDS = 'ABCDEFGHJKSTfmnsu' CSI_SUBPATTERN = '\[(.*?)([%s])' % CSI_COMMANDS OSC_SUBPATTERN = '\](.*?)[\x07\x1b]' ANSI_PATTERN = ('\x01?\x1b(%s|%s)\x02?' % \ (CSI_SUBPATTERN, OSC_SUBPATTERN)) -ANSI_OR_CR_PATTERN = re.compile('(\r)|(?:%s)' % ANSI_PATTERN) +ANSI_OR_SPECIAL_PATTERN = re.compile('(\b|\r)|(?:%s)' % ANSI_PATTERN) SPECIAL_PATTERN = re.compile('([\f])') #----------------------------------------------------------------------------- @@ -80,7 +83,7 @@ class AnsiCodeProcessor(object): self.actions = [] start = 0 - for match in ANSI_OR_CR_PATTERN.finditer(string): + for match in ANSI_OR_SPECIAL_PATTERN.finditer(string): raw = string[start:match.start()] substring = SPECIAL_PATTERN.sub(self._replace_special, raw) if substring or self.actions: @@ -92,6 +95,9 @@ class AnsiCodeProcessor(object): if groups[0] == '\r': self.actions.append(CarriageReturnAction('carriage-return')) yield '' + elif groups[0] == '\b': + self.actions.append(BeepAction('beep')) + yield '' else: params = [ param for param in groups[1].split(';') if param ] if groups[0].startswith('['): diff --git a/IPython/frontend/qt/console/console_widget.py b/IPython/frontend/qt/console/console_widget.py index 8fe9440..69c273c 100644 --- a/IPython/frontend/qt/console/console_widget.py +++ b/IPython/frontend/qt/console/console_widget.py @@ -1517,6 +1517,9 @@ class ConsoleWidget(LoggingConfigurable, QtGui.QWidget): cursor.movePosition( cursor.StartOfLine, cursor.KeepAnchor) + elif act.action == 'beep': + QtGui.qApp.beep() + format = self._ansi_processor.get_format() cursor.insertText(substring, format) else: