Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Is there a way to guarantee an empty blank row before sixels? #304

Answered by hpjansson
ravachol asked this question in Q&A
Discussion options

Is there a way to get a guaranteed one-row blank top line regardless of terminal size?

Or is there’s a way to force full baseHeight usage or a way to query the actual printed height?

printable = convert_image(
pixels,
pix_width,
pix_height,
pix_width * n_channels, // Row stride
CHAFA_PIXEL_RGBA8_UNASSOCIATED, // Correct pixel format
correctedWidth,
baseHeight,
cell_width,
cell_height);

When printing this at row 2 it ends up at row 1 for certain window sizes.

You must be logged in to vote

Chafa doesn't output any positioning seqs in the image data itself, so this seems like an issue where the terminal thinks the image overshoots the lower edge of the visible area and decides to offset it for some reason. You could view this as a terminal bug (what does foot do?), but when I think about it, I'm not sure that the desired behavior is actually specified anywhere. If this happens with other terminal emulators too, I suggest bringing it up in #192 or a new ticket with konsole and foot's authors and a few others.

I think the most reasonable behavior would be to allow the image to overshoot and just crop it at the edge, especially as sixel images are forced to overshoot by a bit (...

Replies: 3 comments 5 replies

Comment options

I'm not sure I understand the question. You print the image at cell offset 2, but it gets placed one row above the cursor? Do you have an example? Pictures/diagrams would help. If you want exact pixel dimensions, you should be able to do that using ChafaPlacement and CHAFA_TUCK_SHRINK_TO_FIT with an image that's the same size as the calculated pixel extent cell_dim * n_cells on each axis.

You must be logged in to vote
1 reply
Comment options

If you want to prevent scrolling when printing a full-height image, there are a couple of ways to do it. One is to emit CHAFA_TERM_SEQ_SET_SIXEL_ADVANCE_RIGHT at the start of the program. Terminals will leave the cursor to the right of the image instead of below or on the last row, and there's more consistency in this mode than with advance-down. See also #192.

Comment options

Well the issue I'm encountering is that at some terminal sizes, the image is printed on the first row, when I have instructed it to print on the second row. This makes the cover jump in and out of position as you resize the app.

Screenshot_20251022_055250 Screenshot_20251022_055306

same code for both (row is 2):

 float aspect_ratio_correction = (float)cell_height / (float)cell_width;
 int correctedWidth = (int)(baseHeight * aspect_ratio_correction);
 if (term_size.width_cells > 0 && correctedWidth > term_size.width_cells)
 {
 setErrorMessage("Invalid terminal dimensions.\n");
 return;
 }
 if (term_size.height_cells > 0 && baseHeight > term_size.height_cells)
 {
 setErrorMessage("Invalid terminal dimensions.\n");
 return;
 }
 // Convert image to a printable string using Chafa
 printable = convert_image(
 pixels,
 pix_width,
 pix_height,
 pix_width * n_channels, // Row stride
 CHAFA_PIXEL_RGBA8_UNASSOCIATED, // Correct pixel format
 correctedWidth,
 baseHeight,
 cell_width,
 cell_height);
 // Ensure the string is null-terminated
 g_string_append_c(printable, '0円');
 // Split the printable string into lines
 const gchar *delimiters = "\n";
 gchar **lines = g_strsplit(printable->str, delimiters, -1);
 // Print each line with indentation
 for (int i = 0; lines[i] != NULL; i++)
 {
 printf("033円[%d;%dH", row + i, col);
 printf("%s", lines[i]);
 fflush(stdout);
 }
 // Free allocated memory
 g_strfreev(lines);
 g_string_free(printable, TRUE);
You must be logged in to vote
4 replies
Comment options

Chafa doesn't output any positioning seqs in the image data itself, so this seems like an issue where the terminal thinks the image overshoots the lower edge of the visible area and decides to offset it for some reason. You could view this as a terminal bug (what does foot do?), but when I think about it, I'm not sure that the desired behavior is actually specified anywhere. If this happens with other terminal emulators too, I suggest bringing it up in #192 or a new ticket with konsole and foot's authors and a few others.

I think the most reasonable behavior would be to allow the image to overshoot and just crop it at the edge, especially as sixel images are forced to overshoot by a bit (always multiple of 6 pixels tall).

Answer selected by ravachol
Comment options

It actually prints the empty row correctly in foot and kitty. So it might be konsole behavior.

Comment options

Ok - probably best to file it as a bug against konsole then.

Comment options

Comment options

I can solve it by making the image one row smaller than I want, too but then things don't get aligned properly with the rest of the elements.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /