sixel: refactor the sixel display mode (#142)

This does not change the current behavior of SDM.
This commit is contained in:
veltza 2024-07-05 12:30:55 +03:00 committed by GitHub
parent 546dd288c0
commit 48c85cdcf5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

48
st.c
View File

@ -220,6 +220,9 @@ static void tsetattr(const int *, int);
static void tsetchar(Rune, const Glyph *, int, int); static void tsetchar(Rune, const Glyph *, int, int);
static void tsetdirt(int, int); static void tsetdirt(int, int);
static void tsetscroll(int, int); static void tsetscroll(int, int);
#if SIXEL_PATCH
static inline void tsetsixelattr(Line line, int x1, int x2);
#endif // SIXEL_PATCH
static void tswapscreen(void); static void tswapscreen(void);
static void tsetmode(int, int, const int *, int); static void tsetmode(int, int, const int *, int);
static int twrite(const char *, int, int); static int twrite(const char *, int, int);
@ -1149,6 +1152,15 @@ tsetdirtattr(int attr)
} }
} }
#if SIXEL_PATCH
void
tsetsixelattr(Line line, int x1, int x2)
{
for (; x1 <= x2; x1++)
line[x1].mode |= ATTR_SIXEL;
}
#endif // SIXEL_PATCH
void void
tfulldirt(void) tfulldirt(void)
{ {
@ -2592,7 +2604,7 @@ strhandle(void)
}; };
#if SIXEL_PATCH #if SIXEL_PATCH
ImageList *im, *newimages, *next, *tail; ImageList *im, *newimages, *next, *tail;
int i, x, y, x1, y1, x2, y2, numimages; int i, x1, y1, x2, y2, numimages;
int cx, cy; int cx, cy;
Line line; Line line;
#if SCROLLBACK_PATCH || REFLOW_PATCH #if SCROLLBACK_PATCH || REFLOW_PATCH
@ -2736,37 +2748,41 @@ strhandle(void)
} else { } else {
term.images = newimages; term.images = newimages;
} }
x2 = MIN(x2, term.col); x2 = MIN(x2, term.col) - 1;
if (IS_SET(MODE_SIXEL_SDM)) {
/* Sixel display mode: put the sixel in the upper left corner of
* the screen, disable scrolling (the sixel will be truncated if
* it is too long) and do not change the cursor position. */
for (i = 0, im = newimages; im; im = next, i++) { for (i = 0, im = newimages; im; im = next, i++) {
next = im->next; next = im->next;
#if SCROLLBACK_PATCH || REFLOW_PATCH
scr = IS_SET(MODE_ALTSCREEN) ? 0 : term.scr;
#endif // SCROLLBACK_PATCH
if (IS_SET(MODE_SIXEL_SDM)) {
if (i >= term.row) { if (i >= term.row) {
delete_image(im); delete_image(im);
continue; continue;
} }
im->y = i + scr; im->y = i + scr;
line = term.line[i]; tsetsixelattr(term.line[i], x1, x2);
} else {
im->y = term.c.y + scr;
line = term.line[term.c.y];
}
for (x = im->x; x < x2; x++) {
line[x].mode |= ATTR_SIXEL;
}
term.dirty[MIN(im->y, term.row-1)] = 1; term.dirty[MIN(im->y, term.row-1)] = 1;
if (!IS_SET(MODE_SIXEL_SDM) && i < numimages-1) { }
} else {
for (i = 0, im = newimages; im; im = next, i++) {
next = im->next;
#if SCROLLBACK_PATCH || REFLOW_PATCH
scr = IS_SET(MODE_ALTSCREEN) ? 0 : term.scr;
#endif // SCROLLBACK_PATCH
im->y = term.c.y + scr;
tsetsixelattr(term.line[term.c.y], x1, x2);
term.dirty[MIN(im->y, term.row-1)] = 1;
if (i < numimages-1) {
im->next = NULL; im->next = NULL;
tnewline(0); tnewline(0);
im->next = next; im->next = next;
} }
} }
/* if mode 8452 is set, sixel scrolling leaves cursor to right of graphic */ /* if mode 8452 is set, sixel scrolling leaves cursor to right of graphic */
if (!IS_SET(MODE_SIXEL_SDM) && IS_SET(MODE_SIXEL_CUR_RT)) if (IS_SET(MODE_SIXEL_CUR_RT))
term.c.x = MIN(term.c.x + newimages->cols, term.col-1); term.c.x = MIN(term.c.x + newimages->cols, term.col-1);
} }
}
#endif // SIXEL_PATCH #endif // SIXEL_PATCH
#if SYNC_PATCH #if SYNC_PATCH
/* https://gitlab.com/gnachman/iterm2/-/wikis/synchronized-updates-spec */ /* https://gitlab.com/gnachman/iterm2/-/wikis/synchronized-updates-spec */