static void ttynew(void);
 static void ttyread(void);
 static void ttyresize(void);
+static void ttysend(char *, size_t);
 static void ttywrite(const char *, size_t);
 
 static void xdraws(char *, Glyph, int, int, int, int);
        for(mk = mshortcuts; mk < mshortcuts + LEN(mshortcuts); mk++) {
                if(e->xbutton.button == mk->b
                                && match(mk->mask, e->xbutton.state)) {
-                       ttywrite(mk->s, strlen(mk->s));
-                       if(IS_SET(MODE_ECHO))
-                               techo(mk->s, strlen(mk->s));
+                       ttysend(mk->s, strlen(mk->s));
                        return;
                }
        }
 
                if(IS_SET(MODE_BRCKTPASTE))
                        ttywrite("\033[200~", 6);
-               ttywrite((const char *)data, nitems * format / 8);
+               ttysend((char *)data, nitems * format / 8);
                if(IS_SET(MODE_BRCKTPASTE))
                        ttywrite("\033[201~", 6);
                XFree(data);
                die("write error on tty: %s\n", SERRNO);
 }
 
+void
+ttysend(char *s, size_t n) {
+       ttywrite(s, n);
+       if(IS_SET(MODE_ECHO))
+               techo(s, n);
+}
+
 void
 ttyresize(void) {
        struct winsize w;
 
        /* 2. custom keys from config.h */
        if((customkey = kmap(ksym, e->state))) {
-               len = strlen(customkey);
-               ttywrite(customkey, len);
-               if(IS_SET(MODE_ECHO))
-                       techo(customkey, len);
+               ttysend(customkey, strlen(customkey));
                return;
        }
 
                        len = 2;
                }
        }
-       ttywrite(buf, len);
-       if(IS_SET(MODE_ECHO))
-               techo(buf, len);
+       ttysend(buf, len);
 }