-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unicode TTY with /dev/vcsu #45
Conversation
Yes, this was mentioned somewhere at the bottom of the README as a nice thing to have, but at the time of writing it wasn't in the mainline kernel. I guess now it is? |
Oh yeah, now that you mention it! It's definitely present in Raspbian Buster (this is on a pretty fresh install), which I guess is the only version we have to reasonably support? |
So to recap, this
The attributes weren't currently used anyway but perhaps would be nice at some point if we get grayscale support. But as it is, having Unicode is much more important and it's very cool that it can finally be used, so thanks a lot again for this pull request. I'm just a tad against breaking running systems though - my old installation doesn't have What do you think? Also, how extensively have you tested it yourself, ie. does it seem that everything Just Works (like running |
I think a fallback should be fairly easy to do, I'd just need to have |
I've added some code to fall back to vcs if vcsu isn't available. I don't have a sufficiently old system available, but at least it doesn't appear to have broken the Unicode mode, so that's nice. I've tested with top, htop, wordgrinder and Midnight commander, which all look fine, though it's a bit hard to tell what's selected. 😉 |
Hmm. Which settings are you using? I got around to actually getting my old ZeroW out to try this, dist-upgrading it to get the I'm running
We should make sure the defaults work somewhat, so probably some more care with font selection too is needed when incorporating this Unicode support. Unless I set some other font it crashes with stuff like (papertty) pi@rasputin:~/new-version/PaperTTY $ sudo /home/pi/.virtualenvs/papertty/bin/python3 ./papertty.py --driver epd2in13 terminal --autofit
Automatic resize of TTY to 20 rows, 62 columns
Started displaying /dev/vcsa1, minimum update interval 0.1 s, exit with Ctrl-C
Traceback (most recent call last):
File "./papertty.py", line 523, in <module>
cli()
File "/home/pi/.virtualenvs/papertty/lib/python3.5/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/home/pi/.virtualenvs/papertty/lib/python3.5/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/home/pi/.virtualenvs/papertty/lib/python3.5/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/pi/.virtualenvs/papertty/lib/python3.5/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/pi/.virtualenvs/papertty/lib/python3.5/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/pi/.virtualenvs/papertty/lib/python3.5/site-packages/click/decorators.py", line 27, in new_func
return f(get_current_context().obj, *args, **kwargs)
File "./papertty.py", line 508, in terminal
**textargs)
File "./papertty.py", line 266, in showtext
draw.text((0, 0), text, font=self.font, fill=fill, spacing=spacing)
File "/home/pi/.virtualenvs/papertty/lib/python3.5/site-packages/PIL/ImageDraw.py", line 212, in text
*args, **kwargs)
File "/home/pi/.virtualenvs/papertty/lib/python3.5/site-packages/PIL/ImageDraw.py", line 236, in multiline_text
line_width, line_height = self.textsize(line, font)
File "/home/pi/.virtualenvs/papertty/lib/python3.5/site-packages/PIL/ImageDraw.py", line 263, in textsize
return font.getsize(text, direction, features)
File "/home/pi/.virtualenvs/papertty/lib/python3.5/site-packages/PIL/ImageFont.py", line 112, in getsize
return self.font.getsize(text)
UnicodeEncodeError: 'latin-1' codec can't encode character '\ufffd' in position 10: ordinal not in range(256) The Pillow in the virtualenv is version 5.2.0 (and the Pi is running stretch, 9.11 with kernel 4.19.66+). I'll look at this tomorrow some more if I have time, but apparently you don't have a similar problem? |
Those replacement characters are certainly strange. Can you attach the contents of your /dev/vcsu1? Pil fonts are not unicode-ready. Even if creating them from a unicode font with pilfont.py, they only contain the latin-1 characters. Should we fall back to vcs if no truetype font was loaded? |
I'll try to take another look in the evening. But yeah, there could be a bit of smartness there to not use Unicode if it's obvious that the chosen font can't handle it (plus a warning message to inform the user). Not sure if there's some smarter way to handle this without making it unnecessarily complex. |
The current way is to use vcsa and skip the attributes to get the content. 🙂 But we can't do that for vcsu, as the Linux people haven't gotten around to implementing vcsua yet. The performance impact of opening vcs even though vcsa is already open is negligible, IMHO. Using vcsa would make the code more complex for little gain. Checking whether we have a TrueType font is pretty easily done, as seen here. Then fall back to vcs. |
I'm currently looking at this (and also implemented the TrueType check, although by adding a I was a bit puzzled at first since now the unicode seemed to first work with a TrueType font, but then tried to start
So that causes the funny replacement characters it seems. I fixed it by simply adding: ...
buff = vcsu.read()
if character_width == 4:
buff = buff.replace(b'\x20\x20\x20\x20', b'\x20\x00\x00\x00')
... And with that the problem appears to be fixed, however I'm still not 100% sure what to blame here, but it's as if On a positive note: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a couple of suggestions for keeping vcsudev
static, adjusting the information text a bit and "fixing" tmux
whitespace. Mostly for reference for now.
One minor thing that came to mind: I suppose if we do want the character attributes, they could simply be read from |
Yes, that was my plan. 🙂 |
This is starting to look pretty good, I think. Did you have something more to add at this time? I think some help texts could be added - that is, making the program clearly state if Unicode won't work because of missing |
Great idea! I did just that. |
Co-Authored-By: joukos <joukos@users.noreply.github.com>
I think I'll go ahead and merge this now. It's a killer feature, thanks for the great work! |
Apparently there's a vcsu device in Linux, that works like vcs but returns UTF-32. I haven't found much documentation though. This seems to make Unicode actually work. Since we no longer need to specify an encoding, I've also removed the encoding parameter.