Skip to content
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

Improve cosmetics on Linux vconsole #5011

Open
jsatchell opened this issue Sep 16, 2024 · 7 comments
Open

Improve cosmetics on Linux vconsole #5011

jsatchell opened this issue Sep 16, 2024 · 7 comments

Comments

@jsatchell
Copy link

Textual works, but doesn't look good on the Linux virtual console environment.
I am about to deploy an in company solution that uses textual on read-only Linux ISOs, where the textual app is launched as the default shell. It all works, but the box drawing looks poor, and you can see the problem by running any textual demo in the console environment. All the graphical elements that should have edges have rows of diamonds (or whatever the missing glyph is shown as for that font). The available colors are limited, and the scroll bars have no contrast, but that could presumably be fixed with some CSS.

Ironically, if you provoke a traceback, the box drawing in the traceback looks great.

The Linux console has some limitations, inherited from VGA hardware text mode. There are at most 256 glyphs, or 512 if you give up bright colors. A standard install ships with about 120 font files, which differ in both glyph shape and size, and the mapping of character index to glyph shape, to cover a range of languages. I have looked at quite a lot of the Latin ones, and all the ones I checked have the basic, single-line box drawing characters and some shading chars, round 0xB0 to 0xB5 and 0xC0 to 0xC6.

There are supposedly some psfu fonts, which do some extended Unicode mapping to the limited set of available glyphs, and these might include some or all of the Unicode box drawing area round 2500 that Textual uses. None of my installs have psfu files, but I could chase that if it one that works was known.

I don't want to solutioneer, but I can see two options.

  • Either, a better font is found (or made).
  • Or, an alternate box drawing mode that uses the existing single line glyphs. Ideally, this would auto-detect, but if we had to pass a parameter in, perhaps to the app object, that would be fine. Looking at the source code, I think changes could be largely localised to the box drawing module.

Happy to help, but I don't want to start changing things on a clone in a way you would never accept.

Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@jsatchell
Copy link
Author

I will investigate, but it looks like the zap fonts include more box drawing chars, and map the Unicode 2500 range, so might be an option. See https://www.zap.org.au/projects/console-fonts-zap/.

@willmcgugan
Copy link
Collaborator

Textual is quite configurable, so it would be quite doable to find a set of styles that work well on the Linux console.

We have an update in the pipeline to allow for ansi-colors. I suspect that most of the poor visuals are due to downsampling truecolor RGB to 256 / 156 colors. We could also have a mode to pick characters for borders that work better.

In short, there is a lot that could be done.

Can I ask who you are working for?

@jsatchell
Copy link
Author

jsatchell commented Sep 19, 2024 via email

@Lunchmeat8
Copy link

QinetiQ Im going to check them out.

@jsatchell
Copy link
Author

Further observations. I have tried the ansi_colors switch from version 0.80.0 onwards, and it doesn't help with my specific problems.

I can improve things a lot by fiddling with the styling, for example by setting the scrollbar-color to something in the VGA color set, it is at least visible - used yellow, which looks weird, but at least has contrast.

My guess that the problem is to do with line drawing characters is wrong; the unicode mappings on the two fonts I tried are good enough that setting border: solid works. If I use zap-light18, I can even mix border: double and border: single as distinct.

Many of the cosmetic glitches can then be improved by setting border: solid on a variety of widgets. My residual glitches come down to the fact that the block drawing characters of different heights and widths are not in any of the console fonts I have tried. This means that border: tall, which is used at the top and bottom of buttons in the default style, comes up as missing glyphs. Setting a border: solid on Button draws an outline, which looks OK, except for variant buttons where the background extends outside the border.

There is a similar problem with the scrollbar, which uses the variable height or width blocks in search of extra position resolution for the thumb. This is hardcoded as class variables in scrollbar.py.

As this is python, I could presumably replace the existing values with my own array, and trade smooth scrolling for reduced artefacts.

Beyond that, maybe one of 512 glyph fonts from the Zap people has more of the block characters, which might solve things at the expense of loosing bright / normal colour distinctions. Alternatively, and this is heading into the realm of fantasy land, are there ansi sequences for switching between fonts? Could one use a special font loaded with blocks and the like for rendering the cosmetics, and swap back to normal font for the Latin characters?

@jsatchell
Copy link
Author

The 512 glyph Zap fonts have lots more accented, Greek and Cyrillic characters, not block drawing.
I have found a PSF font with block drawing; psf-unifont. It is primarily intended to support APL (oddball langauge, originally from IBM, with single character operators for vector, matrix and tensor operations). It doesn't have many accented characters, but probably enough western europen languages. The downside is that because it is a 512 glyph font, you only get 8 colors, and that really messes up the rendering for light mode! In dark mode, it mostly looks OK.
I still need to set scrollbar-color to something, but that is the only thing.

So my suggestion is a documentation fix in the short term: Where you discuss using various terminals, and their short comings, suggest the psf-unifont package for the Linux console, and that because there are only 8 colors, you need to make some harsh style choices, and in particular to set scrollbar-color to something different from the background.
Going forward, when theming is a thing, an eight color theme would give some of this out of the box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants