##// END OF EJS Templates
handle unicode issues in `ipython console` completions...
Min RK -
Show More
@@ -11,6 +11,7 b' except ImportError:'
11
11
12 from IPython.config import Configurable
12 from IPython.config import Configurable
13 from IPython.core.completer import IPCompleter
13 from IPython.core.completer import IPCompleter
14 from IPython.utils.py3compat import str_to_unicode, cast_bytes, unicode_to_str
14 from IPython.utils.traitlets import Float
15 from IPython.utils.traitlets import Float
15 import IPython.utils.rlineimpl as readline
16 import IPython.utils.rlineimpl as readline
16
17
@@ -36,8 +37,17 b' class ZMQCompleter(IPCompleter):'
36 self.readline.set_completer_delims('\r\n')
37 self.readline.set_completer_delims('\r\n')
37
38
38 def complete_request(self, text):
39 def complete_request(self, text):
39 line = readline.get_line_buffer()
40 line = str_to_unicode(readline.get_line_buffer())
40 cursor_pos = readline.get_endidx()
41 byte_cursor_pos = readline.get_endidx()
42
43 # get_endidx is a byte offset
44 # account for multi-byte characters to get correct cursor_pos
45 cursor_pos = byte_cursor_pos
46 i = 0
47 while i < cursor_pos:
48 bytelen = len(cast_bytes(line[i]))
49 cursor_pos -= (bytelen-1)
50 i += 1
41
51
42 # send completion request to kernel
52 # send completion request to kernel
43 # Give the kernel up to 5s to respond
53 # Give the kernel up to 5s to respond
@@ -54,6 +64,7 b' class ZMQCompleter(IPCompleter):'
54 if content["cursor_end"] < cursor_pos:
64 if content["cursor_end"] < cursor_pos:
55 extra = line[content["cursor_end"]: cursor_pos]
65 extra = line[content["cursor_end"]: cursor_pos]
56 matches = [m + extra for m in matches]
66 matches = [m + extra for m in matches]
67 matches = [ unicode_to_str(m) for m in matches ]
57 return matches
68 return matches
58 return []
69 return []
59
70
General Comments 0
You need to be logged in to leave comments. Login now