Skip to content

Commit 88181da

Browse files
committed
kill the logic to find a readline, we can always use _pyrepl.readline now
1 parent 40563f2 commit 88181da

1 file changed

Lines changed: 9 additions & 47 deletions

File tree

Lib/_pyrepl/fancycompleter.py

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from __future__ import with_statement
99
from __future__ import print_function
1010

11+
from _pyrepl import readline
1112
import rlcompleter
1213
import sys
1314
import types
@@ -105,10 +106,7 @@ def set(cls, color, string):
105106
class DefaultConfig:
106107

107108
consider_getitems = True
108-
prefer_pyrepl = True
109109
use_colors = 'auto'
110-
readline = None # set by setup()
111-
using_pyrepl = False # overwritten by find_pyrepl
112110

113111
color_by_type = {
114112
types.BuiltinMethodType: Color.turquoise,
@@ -138,50 +136,12 @@ class DefaultConfig:
138136
((BaseException,), Color.red),
139137
]
140138

141-
def find_pyrepl(self):
142-
try:
143-
import pyrepl.readline
144-
import pyrepl.completing_reader
145-
except ImportError:
146-
return None
147-
self.using_pyrepl = True
148-
if hasattr(pyrepl.completing_reader, 'stripcolor'):
149-
# modern version of pyrepl
150-
return pyrepl.readline, True
151-
else:
152-
return pyrepl.readline, False
153-
154-
def find_pyreadline(self):
155-
try:
156-
import readline
157-
import pyreadline # noqa: F401 # XXX: needed really?
158-
from pyreadline.modes import basemode
159-
except ImportError:
160-
return None
161-
if hasattr(basemode, 'stripcolor'):
162-
# modern version of pyreadline; see:
163-
# https://github.com/pyreadline/pyreadline/pull/48
164-
return readline, True
165-
else:
166-
return readline, False
167-
168-
def find_best_readline(self):
169-
if self.prefer_pyrepl:
170-
result = self.find_pyrepl()
171-
if result:
172-
return result
173-
if sys.platform == 'win32':
174-
result = self.find_pyreadline()
175-
if result:
176-
return result
177-
import readline
178-
return readline, False # by default readline does not support colors
179139

180140
def setup(self):
181-
self.readline, supports_color = self.find_best_readline()
141+
import _colorize
182142
if self.use_colors == 'auto':
183-
#self.use_colors = supports_color
184-
self.use_colors = True
143+
colors = _colorize.get_colors()
144+
self.use_colors = colors.RED != ""
185145

186146

187147
def my_execfile(filename, mydict):
@@ -242,19 +202,21 @@ class Completer(rlcompleter.Completer, ConfigurableClass):
242202
"""
243203

244204
DefaultConfig = DefaultConfig
245-
config_filename = '.fancycompleterrc.py'
205+
config_filename = '.fancycompleterrc.py.xxx'
246206

247207
def __init__(self, namespace=None, Config=None):
248208
rlcompleter.Completer.__init__(self, namespace)
249209
self.config = self.get_config(Config)
250210
self.config.setup()
251-
readline = self.config.readline
252-
if hasattr(readline, '_setup'):
211+
212+
# XXX: double check what happens in this case once fancycompleter works
213+
if False and hasattr(readline, '_setup'):
253214
# this is needed to offer pyrepl a better chance to patch
254215
# raw_input. Usually, it does at import time, but is we are under
255216
# pytest with output captured, at import time we don't have a
256217
# terminal and thus the raw_input hook is not installed
257218
readline._setup()
219+
258220
if self.config.use_colors:
259221
readline.parse_and_bind('set dont-escape-ctrl-chars on')
260222
if self.config.consider_getitems:

0 commit comments

Comments
 (0)