Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implement SIXEL types with custom option#3092

Open
SapphirusBeryl wants to merge 5 commits intoranger:masterfrom
SapphirusBeryl:feature/sixel-chafa-custom
Open

Implement SIXEL types with custom option#3092
SapphirusBeryl wants to merge 5 commits intoranger:masterfrom
SapphirusBeryl:feature/sixel-chafa-custom

Conversation

@SapphirusBeryl
Copy link

Modifies the SixelImageDisplayer class to provide multiple processor backends as well as allowing the user to specify their own via setting a command-line option via sixel_custom in rc.conf.

ISSUE TYPE

  • Improvement/feature implementation

RUNTIME ENVIRONMENT

  • Operating system and version: Arch Linux
  • Terminal emulator and version: alacritty 0.16.0-dev (814e8fef) (sixel patchset)
  • Python version: Python version: 3.13.3 (main, Apr 9 2025, 07:44:25) [GCC 14.2.1 20250207]
  • Ranger version/commit: ranger-master v1.9.3-794-gcc8fd2ac
  • Locale: en_CA.UTF-8

CHECKLIST

  • The CONTRIBUTING document has been read [REQUIRED]
  • All changes follow the code style [REQUIRED]
  • All new and existing tests pass [REQUIRED]
  • Changes require config files to be updated
    • Config files have been updated
  • Changes require documentation to be updated
    • Documentation has been updated
  • Changes require tests to be updated
    • Tests have been updated

DESCRIPTION

Provides the ability to set multiple different SIXEL processor types, as well as two new processor types in addition to imagemagick.

A user may specify one of the following option types:

  • imagemagick
  • chafa
  • custom

imagemagick is set as the default to preserve the current behaviour.

Custom option in particular allows the user to set a custom command-line to utilize
their own SIXEL processor to output into the terminal. That can be set with sixel_custom.

String substitution options are provided to allow the user to specify a path, width&height, etc..

MOTIVATION AND CONTEXT

The inability to set a different SIXEL processor for use with ranger.

Since imagemagick is noticeably slow when navigating through directories of large images (e.g. background wallpapers, photographs, etc.), I decided to implement support for multiple processor types.

chafa is noticeably faster by comparison and doesn't require OpenCL acceleration to work.

Since a custom option is also desirable, I decided to take a shot at that. Input is very much welcome on the approach I've taken. Not exactly sure if string substitution with str.format(..) is the appropriate way to approach this problem. It's simple, however, and takes up almost no footprint.

Solves and fixes these issues with #2466 having been merged:

TESTING

Doesn't affect anything other than the SIXEL image preview functionality.

Both imagemagick, chafa, and the custom options have been tested as working.

Modifies the SixelImageDisplayer class to provide multiple processor
backends as well as allowing the user to specify their own via setting
a command-line option via `sixel_custom` in rc.conf.

Implements a new enum type `SixelType(StrEnum)` to define a sixel type.
Symbols example is broken, so demonstrate custom option with colour
transformations, instead.
Pass `--passthrough none` to allow chafa to render sixels within
ranger under tmux. There's no regression in functionality found in
other terminals as a result. e.g. foot
@SapphirusBeryl SapphirusBeryl force-pushed the feature/sixel-chafa-custom branch 2 times, most recently from 6a8bbf5 to dc58b5c Compare May 15, 2025 23:05
Since chafa moves the cursor around when writing to stdout, obtain the
cursor position from curses, then hide the cursor and reset to a proper
position. This fixes a bug wherein selecting the last item results in
rendering the selection at an arbitrary position in the terminal.
Copy link
Member

@toonn toonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, though I haven't actually reviewed it yet, just wanted to comment that changing the default is on the table if Chafa actually improves usability considerably.

@SapphirusBeryl SapphirusBeryl force-pushed the feature/sixel-chafa-custom branch from 80ca63f to eda3789 Compare May 16, 2025 22:33
@SapphirusBeryl
Copy link
Author

I like this, though I haven't actually reviewed it yet, just wanted to comment that changing the default is on the table if Chafa actually improves usability considerably.

I've noticed a considerable difference in usability with chafa, though I wouldn't want to necessarily impose a one-size-fits-all solution for SIXEL, since there tends to be a lot of variability in implementation between different terminal emulators and multiplexers as well as the processor libraries/applications.

@SapphirusBeryl SapphirusBeryl force-pushed the feature/sixel-chafa-custom branch from eda3789 to 2bb78d9 Compare May 17, 2025 03:11
Workaround for deadlock regression with chafa 1.16.0-1.16.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants