aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
Diffstat (limited to 'st.c')
-rw-r--r--st.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/st.c b/st.c
index 7d546da..3ebf8c6 100644
--- a/st.c
+++ b/st.c
@@ -108,6 +108,7 @@ typedef struct {
108static void execsh(char **); 108static void execsh(char **);
109static void stty(char **); 109static void stty(char **);
110static void sigchld(int); 110static void sigchld(int);
111static void ttywriteraw(const char *, size_t);
111 112
112static void csidump(void); 113static void csidump(void);
113static void csihandle(void); 114static void csihandle(void);
@@ -786,13 +787,38 @@ ttyread(void)
786void 787void
787ttywrite(const char *s, size_t n, int may_echo) 788ttywrite(const char *s, size_t n, int may_echo)
788{ 789{
789 fd_set wfd, rfd; 790 const char *next;
790 ssize_t r;
791 size_t lim = 256;
792 791
793 if (may_echo && IS_SET(MODE_ECHO)) 792 if (may_echo && IS_SET(MODE_ECHO))
794 twrite(s, n, 1); 793 twrite(s, n, 1);
795 794
795 if (!IS_SET(MODE_CRLF)) {
796 ttywriteraw(s, n);
797 return;
798 }
799
800 /* This is similar to how the kernel handles ONLCR for ttys */
801 while (n > 0) {
802 if (*s == '\r') {
803 next = s + 1;
804 ttywriteraw("\r\n", 2);
805 } else {
806 next = memchr(s, '\r', n);
807 DEFAULT(next, s + n);
808 ttywriteraw(s, next - s);
809 }
810 n -= next - s;
811 s = next;
812 }
813}
814
815void
816ttywriteraw(const char *s, size_t n)
817{
818 fd_set wfd, rfd;
819 ssize_t r;
820 size_t lim = 256;
821
796 /* 822 /*
797 * Remember that we are using a pty, which might be a modem line. 823 * Remember that we are using a pty, which might be a modem line.
798 * Writing too much will clog the line. That's why we are doing this 824 * Writing too much will clog the line. That's why we are doing this