X-Git-Url: https://git.armaanb.net/?p=st.git;a=blobdiff_plain;f=st.c;h=3ebf8c6947e69086dfb51541600d5320f8ce7466;hp=7d546da077538f2d15acebcce81548ef7517eec2;hb=33201ac65f74e45b4fa60822ba9a538c3cfa9b25;hpb=52d6fb1ab1f7d41839edebb63c3408578cd44e3c diff --git a/st.c b/st.c index 7d546da..3ebf8c6 100644 --- a/st.c +++ b/st.c @@ -108,6 +108,7 @@ typedef struct { static void execsh(char **); static void stty(char **); static void sigchld(int); +static void ttywriteraw(const char *, size_t); static void csidump(void); static void csihandle(void); @@ -786,13 +787,38 @@ ttyread(void) void ttywrite(const char *s, size_t n, int may_echo) { - fd_set wfd, rfd; - ssize_t r; - size_t lim = 256; + const char *next; if (may_echo && IS_SET(MODE_ECHO)) twrite(s, n, 1); + if (!IS_SET(MODE_CRLF)) { + ttywriteraw(s, n); + return; + } + + /* This is similar to how the kernel handles ONLCR for ttys */ + while (n > 0) { + if (*s == '\r') { + next = s + 1; + ttywriteraw("\r\n", 2); + } else { + next = memchr(s, '\r', n); + DEFAULT(next, s + n); + ttywriteraw(s, next - s); + } + n -= next - s; + s = next; + } +} + +void +ttywriteraw(const char *s, size_t n) +{ + fd_set wfd, rfd; + ssize_t r; + size_t lim = 256; + /* * Remember that we are using a pty, which might be a modem line. * Writing too much will clog the line. That's why we are doing this