aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto E. Vargas Caballero <k0ga@shike2.com>2015-04-13 19:03:53 +0200
committerRoberto E. Vargas Caballero <k0ga@shike2.com>2015-04-15 10:52:44 +0200
commit215bdb2da3eca77ba01b70503c527baaad67c359 (patch)
treed3d8ea65fb4496e9a26ebc55a898bc34ca37e5a8
parent56abffb4b67f235d20de30f29ba027ab34c171e3 (diff)
downloadst-patched-215bdb2da3eca77ba01b70503c527baaad67c359.tar.bz2
st-patched-215bdb2da3eca77ba01b70503c527baaad67c359.tar.xz
st-patched-215bdb2da3eca77ba01b70503c527baaad67c359.zip
Add tty line support
Not always is desirable to create a pseudo terminal, and some times we want to open a terminal emulator over a tty line. With this new patch is possible to do someting like: $ st -l /dev/ttyS0 115200 Without this option was needed to launch another terminal emulator over st (for example minicom, picocom, cu, ...).
-rw-r--r--config.def.h1
-rw-r--r--st.137
-rw-r--r--st.c66
3 files changed, 91 insertions, 13 deletions
diff --git a/config.def.h b/config.def.h
index 5e7caaf..bb5596e 100644
--- a/config.def.h
+++ b/config.def.h
@@ -9,6 +9,7 @@ static char font[] = "Liberation Mono:pixelsize=12:antialias=false:autohint=fals
9static int borderpx = 2; 9static int borderpx = 2;
10static char shell[] = "/bin/sh"; 10static char shell[] = "/bin/sh";
11static char *utmp = NULL; 11static char *utmp = NULL;
12static char stty_args[] = "stty raw -echo -iexten echonl";
12 13
13/* identification sequence returned in DA and DECID */ 14/* identification sequence returned in DA and DECID */
14static char vtiden[] = "\033[?6c"; 15static char vtiden[] = "\033[?6c";
diff --git a/st.1 b/st.1
index a9fec15..9548c1a 100644
--- a/st.1
+++ b/st.1
@@ -15,11 +15,36 @@ st \- simple terminal
15.IR file ] 15.IR file ]
16.RB [ \-t 16.RB [ \-t
17.IR title ] 17.IR title ]
18.RB [ \-l
19.IR line ]
18.RB [ \-w 20.RB [ \-w
19.IR windowid ] 21.IR windowid ]
20.RB [ \-v ] 22.RB [ \-v ]
21.RB [ \-e 23.RB [ \-e
22.IR command ...] 24.IR command ...]
25.RI [ commands ...]
26.PP
27.B st
28.RB [ \-a ]
29.RB [ \-c
30.IR class ]
31.RB [ \-f
32.IR font ]
33.RB [ \-g
34.IR geometry ]
35.RB [ \-i ]
36.RB [ \-o
37.IR file ]
38.RB [ \-t
39.IR title ]
40.RB [ \-l
41.IR line ]
42.RB [ \-w
43.IR windowid ]
44.RB [ \-v ]
45.RB [ \-l
46.IR line ]
47.RI [ stty_args ...]
23.SH DESCRIPTION 48.SH DESCRIPTION
24.B st 49.B st
25is a simple terminal emulator. 50is a simple terminal emulator.
@@ -58,6 +83,11 @@ defines the window title (default 'st').
58embeds st within the window identified by 83embeds st within the window identified by
59.I windowid 84.I windowid
60.TP 85.TP
86.BI \-l " line"
87use a tty line instead of a pseudo terminal.
88When this flag is used
89remaining arguments are used as flags for stty.
90.TP
61.B \-v 91.B \-v
62prints version information to stderr, then exits. 92prints version information to stderr, then exits.
63.TP 93.TP
@@ -67,6 +97,9 @@ st executes
67instead of the shell. If this is used it 97instead of the shell. If this is used it
68.B must be the last option 98.B must be the last option
69on the command line, as in xterm / rxvt. 99on the command line, as in xterm / rxvt.
100This option is only intended for compability,
101and all the remaining arguments are used as a command
102even without it.
70.SH SHORTCUTS 103.SH SHORTCUTS
71.TP 104.TP
72.B Ctrl-Print Screen 105.B Ctrl-Print Screen
@@ -110,7 +143,9 @@ See the LICENSE file for the authors.
110.SH LICENSE 143.SH LICENSE
111See the LICENSE file for the terms of redistribution. 144See the LICENSE file for the terms of redistribution.
112.SH SEE ALSO 145.SH SEE ALSO
113.BR tabbed (1) 146.BR tabbed (1),
147.BR utmp (1),
148.BR stty (1)
114.SH BUGS 149.SH BUGS
115See the TODO file in the distribution. 150See the TODO file in the distribution.
116 151
diff --git a/st.c b/st.c
index bb8c365..d22c605 100644
--- a/st.c
+++ b/st.c
@@ -352,6 +352,7 @@ static void draw(void);
352static void redraw(void); 352static void redraw(void);
353static void drawregion(int, int, int, int); 353static void drawregion(int, int, int, int);
354static void execsh(void); 354static void execsh(void);
355static void stty(void);
355static void sigchld(int); 356static void sigchld(int);
356static void run(void); 357static void run(void);
357 358
@@ -508,6 +509,7 @@ static char *opt_title = NULL;
508static char *opt_embed = NULL; 509static char *opt_embed = NULL;
509static char *opt_class = NULL; 510static char *opt_class = NULL;
510static char *opt_font = NULL; 511static char *opt_font = NULL;
512static char *opt_line = NULL;
511static int oldbutton = 3; /* button event on startup: 3 = release */ 513static int oldbutton = 3; /* button event on startup: 3 = release */
512 514
513static char *usedfont = NULL; 515static char *usedfont = NULL;
@@ -1253,11 +1255,55 @@ sigchld(int a) {
1253 exit(EXIT_SUCCESS); 1255 exit(EXIT_SUCCESS);
1254} 1256}
1255 1257
1258
1259void
1260stty(void)
1261{
1262 char cmd[_POSIX_ARG_MAX], **p, *q, *s;
1263 size_t n, siz;
1264
1265 if((n = strlen(stty_args)) > sizeof(cmd)-1)
1266 die("incorrect stty parameters\n");
1267 memcpy(cmd, stty_args, n);
1268 q = cmd + n;
1269 siz = sizeof(cmd) - n;
1270 for(p = opt_cmd; p && (s = *p); ++p) {
1271 if((n = strlen(s)) > siz-1)
1272 die("stty parameter length too long\n");
1273 *q++ = ' ';
1274 q = memcpy(q, s, n);
1275 q += n;
1276 siz-= n + 1;
1277 }
1278 *q = '\0';
1279 system(cmd);
1280}
1281
1256void 1282void
1257ttynew(void) { 1283ttynew(void) {
1258 int m, s; 1284 int m, s;
1259 struct winsize w = {term.row, term.col, 0, 0}; 1285 struct winsize w = {term.row, term.col, 0, 0};
1260 1286
1287 if(opt_io) {
1288 term.mode |= MODE_PRINT;
1289 iofd = (!strcmp(opt_io, "-")) ?
1290 STDOUT_FILENO :
1291 open(opt_io, O_WRONLY | O_CREAT, 0666);
1292 if(iofd < 0) {
1293 fprintf(stderr, "Error opening %s:%s\n",
1294 opt_io, strerror(errno));
1295 }
1296 }
1297
1298 if (opt_line) {
1299 if((cmdfd = open(opt_line, O_RDWR)) < 0)
1300 die("open line failed: %s\n", strerror(errno));
1301 close(STDIN_FILENO);
1302 dup(cmdfd);
1303 stty();
1304 return;
1305 }
1306
1261 /* seems to work fine on linux, openbsd and freebsd */ 1307 /* seems to work fine on linux, openbsd and freebsd */
1262 if(openpty(&m, &s, NULL, NULL, &w) < 0) 1308 if(openpty(&m, &s, NULL, NULL, &w) < 0)
1263 die("openpty failed: %s\n", strerror(errno)); 1309 die("openpty failed: %s\n", strerror(errno));
@@ -1267,6 +1313,7 @@ ttynew(void) {
1267 die("fork failed\n"); 1313 die("fork failed\n");
1268 break; 1314 break;
1269 case 0: 1315 case 0:
1316 close(iofd);
1270 setsid(); /* create a new process group */ 1317 setsid(); /* create a new process group */
1271 dup2(s, STDIN_FILENO); 1318 dup2(s, STDIN_FILENO);
1272 dup2(s, STDOUT_FILENO); 1319 dup2(s, STDOUT_FILENO);
@@ -1281,16 +1328,6 @@ ttynew(void) {
1281 close(s); 1328 close(s);
1282 cmdfd = m; 1329 cmdfd = m;
1283 signal(SIGCHLD, sigchld); 1330 signal(SIGCHLD, sigchld);
1284 if(opt_io) {
1285 term.mode |= MODE_PRINT;
1286 iofd = (!strcmp(opt_io, "-")) ?
1287 STDOUT_FILENO :
1288 open(opt_io, O_WRONLY | O_CREAT, 0666);
1289 if(iofd < 0) {
1290 fprintf(stderr, "Error opening %s:%s\n",
1291 opt_io, strerror(errno));
1292 }
1293 }
1294 break; 1331 break;
1295 } 1332 }
1296} 1333}
@@ -4009,9 +4046,11 @@ run(void) {
4009 4046
4010void 4047void
4011usage(void) { 4048usage(void) {
4012 die("%s " VERSION " (c) 2010-2015 st engineers\n" \ 4049 die("%s " VERSION " (c) 2010-2015 st engineers\n"
4013 "usage: st [-a] [-v] [-c class] [-f font] [-g geometry] [-o file]\n" 4050 "usage: st [-a] [-v] [-c class] [-f font] [-g geometry] [-o file]\n"
4014 " [-i] [-t title] [-w windowid] [-e command ...] [command ...]\n", 4051 " [-i] [-t title] [-w windowid] [-e command ...] [command ...]\n"
4052 " st [-a] [-v] [-c class] [-f font] [-g geometry] [-o file]\n"
4053 " [-i] [-t title] [-w windowid] [-l line] [stty_args ...]\n",
4015 argv0); 4054 argv0);
4016} 4055}
4017 4056
@@ -4047,6 +4086,9 @@ main(int argc, char *argv[]) {
4047 case 'o': 4086 case 'o':
4048 opt_io = EARGF(usage()); 4087 opt_io = EARGF(usage());
4049 break; 4088 break;
4089 case 'l':
4090 opt_line = EARGF(usage());
4091 break;
4050 case 't': 4092 case 't':
4051 opt_title = EARGF(usage()); 4093 opt_title = EARGF(usage());
4052 break; 4094 break;