diff options
| author | Devin J. Pohly <djpohly@gmail.com> | 2018-02-22 00:42:23 -0600 |
|---|---|---|
| committer | Devin J. Pohly <djpohly@gmail.com> | 2018-02-25 21:53:24 -0600 |
| commit | 52d6fb1ab1f7d41839edebb63c3408578cd44e3c (patch) | |
| tree | d33c81682f014f242b1c4d138ede71d90ca39b8e | |
| parent | cfc7acdfd923924ae150a32061fb95987697b159 (diff) | |
| download | st-52d6fb1ab1f7d41839edebb63c3408578cd44e3c.tar.gz st-52d6fb1ab1f7d41839edebb63c3408578cd44e3c.zip | |
Move terminal echo logic into st.c
The only thing differentiating ttywrite and ttysend was the potential
for echo; make this a parameter and remove ttysend.
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
| -rw-r--r-- | st.c | 23 | ||||
| -rw-r--r-- | st.h | 3 | ||||
| -rw-r--r-- | x.c | 18 |
3 files changed, 19 insertions, 25 deletions
| @@ -784,12 +784,15 @@ ttyread(void) | |||
| 784 | } | 784 | } |
| 785 | 785 | ||
| 786 | void | 786 | void |
| 787 | ttywrite(const char *s, size_t n) | 787 | ttywrite(const char *s, size_t n, int may_echo) |
| 788 | { | 788 | { |
| 789 | fd_set wfd, rfd; | 789 | fd_set wfd, rfd; |
| 790 | ssize_t r; | 790 | ssize_t r; |
| 791 | size_t lim = 256; | 791 | size_t lim = 256; |
| 792 | 792 | ||
| 793 | if (may_echo && IS_SET(MODE_ECHO)) | ||
| 794 | twrite(s, n, 1); | ||
| 795 | |||
| 793 | /* | 796 | /* |
| 794 | * Remember that we are using a pty, which might be a modem line. | 797 | * Remember that we are using a pty, which might be a modem line. |
| 795 | * Writing too much will clog the line. That's why we are doing this | 798 | * Writing too much will clog the line. That's why we are doing this |
| @@ -841,14 +844,6 @@ write_error: | |||
| 841 | } | 844 | } |
| 842 | 845 | ||
| 843 | void | 846 | void |
| 844 | ttysend(char *s, size_t n) | ||
| 845 | { | ||
| 846 | ttywrite(s, n); | ||
| 847 | if (IS_SET(MODE_ECHO)) | ||
| 848 | twrite(s, n, 1); | ||
| 849 | } | ||
| 850 | |||
| 851 | void | ||
| 852 | ttyresize(int tw, int th) | 847 | ttyresize(int tw, int th) |
| 853 | { | 848 | { |
| 854 | struct winsize w; | 849 | struct winsize w; |
| @@ -1570,7 +1565,7 @@ csihandle(void) | |||
| 1570 | break; | 1565 | break; |
| 1571 | case 'c': /* DA -- Device Attributes */ | 1566 | case 'c': /* DA -- Device Attributes */ |
| 1572 | if (csiescseq.arg[0] == 0) | 1567 | if (csiescseq.arg[0] == 0) |
| 1573 | ttywrite(vtiden, strlen(vtiden)); | 1568 | ttywrite(vtiden, strlen(vtiden), 0); |
| 1574 | break; | 1569 | break; |
| 1575 | case 'C': /* CUF -- Cursor <n> Forward */ | 1570 | case 'C': /* CUF -- Cursor <n> Forward */ |
| 1576 | case 'a': /* HPR -- Cursor <n> Forward */ | 1571 | case 'a': /* HPR -- Cursor <n> Forward */ |
| @@ -1698,7 +1693,7 @@ csihandle(void) | |||
| 1698 | if (csiescseq.arg[0] == 6) { | 1693 | if (csiescseq.arg[0] == 6) { |
| 1699 | len = snprintf(buf, sizeof(buf),"\033[%i;%iR", | 1694 | len = snprintf(buf, sizeof(buf),"\033[%i;%iR", |
| 1700 | term.c.y+1, term.c.x+1); | 1695 | term.c.y+1, term.c.x+1); |
| 1701 | ttywrite(buf, len); | 1696 | ttywrite(buf, len, 0); |
| 1702 | } | 1697 | } |
| 1703 | break; | 1698 | break; |
| 1704 | case 'r': /* DECSTBM -- Set Scrolling Region */ | 1699 | case 'r': /* DECSTBM -- Set Scrolling Region */ |
| @@ -1916,7 +1911,7 @@ iso14755(const Arg *arg) | |||
| 1916 | (*e != '\n' && *e != '\0')) | 1911 | (*e != '\n' && *e != '\0')) |
| 1917 | return; | 1912 | return; |
| 1918 | 1913 | ||
| 1919 | ttysend(uc, utf8encode(utf32, uc)); | 1914 | ttywrite(uc, utf8encode(utf32, uc), 1); |
| 1920 | } | 1915 | } |
| 1921 | 1916 | ||
| 1922 | void | 1917 | void |
| @@ -2129,7 +2124,7 @@ tcontrolcode(uchar ascii) | |||
| 2129 | case 0x99: /* TODO: SGCI */ | 2124 | case 0x99: /* TODO: SGCI */ |
| 2130 | break; | 2125 | break; |
| 2131 | case 0x9a: /* DECID -- Identify Terminal */ | 2126 | case 0x9a: /* DECID -- Identify Terminal */ |
| 2132 | ttywrite(vtiden, strlen(vtiden)); | 2127 | ttywrite(vtiden, strlen(vtiden), 0); |
| 2133 | break; | 2128 | break; |
| 2134 | case 0x9b: /* TODO: CSI */ | 2129 | case 0x9b: /* TODO: CSI */ |
| 2135 | case 0x9c: /* TODO: ST */ | 2130 | case 0x9c: /* TODO: ST */ |
| @@ -2201,7 +2196,7 @@ eschandle(uchar ascii) | |||
| 2201 | } | 2196 | } |
| 2202 | break; | 2197 | break; |
| 2203 | case 'Z': /* DECID -- Identify Terminal */ | 2198 | case 'Z': /* DECID -- Identify Terminal */ |
| 2204 | ttywrite(vtiden, strlen(vtiden)); | 2199 | ttywrite(vtiden, strlen(vtiden), 0); |
| 2205 | break; | 2200 | break; |
| 2206 | case 'c': /* RIS -- Reset to inital state */ | 2201 | case 'c': /* RIS -- Reset to inital state */ |
| 2207 | treset(); | 2202 | treset(); |
| @@ -176,8 +176,7 @@ void tsetdirtattr(int); | |||
| 176 | void ttynew(char *, char *, char **); | 176 | void ttynew(char *, char *, char **); |
| 177 | size_t ttyread(void); | 177 | size_t ttyread(void); |
| 178 | void ttyresize(int, int); | 178 | void ttyresize(int, int); |
| 179 | void ttysend(char *, size_t); | 179 | void ttywrite(const char *, size_t, int); |
| 180 | void ttywrite(const char *, size_t); | ||
| 181 | 180 | ||
| 182 | void resettitle(void); | 181 | void resettitle(void); |
| 183 | 182 | ||
| @@ -390,7 +390,7 @@ mousereport(XEvent *e) | |||
| 390 | return; | 390 | return; |
| 391 | } | 391 | } |
| 392 | 392 | ||
| 393 | ttywrite(buf, len); | 393 | ttywrite(buf, len, 0); |
| 394 | } | 394 | } |
| 395 | 395 | ||
| 396 | void | 396 | void |
| @@ -408,7 +408,7 @@ bpress(XEvent *e) | |||
| 408 | for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) { | 408 | for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) { |
| 409 | if (e->xbutton.button == ms->b | 409 | if (e->xbutton.button == ms->b |
| 410 | && match(ms->mask, e->xbutton.state)) { | 410 | && match(ms->mask, e->xbutton.state)) { |
| 411 | ttysend(ms->s, strlen(ms->s)); | 411 | ttywrite(ms->s, strlen(ms->s), 1); |
| 412 | return; | 412 | return; |
| 413 | } | 413 | } |
| 414 | } | 414 | } |
| @@ -520,10 +520,10 @@ selnotify(XEvent *e) | |||
| 520 | } | 520 | } |
| 521 | 521 | ||
| 522 | if (IS_SET(MODE_BRCKTPASTE) && ofs == 0) | 522 | if (IS_SET(MODE_BRCKTPASTE) && ofs == 0) |
| 523 | ttywrite("\033[200~", 6); | 523 | ttywrite("\033[200~", 6, 0); |
| 524 | ttysend((char *)data, nitems * format / 8); | 524 | ttywrite((char *)data, nitems * format / 8, 1); |
| 525 | if (IS_SET(MODE_BRCKTPASTE) && rem == 0) | 525 | if (IS_SET(MODE_BRCKTPASTE) && rem == 0) |
| 526 | ttywrite("\033[201~", 6); | 526 | ttywrite("\033[201~", 6, 0); |
| 527 | XFree(data); | 527 | XFree(data); |
| 528 | /* number of 32-bit chunks returned */ | 528 | /* number of 32-bit chunks returned */ |
| 529 | ofs += nitems * format / 32; | 529 | ofs += nitems * format / 32; |
| @@ -1634,12 +1634,12 @@ focus(XEvent *ev) | |||
| 1634 | win.state |= WIN_FOCUSED; | 1634 | win.state |= WIN_FOCUSED; |
| 1635 | xseturgency(0); | 1635 | xseturgency(0); |
| 1636 | if (IS_SET(MODE_FOCUS)) | 1636 | if (IS_SET(MODE_FOCUS)) |
| 1637 | ttywrite("\033[I", 3); | 1637 | ttywrite("\033[I", 3, 0); |
| 1638 | } else { | 1638 | } else { |
| 1639 | XUnsetICFocus(xw.xic); | 1639 | XUnsetICFocus(xw.xic); |
| 1640 | win.state &= ~WIN_FOCUSED; | 1640 | win.state &= ~WIN_FOCUSED; |
| 1641 | if (IS_SET(MODE_FOCUS)) | 1641 | if (IS_SET(MODE_FOCUS)) |
| 1642 | ttywrite("\033[O", 3); | 1642 | ttywrite("\033[O", 3, 0); |
| 1643 | } | 1643 | } |
| 1644 | } | 1644 | } |
| 1645 | 1645 | ||
| @@ -1714,7 +1714,7 @@ kpress(XEvent *ev) | |||
| 1714 | 1714 | ||
| 1715 | /* 2. custom keys from config.h */ | 1715 | /* 2. custom keys from config.h */ |
| 1716 | if ((customkey = kmap(ksym, e->state))) { | 1716 | if ((customkey = kmap(ksym, e->state))) { |
| 1717 | ttysend(customkey, strlen(customkey)); | 1717 | ttywrite(customkey, strlen(customkey), 1); |
| 1718 | return; | 1718 | return; |
| 1719 | } | 1719 | } |
| 1720 | 1720 | ||
| @@ -1733,7 +1733,7 @@ kpress(XEvent *ev) | |||
| 1733 | len = 2; | 1733 | len = 2; |
| 1734 | } | 1734 | } |
| 1735 | } | 1735 | } |
| 1736 | ttysend(buf, len); | 1736 | ttywrite(buf, len, 1); |
| 1737 | } | 1737 | } |
| 1738 | 1738 | ||
| 1739 | 1739 | ||
