From df98226564290288b432107585eca9174cb4f441 2010-09-10 19:15:56 From: epatters Date: 2010-09-10 19:15:56 Subject: [PATCH] Fixed ANSI compliance issue in AnsiCodeProcessor. Among other things, this fixes 'ls' on Mac OS. I also added a safety SGR reset in FrontendWidget to prevent bad ANSI codes from hosing the input buffer. --- diff --git a/IPython/frontend/qt/console/ansi_code_processor.py b/IPython/frontend/qt/console/ansi_code_processor.py index 6e485eb..efcec6e 100644 --- a/IPython/frontend/qt/console/ansi_code_processor.py +++ b/IPython/frontend/qt/console/ansi_code_processor.py @@ -104,8 +104,11 @@ class AnsiCodeProcessor(object): The parameter codes for the command. """ if command == 'm': # SGR - Select Graphic Rendition - for code in params: - self.set_sgr_code(code) + if params: + for code in params: + self.set_sgr_code(code) + else: + self.set_sgr_code(0) elif (command == 'J' or # ED - Erase Data command == 'K'): # EL - Erase in Line diff --git a/IPython/frontend/qt/console/frontend_widget.py b/IPython/frontend/qt/console/frontend_widget.py index 873587c..0adf7ad 100644 --- a/IPython/frontend/qt/console/frontend_widget.py +++ b/IPython/frontend/qt/console/frontend_widget.py @@ -265,6 +265,12 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): # before writing a new prompt. self.kernel_manager.sub_channel.flush() + # Reset the ANSI style information to prevent bad text in stdout + # from messing up our colors. We're not a true terminal so we're + # allowed to do this. + if self.ansi_codes: + self._ansi_processor.reset_sgr() + content = msg['content'] status = content['status'] if status == 'ok':