- # fribidi does not support ungetting, so force newlines
- params['progress_with_newline'] = True
-
- for fid in ['_screen_file', '_err_file']:
- class FribidiOut(object):
- def __init__(self, outfile, errfile):
- self.outfile = outfile
- self.process = subprocess.Popen(
- ['fribidi'],
- stdin=subprocess.PIPE,
- stdout=outfile,
- stderr=errfile)
-
- def write(self, s):
- res = self.process.stdin.write(s)
- self.flush()
- return res
-
- def flush(self):
- return self.process.stdin.flush()
-
- def isatty(self):
- return self.outfile.isatty()
-
- try:
- vout = FribidiOut(getattr(self, fid), self._err_file)
- setattr(self, fid, vout)
- except OSError as ose:
- if ose.errno == 2:
- self.report_warning(u'Could not find fribidi executable, ignoring --bidi-workaround . Make sure that fribidi is an executable file in one of the directories in your $PATH.')
- break
- else:
- raise
+ try:
+ import pty
+ master, slave = pty.openpty()
+ width = get_term_width()
+ if width is None:
+ width_args = []
+ else:
+ width_args = ['-w', str(width)]
+ self._fribidi = subprocess.Popen(
+ ['fribidi', '-c', 'UTF-8'] + width_args,
+ stdin=subprocess.PIPE,
+ stdout=slave,
+ stderr=self._err_file)
+ self._fribidi_channel = os.fdopen(master, 'rb')
+ except OSError as ose:
+ if ose.errno == 2:
+ self.report_warning(u'Could not find fribidi executable, ignoring --bidi-workaround . Make sure that fribidi is an executable file in one of the directories in your $PATH.')
+ else:
+ raise