colout icon indicating copy to clipboard operation
colout copied to clipboard

UnicodeEncodeError when using `less -R`

Open while0pass opened this issue 7 years ago • 1 comments

I get an UnicodeEncodeError when I use colout with less -R. When I use less without options or just don't use less at all, everything goes fine:

$ cat svn-diff.txt | colout -s diff | less
$ cat svn-diff.txt | colout -s diff

But if I add -R option so that ascii escape sequences wouldn't be striped, I get this:

$ cat svn-diff.txt | colout -s diff | less -R

Index: generate_fountain.py
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/colout/colout.py", line 862, in <module>
    write_all( as_all, sys.stdin, sys.stdout, highlight, lexer, formatter )
  File "/usr/local/lib/python2.7/dist-packages/colout/colout.py", line 729, in write_all
    map_write( stream_in, stream_out, function, *args )
  File "/usr/local/lib/python2.7/dist-packages/colout/colout.py", line 574, in map_write
    write( function(item, *args), stream_out )
  File "/usr/local/lib/python2.7/dist-packages/colout/colout.py", line 545, in write
    stream.write(colored)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0412' in position 16: ordinal not in range(128)
===================================================================
--- generate_fountain.py        (revision 1294)
+++ generate_fountain.py        (working copy)
@@ -5,7 +5,7 @@

svn-diff.txt contains several non-ascii characters.

while0pass avatar Nov 23 '16 10:11 while0pass

Most probably related to #85, fixed by e9f0bff0cce0e36adf7419520e505d1aa3009b1d, please check.

nojhan avatar Feb 26 '18 17:02 nojhan