From 14ae4c0f28d14eae1e22288e4572484d58c456b6 Mon Sep 17 00:00:00 2001 From: epatters Date: Wed, 14 Sep 2011 13:59:16 -0500 Subject: [PATCH] BUG: Don't use readline in the ZMQShell. Closes gh-617. --- IPython/core/interactiveshell.py | 18 +++++++++++++++++- IPython/core/magic.py | 5 +++-- IPython/zmq/zmqshell.py | 9 ++------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 6f500463f35..928032afbef 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -108,6 +108,11 @@ def softspace(file, newvalue): def no_op(*a, **kw): pass +class NoOpContext(object): + def __enter__(self): pass + def __exit__(self, type, value, traceback): pass +no_op_context = NoOpContext() + class SpaceInInput(Exception): pass class Bunch: pass @@ -242,6 +247,15 @@ class InteractiveShell(SingletonConfigurable, Magic): default_value=get_default_colors(), config=True, help="Set the color scheme (NoColor, Linux, or LightBG)." ) + colors_force = CBool(False, help= + """ + Force use of ANSI color codes, regardless of OS and readline + availability. + """ + # FIXME: This is essentially a hack to allow ZMQShell to show colors + # without readline on Win32. When the ZMQ formatting system is + # refactored, this should be removed. + ) debug = CBool(False, config=True) deep_reload = CBool(False, config=True, help= """ @@ -1636,10 +1650,12 @@ def init_readline(self): self.has_readline = False self.readline = None # Set a number of methods that depend on readline to be no-op + self.readline_no_record = no_op_context self.set_readline_completer = no_op self.set_custom_completer = no_op self.set_completer_frame = no_op - warn('Readline services not available or not loaded.') + if self.readline_use: + warn('Readline services not available or not loaded.') else: self.has_readline = True self.readline = readline diff --git a/IPython/core/magic.py b/IPython/core/magic.py index e33d344aa4c..aa12ddcf800 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -2496,7 +2496,8 @@ def color_switch_err(name): import IPython.utils.rlineimpl as readline - if not readline.have_readline and sys.platform == "win32": + if not shell.colors_force and \ + not readline.have_readline and sys.platform == "win32": msg = """\ Proper color support under MS Windows requires the pyreadline library. You can find it at: @@ -2510,7 +2511,7 @@ def color_switch_err(name): warn(msg) # readline option is 0 - if not shell.has_readline: + if not shell.colors_force and not shell.has_readline: new_scheme = 'NoColor' # Set prompt colors diff --git a/IPython/zmq/zmqshell.py b/IPython/zmq/zmqshell.py index 2bbf2a9b0ff..a33779fa228 100644 --- a/IPython/zmq/zmqshell.py +++ b/IPython/zmq/zmqshell.py @@ -84,13 +84,8 @@ class ZMQInteractiveShell(InteractiveShell): # Override the traitlet in the parent class, because there's no point using # readline for the kernel. Can be removed when the readline code is moved # to the terminal frontend. - - # FIXME. This is disabled for now, even though it may cause problems under - # Windows, because it breaks %run in the Qt console. See gh-617 for more - # details. Re-enable once we've fully tested that %run works in the Qt - # console with syntax highlighting in tracebacks. - # readline_use = CBool(False) - # /FIXME + colors_force = CBool(True) + readline_use = CBool(False) exiter = Instance(ZMQExitAutocall) def _exiter_default(self):