parent
484b9af6ed
commit
7e7803f680
|
@ -81,7 +81,7 @@ def finish_args(args):
|
|||
args.renderer_arg = mergeargs((parsedotval(v) for v in args.renderer_arg))
|
||||
|
||||
|
||||
def write_output(args, powerline, segment_info, write):
|
||||
def write_output(args, powerline, segment_info, write, encoding):
|
||||
if args.renderer_arg:
|
||||
segment_info.update(args.renderer_arg)
|
||||
if args.side.startswith('above'):
|
||||
|
@ -90,8 +90,8 @@ def write_output(args, powerline, segment_info, write):
|
|||
segment_info=segment_info,
|
||||
mode=segment_info['environ'].get('_POWERLINE_MODE'),
|
||||
):
|
||||
write(line)
|
||||
write('\n')
|
||||
write(line.encode(encoding, 'replace'))
|
||||
write(b'\n')
|
||||
args.side = args.side[len('above'):]
|
||||
|
||||
if args.side:
|
||||
|
@ -101,4 +101,4 @@ def write_output(args, powerline, segment_info, write):
|
|||
segment_info=segment_info,
|
||||
mode=segment_info['environ'].get('_POWERLINE_MODE'),
|
||||
)
|
||||
write(rendered)
|
||||
write(rendered.encode(encoding, 'replace'))
|
||||
|
|
|
@ -12,7 +12,7 @@ from signal import signal, SIGTERM
|
|||
from time import sleep
|
||||
from functools import partial
|
||||
from locale import getpreferredencoding
|
||||
from io import StringIO
|
||||
from io import BytesIO
|
||||
|
||||
from powerline.shell import get_argparser, finish_args, ShellPowerline, write_output
|
||||
from powerline.lib.monotonic import monotonic
|
||||
|
@ -98,8 +98,8 @@ def render(args, environ, cwd):
|
|||
powerline.pl.exception('Failed to render {0}: {1}', str(key), str(e))
|
||||
else:
|
||||
return 'Failed to render {0}: {1}'.format(str(key), str(e))
|
||||
s = StringIO()
|
||||
write_output(args, powerline, segment_info, s.write)
|
||||
s = BytesIO()
|
||||
write_output(args, powerline, segment_info, s.write, encoding)
|
||||
s.seek(0)
|
||||
return s.read()
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
import sys
|
||||
import os
|
||||
|
||||
from locale import getpreferredencoding
|
||||
|
||||
try:
|
||||
from powerline.shell import ShellPowerline, get_argparser, finish_args, write_output
|
||||
except ImportError:
|
||||
|
@ -11,11 +13,10 @@ except ImportError:
|
|||
from powerline.shell import ShellPowerline, get_argparser, finish_args, write_output # NOQA
|
||||
|
||||
|
||||
def write(output):
|
||||
try:
|
||||
sys.stdout.write(output)
|
||||
except UnicodeEncodeError:
|
||||
sys.stdout.write(output.encode('utf-8'))
|
||||
if sys.version_info < (3,):
|
||||
write = sys.stdout.write
|
||||
else:
|
||||
write = sys.stdout.buffer.write
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -23,4 +24,4 @@ if __name__ == '__main__':
|
|||
finish_args(args)
|
||||
powerline = ShellPowerline(args, run_once=True)
|
||||
segment_info = {'args': args, 'environ': os.environ}
|
||||
write_output(args, powerline, segment_info, write)
|
||||
write_output(args, powerline, segment_info, write, getpreferredencoding())
|
||||
|
|
Loading…
Reference in New Issue