From 2090981be3d3e5ca1083c004a08f54aced2d0720 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Mon, 20 Apr 2020 10:24:34 +0200 Subject: [PATCH] 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. --- config.def.h | 3 ++- st.1 | 3 ++- st.c | 16 ++++++++++------ st.h | 3 ++- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/config.def.h b/config.def.h index 959a90c..52059ab 100644 --- a/config.def.h +++ b/config.def.h @@ -25,13 +25,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 51a6835..9d8a9ba 100644 --- a/st.c +++ b/st.c @@ -726,7 +726,7 @@ die(const char *errstr, ...) void execsh(char *cmd, char **args) { - char *sh, *prog; + char *sh, *prog, *arg; const struct passwd *pw; errno = 0; @@ -740,12 +740,16 @@ 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; + arg = NULL; + } DEFAULT(args, ((char *[]) {prog, NULL})); unsetenv("COLUMNS"); @@ -2768,4 +2772,4 @@ redraw(void) draw(); } -#include "patch/st_include.c" \ No newline at end of file +#include "patch/st_include.c" diff --git a/st.h b/st.h index f8fa2be..030de38 100644 --- a/st.h +++ b/st.h @@ -132,6 +132,7 @@ int borderpx; /* config.h globals */ extern char *utmp; +extern char *scroll; extern char *stty_args; extern char *vtiden; extern wchar_t *worddelimiters; @@ -145,4 +146,4 @@ extern const int boxdraw, boxdraw_bold, boxdraw_braille; #endif // BOXDRAW_PATCH #if ALPHA_PATCH extern float alpha; -#endif // ALPHA_PATCH \ No newline at end of file +#endif // ALPHA_PATCH