|
8 | 8 | from __future__ import with_statement |
9 | 9 | from __future__ import print_function |
10 | 10 |
|
| 11 | +from _pyrepl import readline |
11 | 12 | import rlcompleter |
12 | 13 | import sys |
13 | 14 | import types |
@@ -105,10 +106,7 @@ def set(cls, color, string): |
105 | 106 | class DefaultConfig: |
106 | 107 |
|
107 | 108 | consider_getitems = True |
108 | | - prefer_pyrepl = True |
109 | 109 | use_colors = 'auto' |
110 | | - readline = None # set by setup() |
111 | | - using_pyrepl = False # overwritten by find_pyrepl |
112 | 110 |
|
113 | 111 | color_by_type = { |
114 | 112 | types.BuiltinMethodType: Color.turquoise, |
@@ -138,50 +136,12 @@ class DefaultConfig: |
138 | 136 | ((BaseException,), Color.red), |
139 | 137 | ] |
140 | 138 |
|
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 |
179 | 139 |
|
180 | 140 | def setup(self): |
181 | | - self.readline, supports_color = self.find_best_readline() |
| 141 | + import _colorize |
182 | 142 | 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 != "" |
185 | 145 |
|
186 | 146 |
|
187 | 147 | def my_execfile(filename, mydict): |
@@ -242,19 +202,21 @@ class Completer(rlcompleter.Completer, ConfigurableClass): |
242 | 202 | """ |
243 | 203 |
|
244 | 204 | DefaultConfig = DefaultConfig |
245 | | - config_filename = '.fancycompleterrc.py' |
| 205 | + config_filename = '.fancycompleterrc.py.xxx' |
246 | 206 |
|
247 | 207 | def __init__(self, namespace=None, Config=None): |
248 | 208 | rlcompleter.Completer.__init__(self, namespace) |
249 | 209 | self.config = self.get_config(Config) |
250 | 210 | 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'): |
253 | 214 | # this is needed to offer pyrepl a better chance to patch |
254 | 215 | # raw_input. Usually, it does at import time, but is we are under |
255 | 216 | # pytest with output captured, at import time we don't have a |
256 | 217 | # terminal and thus the raw_input hook is not installed |
257 | 218 | readline._setup() |
| 219 | + |
258 | 220 | if self.config.use_colors: |
259 | 221 | readline.parse_and_bind('set dont-escape-ctrl-chars on') |
260 | 222 | if self.config.consider_getitems: |
|
0 commit comments