Hi, I attach several patches for st (sorry, for different reasons i cannot use git-send-email).
Regards,
>From d18c3a8c9eb82b2d135f4feb44060e6adb29428e Mon Sep 17 00:00:00 2001 From: "Roberto E. Vargas Caballero" <k...@shike2.com> Date: Fri, 10 Apr 2020 22:26:12 +0200 Subject: [PATCH 3/4] Fix style issue --- st.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/st.c b/st.c index 81973ee..2ecf8f3 100644 --- a/st.c +++ b/st.c @@ -366,7 +366,8 @@ static const char base64_digits[] = { char base64dec_getc(const char **src) { - while (**src && !isprint(**src)) (*src)++; + while (**src && !isprint(**src)) + (*src)++; return **src ? *((*src)++) : '='; /* emulate padding if string ends */ } -- 2.26.0
>From 9a847d761579f7bec8a24ddcf8034d7600c9b4a8 Mon Sep 17 00:00:00 2001 From: "Roberto E. Vargas Caballero" <k...@shike2.com> Date: Fri, 10 Apr 2020 22:50:23 +0200 Subject: [PATCH 4/4] Add terminfo entries for backspace mode St used to use backspace as BS until the commit 230d0c8, but due to general lack of knowledge of lusers, we moved to the most common configuration in linux to avoid answering the same question 3 times per month. With the most common configuration we have a backspace that returns a DEL, and we have a Delete key that doesn't return a DEL character neither a BS. When dealing with devices connected using a serial line (or even with Plan9) it is more common Backspace as BS and Delete as DEL. For this reason, st is not always the best tool when you talk with a serial device. This patch adds new terminfo entries for Backspace as BS and Delete as DEL. A patch for confg.h is also added, to make easier switch between both configurations. --- configs/backspace.diff | 30 ++++++++++++++++++++++++++++++ st.info | 10 ++++++++++ 2 files changed, 40 insertions(+) create mode 100644 configs/backspace.diff diff --git a/configs/backspace.diff b/configs/backspace.diff new file mode 100644 index 0000000..cdbf4f4 --- /dev/null +++ b/configs/backspace.diff @@ -0,0 +1,30 @@ +--- config.h 2020-04-11 09:22:38.386974190 +0200 ++++ config.h 2020-04-11 09:47:50.267056817 +0200 +@@ -64,7 +64,7 @@ + static int bellvolume = 0; + + /* default TERM value */ +-char *termname = "st-256color"; ++char *termname = "st-bs-256color"; + + /* + * spaces per tab +@@ -265,7 +265,7 @@ + { XK_KP_Delete, ShiftMask, "\033[2K", -1, 0}, + { XK_KP_Delete, ShiftMask, "\033[3;2~", +1, 0}, + { XK_KP_Delete, XK_ANY_MOD, "\033[P", -1, 0}, +- { XK_KP_Delete, XK_ANY_MOD, "\033[3~", +1, 0}, ++ { XK_KP_Delete, XK_ANY_MOD, "\0177", +1, 0}, + { XK_KP_Multiply, XK_ANY_MOD, "\033Oj", +2, 0}, + { XK_KP_Add, XK_ANY_MOD, "\033Ok", +2, 0}, + { XK_KP_Enter, XK_ANY_MOD, "\033OM", +2, 0}, +@@ -333,8 +333,7 @@ + { XK_Delete, ShiftMask, "\033[2K", -1, 0}, + { XK_Delete, ShiftMask, "\033[3;2~", +1, 0}, + { XK_Delete, XK_ANY_MOD, "\033[P", -1, 0}, +- { XK_Delete, XK_ANY_MOD, "\033[3~", +1, 0}, +- { XK_BackSpace, XK_NO_MOD, "\177", 0, 0}, ++ { XK_Delete, XK_ANY_MOD, "\0177", +1, 0}, + { XK_BackSpace, Mod1Mask, "\033\177", 0, 0}, + { XK_Home, ShiftMask, "\033[2J", 0, -1}, + { XK_Home, ShiftMask, "\033[1;2H", 0, +1}, diff --git a/st.info b/st.info index 78ffd30..1df490b 100644 --- a/st.info +++ b/st.info @@ -220,3 +220,13 @@ st-meta-256color| simpleterm with meta key and 256 colors, smm=\E[?1034h, rs2=\E[4l\E>\E[?1034h, is2=\E[4l\E>\E[?1034h, + +st-bs| simpleterm with backspace as backspace, + use=st, + kbs=\010, + kdch1=\177, + +st-bs-256color| simpleterm with backspace as backspace and 256colors, + use=st-256color, + kbs=\010, + kdch1=\177, -- 2.26.0
>From 6d02a2710b3ecdd1874c3a34c5d9fc2e19747c73 Mon Sep 17 00:00:00 2001 From: "Roberto E. Vargas Caballero" <k...@shike2.com> Date: Fri, 10 Apr 2020 22:25:46 +0200 Subject: [PATCH 2/4] ttyread: Test for EOF while reading tty When If a read operation returns 0 then it means that we arrived to the end of the file, and new reads will return 0 unless you do some other operation such as lseek(). This case happens with usb-232 adapters when they are unplugged. --- st.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/st.c b/st.c index 5f2352a..81973ee 100644 --- a/st.c +++ b/st.c @@ -823,17 +823,24 @@ ttyread(void) int ret; /* append read bytes to unprocessed bytes */ - if ((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0) - die("couldn't read from shell: %s\n", strerror(errno)); - buflen += ret; + ret = read(cmdfd, buf+buflen, LEN(buf)-buflen); - written = twrite(buf, buflen, 0); - buflen -= written; - /* keep any uncomplete utf8 char for the next call */ - if (buflen > 0) - memmove(buf, buf + written, buflen); + switch (ret) { + case 0: + fputs("Found EOF in input\n", stderr); + exit(0); + case -1: + die("couldn't read from shell: %s\n", strerror(errno)); + default: + buflen += ret; + written = twrite(buf, buflen, 0); + buflen -= written; + /* keep any uncomplete utf8 char for the next call */ + if (buflen > 0) + memmove(buf, buf + written, buflen); + return ret; - return ret; + } } void -- 2.26.0
>From 05485fb70f5cd2e130d2d3fa82281dc37b4c68fb Mon Sep 17 00:00:00 2001 From: "Roberto E. Vargas Caballero" <k...@shike2.com> Date: Fri, 10 Apr 2020 22:06:32 +0200 Subject: [PATCH 1/4] Add support for scroll(1) Scroll is a program that stores all the lines of its child and be used in st as a way of implementing scrollback. This solution is much better than implementing the scrollback in st itself because having a different program allows to use it in any other program without doing modifications to those programs. Add scroll option --- config.def.h | 3 ++- st.1 | 3 ++- st.c | 16 ++++++++++------ st.h | 1 + 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/config.def.h b/config.def.h index 546edda..dfcbda9 100644 --- a/config.def.h +++ b/config.def.h @@ -11,13 +11,14 @@ static int borderpx = 2; /* * What program is execed by st depends of these precedence rules: * 1: program passed with -e - * 2: utmp option + * 2: scroll and/or utmp * 3: SHELL environment variable * 4: value of shell in /etc/passwd * 5: value of shell in config.h */ static char *shell = "/bin/sh"; char *utmp = NULL; +char *scroll = NULL; char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400"; /* identification sequence returned in DA and DECID */ diff --git a/st.1 b/st.1 index e8d6059..39120b4 100644 --- a/st.1 +++ b/st.1 @@ -170,7 +170,8 @@ See the LICENSE file for the terms of redistribution. .SH SEE ALSO .BR tabbed (1), .BR utmp (1), -.BR stty (1) +.BR stty (1), +.BR scroll (1) .SH BUGS See the TODO file in the distribution. diff --git a/st.c b/st.c index 3e48410..5f2352a 100644 --- a/st.c +++ b/st.c @@ -664,7 +664,7 @@ die(const char *errstr, ...) void execsh(char *cmd, char **args) { - char *sh, *prog; + char *sh, *prog, *arg; const struct passwd *pw; errno = 0; @@ -678,13 +678,17 @@ execsh(char *cmd, char **args) if ((sh = getenv("SHELL")) == NULL) sh = (pw->pw_shell[0]) ? pw->pw_shell : cmd; - if (args) + if (args) { prog = args[0]; - else if (utmp) - prog = utmp; - else + arg = NULL; + } else if (scroll || utmp) { + prog = scroll ? scroll : utmp; + arg = scroll ? utmp : NULL; + } else { prog = sh; - DEFAULT(args, ((char *[]) {prog, NULL})); + arg = NULL; + } + DEFAULT(args, ((char *[]) {prog, arg, NULL})); unsetenv("COLUMNS"); unsetenv("LINES"); diff --git a/st.h b/st.h index a1928ca..d978458 100644 --- a/st.h +++ b/st.h @@ -113,6 +113,7 @@ char *xstrdup(char *); /* config.h globals */ extern char *utmp; +extern char *scroll; extern char *stty_args; extern char *vtiden; extern wchar_t *worddelimiters; -- 2.26.0