-
Notifications
You must be signed in to change notification settings - Fork 107
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
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
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
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_055306same 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);
Beta Was this translation helpful? Give feedback.
All reactions
-
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).
Beta Was this translation helpful? Give feedback.
All reactions
-
It actually prints the empty row correctly in foot and kitty. So it might be konsole behavior.
Beta Was this translation helpful? Give feedback.
All reactions
-
Ok - probably best to file it as a bug against konsole then.
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
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.
Beta Was this translation helpful? Give feedback.