parent
0d6d25d147
commit
b38628d474
70
buffer.py
70
buffer.py
|
@ -423,13 +423,83 @@ class IperlBuffer(Buffer):
|
||||||
def readonly(self):
|
def readonly(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
class IperlBuffer2(Buffer):
|
||||||
def get_ipython_name(parent):
|
def get_ipython_name(parent):
|
||||||
if hasattr(parent, 'path'):
|
if hasattr(parent, 'path'):
|
||||||
return '*IPython:%s*' % parent.name()
|
return '*IPython:%s*' % parent.name()
|
||||||
else:
|
else:
|
||||||
return '*IPython*'
|
return '*IPython*'
|
||||||
|
get_ipython_name = classmethod(get_ipython_name)
|
||||||
|
btype = 'ipython'
|
||||||
|
modename = 'ipython'
|
||||||
|
readre = re.compile('^([A-Z]+):(.*)\n$')
|
||||||
|
_name = '*IPython*'
|
||||||
|
def __init__(self, parent):
|
||||||
|
if hasattr(parent, 'path'):
|
||||||
|
self.parent = parent
|
||||||
|
else:
|
||||||
|
self.parent = None
|
||||||
|
Buffer.__init__(self)
|
||||||
|
f = open('/dev/null', 'w')
|
||||||
|
self.pipe = Popen(self.get_cmd(), stdin=PIPE, stdout=PIPE, stderr=f)
|
||||||
|
self.prompt = '***'
|
||||||
|
self.clear()
|
||||||
|
self.pipe_read()
|
||||||
|
self._name = get_ipython_name(parent)
|
||||||
|
def name(self):
|
||||||
|
return self._name
|
||||||
|
def get_cmd(self):
|
||||||
|
if self.parent:
|
||||||
|
return ('epython', '-p', self.parent.path)
|
||||||
|
else:
|
||||||
|
return ('epython',)
|
||||||
|
def pipe_readline(self):
|
||||||
|
line = self.pipe.stdout.readline()
|
||||||
|
m = self.readre.match(line)
|
||||||
|
if m:
|
||||||
|
return (m.group(1), m.group(2))
|
||||||
|
else:
|
||||||
|
return (None, line.rstrip())
|
||||||
|
def pipe_read(self):
|
||||||
|
lines = []
|
||||||
|
while True:
|
||||||
|
(type_, value) = self.pipe_readline()
|
||||||
|
if type_ == 'PROMPT':
|
||||||
|
self.prompt = value.strip() + ' '
|
||||||
|
break
|
||||||
|
value.rstrip()
|
||||||
|
if value:
|
||||||
|
lines.append(value)
|
||||||
|
if lines:
|
||||||
|
output = '\n'.join(lines) + '\n'
|
||||||
|
p = self.get_buffer_end()
|
||||||
|
self.insert_string(p, output, force=True)
|
||||||
|
def pipe_write(self, s):
|
||||||
|
self.pipe.stdin.write("%s\n" % s)
|
||||||
|
self.pipe.stdin.flush()
|
||||||
|
def pipe_read_completions(self):
|
||||||
|
(typ_, value) = self.pipe_readline()
|
||||||
|
assert typ_ == 'COMPLETIONS', '%r %r' % (typ_, value)
|
||||||
|
candidates = [x for x in value.split('|') if x]
|
||||||
|
return candidates
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
self.set_data('', force=True)
|
||||||
|
def changed(self):
|
||||||
|
return False
|
||||||
|
def close(self):
|
||||||
|
global ipython
|
||||||
|
ipython = None
|
||||||
|
def readonly(self):
|
||||||
|
return True
|
||||||
|
|
||||||
class IpythonBuffer(Buffer):
|
class IpythonBuffer(Buffer):
|
||||||
|
def get_ipython_name(parent):
|
||||||
|
if hasattr(parent, 'path'):
|
||||||
|
return '*IPython:%s*' % parent.name()
|
||||||
|
else:
|
||||||
|
return '*IPython*'
|
||||||
|
get_ipython_name = classmethod(get_ipython_name)
|
||||||
btype = 'ipython'
|
btype = 'ipython'
|
||||||
modename = 'ipython'
|
modename = 'ipython'
|
||||||
readre = re.compile('^([A-Z]+):(.*)\n$')
|
readre = re.compile('^([A-Z]+):(.*)\n$')
|
||||||
|
|
|
@ -76,7 +76,7 @@ class IpythonPathStart(method.Method):
|
||||||
if w.buffer.btype == 'ipython':
|
if w.buffer.btype == 'ipython':
|
||||||
b = w.buffer
|
b = w.buffer
|
||||||
else:
|
else:
|
||||||
name = buffer.get_ipython_name(w.buffer)
|
name = buffer.IpythonBuffer.get_ipython_name(w.buffer)
|
||||||
if not a.has_buffer_name(name):
|
if not a.has_buffer_name(name):
|
||||||
b = buffer.IpythonBuffer(w.buffer)
|
b = buffer.IpythonBuffer(w.buffer)
|
||||||
a.add_buffer(b)
|
a.add_buffer(b)
|
||||||
|
|
Loading…
Reference in New Issue