aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorDevin J. Pohly <djpohly@gmail.com>2018-02-22 01:05:12 -0600
committerDevin J. Pohly <djpohly@gmail.com>2018-02-25 21:53:24 -0600
commit33201ac65f74e45b4fa60822ba9a538c3cfa9b25 (patch)
treed14efba42f31bc0f4900a9af90988093464ad781 /st.c
parent52d6fb1ab1f7d41839edebb63c3408578cd44e3c (diff)
downloadst-33201ac65f74e45b4fa60822ba9a538c3cfa9b25.tar.gz
st-33201ac65f74e45b4fa60822ba9a538c3cfa9b25.tar.bz2
st-33201ac65f74e45b4fa60822ba9a538c3cfa9b25.zip
Move CRLF input processing into ttywrite
This also allows us to remove the crlf field from the Key struct, since the only difference it made was converting "\r" to "\r\n" (which is now done automatically in ttywrite). In addition, MODE_CRLF is no longer referenced from x.c. Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
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 {
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