dylanaraps / dylanaraps/dfm

SIXEL previews fail when using the full terminal dimensions

Open
#12 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C
Stars
93
Forks
7
Avg merge
14h 52m
Merged PRs (30d)
1

Description

# SIXEL previews fail with large terminal dimensions

## Problem

This is related to commit [c4d442e](https://github.com/dylanaraps/dfm/commit/c4d442e6b87d2eb7d464e7d135fa881aa111c818), which added SIXEL margins following [PR #10](https://github.com/dylanaraps/dfm/pull/10).

Sorry for bringing this up again. I initially thought the margin change had fully resolved the SIXEL preview issue, but further testing with different images revealed this additional case.

The margins fixed image clipping, but I found another issue with larger terminal dimensions: some images do not render when `dfm` passes the full terminal size to `chafa`.

My setup:

- xterm 410
- tmux 3.7b
- chafa 1.18.2
- SIXEL enabled in xterm and tmux

The affected files were normal PNG and JPEG images, including screenshots with dimensions around 1366x768 and 1370x768.

The command generated by `dfm` used a size such as:

```text
-s 188x43
```

The same images rendered correctly when limiting the size manually:

```bash
chafa --format=sixel -s 100x20 image.png
```

## Downstream patch used for testing

I tested the following downstream SlackBuild patch successfully:

```diff
-#define DFM_IMG_CHAFA_CMD "chafa", "--format=sixel", "-s"
+#define DFM_IMG_CHAFA_CMD "chafa", "--format=sixels", "--animate=off", \
+ "--colors=256", "--dither=ordered", "--margin-bottom=1", \
+ "--margin-right=1", "-s"
```

The patch also limits the dimensions passed by `dfm`:

```diff
-str_push_u32(&p->io, p->col);
+str_push_u32(&p->io, MIN(p->col, 100));
str_push_c(&p->io, 'x');
-str_push_u32(&p->io, p->row - 1);
+str_push_u32(&p->io, MIN(p->row - 1, 20));
```

With these changes, the affected PNG and JPEG images render correctly in
xterm + tmux using SIXEL output.

## Workaround

Limiting the SIXEL preview size to approximately `100x20` terminal cells makes the previews work reliably.

Would it make sense for `dfm` to cap the SIXEL preview dimensions, or otherwise account for terminal SIXEL graphic-size limits?

Contributor guide

No contributing guide indexed for this repository

Research direction

Locate the SIXEL/chafa command construction and the code that appends p->col and p->row - 1 to the size argument. Reproduce the failure with large terminal dimensions using the reported xterm, tmux, and chafa setup, then compare it with the approximately 100x20 workaround. Done means the affected PNG and JPEG previews render reliably with SIXEL without image clipping.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.