diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 6f50046..928032a 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 @@ class InteractiveShell(SingletonConfigurable, Magic): 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 e33d344..aa12ddc 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -2496,7 +2496,8 @@ Currently the magic system has the following functions:\n""" 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 @@ Defaulting color scheme to 'NoColor'""" 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 2bbf2a9..a33779f 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):