Add write I/O to file

This is a theorical feature listed in http://st.suckless.org/goals. All the
input/output of the terminal will be written to a file, which can be very
useful for debugging, and also allow interconnect st to other process
through named pipes.
---
 st.1 |    6 ++++++
 st.c |   14 +++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)
This commit is contained in:
Roberto E. Vargas Caballero 2012-09-03 21:52:21 +02:00
parent cfefa054e8
commit a984ffc4cb
2 changed files with 19 additions and 1 deletions

6
st.1
View File

@ -10,6 +10,8 @@ st \- simple terminal
.RB [ \-w .RB [ \-w
.IR windowid ] .IR windowid ]
.RB [ \-v ] .RB [ \-v ]
.RB [ \-f
.IR file ]
.RB [ \-e .RB [ \-e
.IR command ...] .IR command ...]
.SH DESCRIPTION .SH DESCRIPTION
@ -30,6 +32,10 @@ embeds st within the window identified by
.B \-v .B \-v
prints version information to stderr, then exits. prints version information to stderr, then exits.
.TP .TP
.BI \-f " file"
writes all the I/O to
.I file
.TP
.BI \-e " program " [ " arguments " "... ]" .BI \-e " program " [ " arguments " "... ]"
st executes st executes
.I program .I program

14
st.c
View File

@ -36,7 +36,7 @@
#define USAGE \ #define USAGE \
"st " VERSION " (c) 2010-2012 st engineers\n" \ "st " VERSION " (c) 2010-2012 st engineers\n" \
"usage: st [-t title] [-c class] [-w windowid] [-v] [-e command...]\n" "usage: st [-t title] [-c class] [-w windowid] [-v] [-f file] [-e command...]\n"
/* XEMBED messages */ /* XEMBED messages */
#define XEMBED_FOCUS_IN 4 #define XEMBED_FOCUS_IN 4
@ -342,7 +342,9 @@ static STREscape strescseq;
static int cmdfd; static int cmdfd;
static pid_t pid; static pid_t pid;
static Selection sel; static Selection sel;
static FILE *fileio;
static char **opt_cmd = NULL; static char **opt_cmd = NULL;
static char *opt_io = NULL;
static char *opt_title = NULL; static char *opt_title = NULL;
static char *opt_embed = NULL; static char *opt_embed = NULL;
static char *opt_class = NULL; static char *opt_class = NULL;
@ -776,6 +778,10 @@ ttynew(void) {
close(s); close(s);
cmdfd = m; cmdfd = m;
signal(SIGCHLD, sigchld); signal(SIGCHLD, sigchld);
if (opt_io && !(fileio = fopen(opt_io, "w"))) {
fprintf(stderr, "Error opening %s:%s",
opt_io, strerror(errno));
}
} }
} }
@ -1534,6 +1540,9 @@ tputtab(bool forward) {
void void
tputc(char *c) { tputc(char *c) {
char ascii = *c; char ascii = *c;
if (fileio)
putc(ascii, fileio);
if(term.esc & ESC_START) { if(term.esc & ESC_START) {
if(term.esc & ESC_CSI) { if(term.esc & ESC_CSI) {
csiescseq.buf[csiescseq.len++] = ascii; csiescseq.buf[csiescseq.len++] = ascii;
@ -2269,6 +2278,9 @@ main(int argc, char *argv[]) {
case 'w': case 'w':
if(++i < argc) opt_embed = argv[i]; if(++i < argc) opt_embed = argv[i];
break; break;
case 'f':
if (++i < argc) opt_io = argv[i];
break;
case 'e': case 'e':
/* eat every remaining arguments */ /* eat every remaining arguments */
if(++i < argc) opt_cmd = &argv[i]; if(++i < argc) opt_cmd = &argv[i];