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

Add support for Sixel graphics #547

Open
grynspan opened this issue Jul 17, 2024 · 6 comments
Open

Add support for Sixel graphics #547

grynspan opened this issue Jul 17, 2024 · 6 comments
Assignees
Labels
command-line experience enhancements to the command line interface enhancement New feature or request help wanted Extra attention is needed linux 🐧 Linux support (all distros) tools integration Integration of swift-testing into tools/IDEs

Comments

@grynspan
Copy link
Contributor

On terminal apps that support it (mainly Linux), we could add support for Sixel graphics to improve the display of test diamond symbols from swift test. On macOS, when SF Symbols is installed, we get nice Xcode-like test diamond glyphs, but on other platforms we must always use fallback Unicode characters because the SF Symbols fallback logic on macOS is platform-specific.

@grynspan
Copy link
Contributor Author

grynspan commented Jul 17, 2024

Windows Terminal support for Sixel is tracked here.

Actually, looks like it's been recently implemented!

@grynspan grynspan self-assigned this Jul 17, 2024
@grynspan grynspan added enhancement New feature or request help wanted Extra attention is needed tools integration Integration of swift-testing into tools/IDEs linux 🐧 Linux support (all distros) labels Jul 17, 2024
@j4james
Copy link

j4james commented Jul 20, 2024

Another possible solution you might want to consider for this is Dynamically Redefinable Character Sets. For example this sequence defines a character set with the < and > characters representing the two halves of a diamond glyph.

printf "\eP0;28;0;10;0;2;16;0{ @????_ow{}}/??EN^xpbFN/??????@BFF;??????????/??????????/??????????;}}{wo_????/Fbpw{^NE??/FFB@??????\e\\"

And from then on you can output the diamond with a sequence like this:

printf "\e( @<>\e(B"

It's not as widely supported as Sixel graphics, especially not on Linux, but it should at least work on mlterm. On the plus side, it's easier to use than Sixel, you can color it just like you would any other text, and it should automatically fallback to showing <> when DRCS is not supported, which doesn't seem that unreasonable.

This is an example of what it looks like in Windows Terminal:
image

@grynspan
Copy link
Contributor Author

It's a possibility, however:

It's not as widely supported as Sixel graphics, especially not on Linux

That would be a pretty strong argument against it! While Sixel hardly has what I'd consider widespread support, it does work with Konsole and recent Windows Terminal versions. (As I understand it, GNOME Terminal does not support either Sixel or DRCs.)

@j4james
Copy link

j4james commented Jul 20, 2024

That would be a pretty strong argument against it!

I don't disagree. My concern was that you might find Sixel impossible to use in the way you need it (I've not actually used swift-testing, so perhaps I've misunderstood your requirements). But if you can make it work, that's great. If not, DRCS may be better than nothing.

As I understand it, GNOME Terminal does not support either Sixel or DRCs.

Correct. Sixel will likely be supported at some point though. That's waiting on the vte library, which has actually had Sixel as a compile time option for several years now, but the maintainer doesn't consider it good enough to be released yet.

@grynspan
Copy link
Contributor Author

There are two use cases for Sixel in Swift Testing that I'm thinking about:

  1. Per-message symbols indicating that a test passed, failed, etc. We currently use Unicode characters for this, but the effectiveness of characters used is dependent on the terminal font.
  2. Post-run output like code coverage flame graphs or the like, where text mode wouldn't provide sufficient resolution. (We could also use available system libraries to just output an image to disk for this sort of thing, but that's boring!)

@j4james
Copy link

j4james commented Jul 20, 2024

Per-message symbols indicating that a test passed, failed, etc.

This is the case I thought would be tricky, because you assumedly need the image to align with the text content. On a real VT340 you would just create an image that is 10x20, and that would fill exactly one text cell (the same is true of most commercial terminal emulators). But Linux terminals typically require you to query them first to find out how big to make the image (and pray the user doesn't change the font size halfway through a test run).

The second problem comes in predicting where the cursor will end up after you've output the image. There's a standard way that this should be expected work, but in practice most terminals tend to invent their own rules for cursor positioning, so the exact behavior will differ from one terminal to another. And if you're writing content at the bottom of the screen, this can often end up triggering a scroll when you wouldn't expect it to.

All of these issues are probably solvable, but you can see what I meant when I said DRCS was easier!

Post-run output like code coverage flame graphs or the like

This is definitely a good use case for Sixel.

@grynspan grynspan added the command-line experience enhancements to the command line interface label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
command-line experience enhancements to the command line interface enhancement New feature or request help wanted Extra attention is needed linux 🐧 Linux support (all distros) tools integration Integration of swift-testing into tools/IDEs
Projects
None yet
Development

No branches or pull requests

2 participants