Skip to content

Commit

Permalink
Support stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Feb 11, 2018
1 parent 8921b1a commit 1c57338
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions rplugin/python3/deoplete/child.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def main(self):
self.debug('main_loop: end')

def _write(self, expr):
sys.stdout.buffer.write(self._packer.pack(expr))
sys.stdout.flush()
sys.stderr.buffer.write(self._packer.pack(expr))
sys.stderr.flush()

def _enable_logging(self):
logging = self._vim.vars['deoplete#_logging']
Expand Down
13 changes: 13 additions & 0 deletions rplugin/python3/deoplete/dp_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# ============================================================================

import sys
import io

from neovim import attach

Expand All @@ -28,10 +29,22 @@ def attach_vim(serveraddr):
return vim


class RedirectStream(io.IOBase):
def __init__(self, handler):
self.handler = handler

def write(self, line):
self.handler(line)

def writelines(self, lines):
self.handler('\n'.join(lines))


def main(serveraddr):
vim = attach_vim(serveraddr)
from deoplete.child import Child
from deoplete.util import error_tb
sys.stdout = RedirectStream(lambda data: vim.out_write(data))
try:
child = Child(vim)
child.main()
Expand Down
2 changes: 1 addition & 1 deletion rplugin/python3/deoplete/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def kill(self):

def enqueue_output(self):
while self._proc:
b = self._proc.stdout.raw.read(102400)
b = self._proc.stderr.raw.read(102400)
if b == b'':
# EOF
break
Expand Down

0 comments on commit 1c57338

Please sign in to comment.