Skip to content

Add Sixel graphics device support - #223

Open
RestlessTail wants to merge 6 commits into
r-lib:mainfrom
RestlessTail:sixel-device
Open

RestlessTail wants to merge 6 commits into
r-lib:mainfrom
RestlessTail:sixel-device

Conversation

@RestlessTail

@RestlessTail RestlessTail commented Nov 14, 2026 •

Copy link
Copy Markdown

Fix #221

This PR adds a new agg_sixel() graphics device to ragg, enabling R graphics to be rendered directly to the terminal using the SIXEL bitmap graphics protocol.

The output is written to standard output when the graphics device is closed with dev.off(). This allows plots to be displayed in terminal emulators that support SIXEL graphics.

Implementation Details

  • Add a new agg_sixel() graphics device.
  • Implement a self-contained SIXEL encoder in a single header-only C++ file, without introducing external dependencies such as libsixel.
  • Write the encoded graphics to standard output when the device is closed.
  • Register and export the new device, with corresponding documentation.

Usage

agg_sixel()
plot(sin, -pi, 2 * pi)
dev.off()

The resulting SIXEL data is written to standard output and can be rendered by compatible terminal emulators.

Output Handling

The SIXEL output is written directly to stdout using fwrite(), since it consists of terminal escape sequences and should ideally be interpreted by a terminal emulator rather than displayed as text in an R GUI console.

This triggers a devtools::check() NOTE about writing to stdout from compiled code. I'm not entirely sure whether there is a more appropriate R API for this use case, so I'd appreciate your advice on whether this approach is acceptable or if there is a better alternative.

Testing

Verified on the following terminals:

Platform Terminal Emulator Supports SIXEL1 Result
Windows Windows Terminal Yes Succeeded
Windows WezTerm2 Yes Succeeded
Windows VS Code3 Yes Succeeded
Windows Alacritty No Ignored
Ubuntu Konsole Yes Succeeded
Ubuntu WezTerm Yes Succeeded
Ubuntu XTerm4 Yes Succeeded
Ubuntu GNOME Terminal No Ignored
Ubuntu VS Code Yes Succeeded
  1. SIXEL support information is based on https://www.arewesixelyet.com/
  2. Requires the Nightly build of WezTerm
  3. The following options need to be enabled: enableImages, gpuAcceleration, and windowsUseConptyDll (only on Windows)
  4. XTerm needs to be launched with xterm -ti 340

@RestlessTail

Copy link
Copy Markdown
Author

Thanks for adding the tests!

There is one compatibility issue I'd like to discuss. The implementation currently uses a few C++17 features (structured bindings and try_emplace), but oldrel-4 (R 4.2) defaults to C++14, so the corresponding CI job fails to compile.

I'm considering rewriting those parts to keep C++14 compatibility rather than raising the required C++ standard. Would you prefer that approach?

Also, just for context, c7d1f2c contains temporary CI workarounds (installing an unreleased dependency via Remotes: and enabling manual workflow triggers). I kept them in a separate commit so they can be reverted independently once they're no longer needed.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

Perhaps add a SIXEL output device?

2 participants