diff options
Diffstat (limited to '')
| -rw-r--r-- | st.c | 34 |
1 files changed, 20 insertions, 14 deletions
| @@ -606,24 +606,31 @@ dump(char c) { | |||
| 606 | 606 | ||
| 607 | void | 607 | void |
| 608 | ttyread(void) { | 608 | ttyread(void) { |
| 609 | char buf[BUFSIZ], *ptr; | 609 | static char buf[BUFSIZ]; |
| 610 | static int buflen = 0; | ||
| 611 | char *ptr; | ||
| 610 | char s[UTF_SIZ]; | 612 | char s[UTF_SIZ]; |
| 611 | int ret, br; | 613 | int charsize; /* size of utf8 char in bytes */ |
| 612 | static int buflen = 0; | 614 | long utf8c; |
| 613 | long u; | 615 | int ret; |
| 614 | 616 | ||
| 617 | /* append read bytes to unprocessed bytes */ | ||
| 615 | if((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0) | 618 | if((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0) |
| 616 | die("Couldn't read from shell: %s\n", SERRNO); | 619 | die("Couldn't read from shell: %s\n", SERRNO); |
| 617 | else { | 620 | |
| 618 | buflen += ret; | 621 | /* process every complete utf8 char */ |
| 619 | for(ptr=buf; buflen>=UTF_SIZ||isfullutf8(ptr,buflen); buflen-=br) { | 622 | buflen += ret; |
| 620 | br = utf8decode(ptr, &u); | 623 | ptr = buf; |
| 621 | utf8encode(&u, s); | 624 | while(buflen >= UTF_SIZ || isfullutf8(ptr,buflen)) { |
| 622 | tputc(s); | 625 | charsize = utf8decode(ptr, &utf8c); |
| 623 | ptr += br; | 626 | utf8encode(&utf8c, s); |
| 624 | } | 627 | tputc(s); |
| 625 | memcpy(buf, ptr, buflen); | 628 | ptr += charsize; |
| 629 | buflen -= charsize; | ||
| 626 | } | 630 | } |
| 631 | |||
| 632 | /* keep any uncomplete utf8 char for the next call */ | ||
| 633 | memcpy(buf, ptr, buflen); | ||
| 627 | } | 634 | } |
| 628 | 635 | ||
| 629 | void | 636 | void |
| @@ -1774,7 +1781,6 @@ kpress(XEvent *ev) { | |||
| 1774 | /* 3. X lookup */ | 1781 | /* 3. X lookup */ |
| 1775 | default: | 1782 | default: |
| 1776 | if(len > 0) { | 1783 | if(len > 0) { |
| 1777 | buf[sizeof(buf)-1] = '\0'; | ||
| 1778 | if(meta && len == 1) | 1784 | if(meta && len == 1) |
| 1779 | ttywrite("\033", 1); | 1785 | ttywrite("\033", 1); |
| 1780 | ttywrite(buf, len); | 1786 | ttywrite(buf, len); |
