diff --git a/st.c b/st.c index 2594c65..66570a0 100644 --- a/st.c +++ b/st.c @@ -137,6 +137,7 @@ enum term_mode { MODE_MOUSEMANY = 1 << 18, MODE_BRCKTPASTE = 1 << 19, MODE_PRINT = 1 << 20, + MODE_UTF8 = 1 << 21, MODE_MOUSE = MODE_MOUSEBTN|MODE_MOUSEMOTION|MODE_MOUSEX10\ |MODE_MOUSEMANY, }; @@ -560,6 +561,8 @@ typedef struct { static Fontcache frc[16]; static int frclen = 0; +#include "sixel.c" + ssize_t xwrite(int fd, const char *s, size_t len) { @@ -1481,15 +1484,22 @@ ttyread(void) /* process every complete utf8 char */ buflen += ret; ptr = buf; - while ((charsize = utf8decode(ptr, &unicodep, buflen))) { - tputc(unicodep); - ptr += charsize; - buflen -= charsize; + if (term.mode & MODE_UTF8) { + while ((charsize = utf8decode(ptr, &unicodep, buflen))) { + if (sixel_mode) + tputsixelc(unicodep); + else + tputc(unicodep); + ptr += charsize; + buflen -= charsize; + } + /* keep any uncomplete utf8 char for the next call */ + memmove(buf, ptr, buflen); + } else { + while (buflen-- > 0) + tputc(*ptr++ & 0xFF); } - /* keep any uncomplete utf8 char for the next call */ - memmove(buf, ptr, buflen); - return ret; } @@ -1656,7 +1666,7 @@ treset(void) term.tabs[i] = 1; term.top = 0; term.bot = term.row - 1; - term.mode = MODE_WRAP; + term.mode = MODE_WRAP|MODE_UTF8; memset(term.trantbl, CS_USA, sizeof(term.trantbl)); term.charset = 0; @@ -2929,11 +2939,13 @@ tputc(Rune u) int width, len; Glyph *gp; - control = ISCONTROL(u); - len = utf8encode(u, c); - if (!control && (width = wcwidth(u)) == -1) { - memcpy(c, "\357\277\275", 4); /* UTF_INVALID */ - width = 1; + if (term.mode & UTF8) { + control = ISCONTROL(u); + len = utf8encode(u, c); + if (!control && (width = wcwidth(u)) == -1) { + memcpy(c, "\357\277\275", 4); /* UTF_INVALID */ + width = 1; + } } if (IS_SET(MODE_PRINT)) @@ -2950,6 +2962,8 @@ tputc(Rune u) ISCONTROLC1(u)) { term.esc &= ~(ESC_START|ESC_STR); term.esc |= ESC_STR_END; + } else if (sixel_mode) { + tpuc_sixel(); } else if (strescseq.len + len < sizeof(strescseq.buf) - 1) { memmove(&strescseq.buf[strescseq.len], c, len); strescseq.len += len;