From b1b3a5fdda40211d1ce4d5018425861abbd88f06 Mon Sep 17 00:00:00 2001 From: Alexander Sedov Date: Mon, 25 Feb 2013 22:38:33 +0400 Subject: [st] [PATCH] Replacing linefeeds with returns in ttywrite(). To: dev@suckless.org This is to work around buggy behaviour in applications such as nano, and seems to work fine with all other applications. --- st.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/st.c b/st.c index afa6813..74e31d8 100644 --- a/st.c +++ b/st.c @@ -1109,7 +1109,14 @@ ttyread(void) { void ttywrite(const char *s, size_t n) { - if(write(cmdfd, s, n) == -1) + const char *p = s, *q, *end = s + n; + while ((q = memchr(p, '\n', end - p))) { + if(write(cmdfd, p, q - p) == -1 + ||write(cmdfd, "\r", 1) == -1) + die("write error on tty: %s\n", SERRNO); + p = q + 1; + } + if(write(cmdfd, p, end - p) == -1) die("write error on tty: %s\n", SERRNO); } -- 1.7.10.4