Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for beep ('\b') character in qtconsole.

  • Loading branch information...
commit 8eb8d564daf396cd6c5e340a696257188207da23 1 parent 7d05f6c
@mdboom authored
View
10 IPython/frontend/qt/console/ansi_code_processor.py
@@ -29,13 +29,16 @@
# 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 @@ def split_string(self, string):
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 @@ def split_string(self, string):
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('['):
View
3  IPython/frontend/qt/console/console_widget.py
@@ -1517,6 +1517,9 @@ def _insert_plain_text(self, cursor, text):
cursor.movePosition(
cursor.StartOfLine, cursor.KeepAnchor)
+ elif act.action == 'beep':
+ QtGui.qApp.beep()
+
format = self._ansi_processor.get_format()
cursor.insertText(substring, format)
else:
Please sign in to comment.
Something went wrong with that request. Please try again.