diff options
| -rw-r--r-- | config.def.h | 1 | ||||
| -rw-r--r-- | st.1 | 37 | ||||
| -rw-r--r-- | st.c | 66 |
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 | |||
| 9 | static int borderpx = 2; | 9 | static int borderpx = 2; |
| 10 | static char shell[] = "/bin/sh"; | 10 | static char shell[] = "/bin/sh"; |
| 11 | static char *utmp = NULL; | 11 | static char *utmp = NULL; |
| 12 | static 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 */ |
| 14 | static char vtiden[] = "\033[?6c"; | 15 | static char vtiden[] = "\033[?6c"; |
| @@ -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 |
| 25 | is a simple terminal emulator. | 50 | is a simple terminal emulator. |
| @@ -58,6 +83,11 @@ defines the window title (default 'st'). | |||
| 58 | embeds st within the window identified by | 83 | embeds st within the window identified by |
| 59 | .I windowid | 84 | .I windowid |
| 60 | .TP | 85 | .TP |
| 86 | .BI \-l " line" | ||
| 87 | use a tty line instead of a pseudo terminal. | ||
| 88 | When this flag is used | ||
| 89 | remaining arguments are used as flags for stty. | ||
| 90 | .TP | ||
| 61 | .B \-v | 91 | .B \-v |
| 62 | prints version information to stderr, then exits. | 92 | prints version information to stderr, then exits. |
| 63 | .TP | 93 | .TP |
| @@ -67,6 +97,9 @@ st executes | |||
| 67 | instead of the shell. If this is used it | 97 | instead of the shell. If this is used it |
| 68 | .B must be the last option | 98 | .B must be the last option |
| 69 | on the command line, as in xterm / rxvt. | 99 | on the command line, as in xterm / rxvt. |
| 100 | This option is only intended for compability, | ||
| 101 | and all the remaining arguments are used as a command | ||
| 102 | even 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 |
| 111 | See the LICENSE file for the terms of redistribution. | 144 | See 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 |
| 115 | See the TODO file in the distribution. | 150 | See the TODO file in the distribution. |
| 116 | 151 | ||
| @@ -352,6 +352,7 @@ static void draw(void); | |||
| 352 | static void redraw(void); | 352 | static void redraw(void); |
| 353 | static void drawregion(int, int, int, int); | 353 | static void drawregion(int, int, int, int); |
| 354 | static void execsh(void); | 354 | static void execsh(void); |
| 355 | static void stty(void); | ||
| 355 | static void sigchld(int); | 356 | static void sigchld(int); |
| 356 | static void run(void); | 357 | static void run(void); |
| 357 | 358 | ||
| @@ -508,6 +509,7 @@ static char *opt_title = NULL; | |||
| 508 | static char *opt_embed = NULL; | 509 | static char *opt_embed = NULL; |
| 509 | static char *opt_class = NULL; | 510 | static char *opt_class = NULL; |
| 510 | static char *opt_font = NULL; | 511 | static char *opt_font = NULL; |
| 512 | static char *opt_line = NULL; | ||
| 511 | static int oldbutton = 3; /* button event on startup: 3 = release */ | 513 | static int oldbutton = 3; /* button event on startup: 3 = release */ |
| 512 | 514 | ||
| 513 | static char *usedfont = NULL; | 515 | static char *usedfont = NULL; |
| @@ -1253,11 +1255,55 @@ sigchld(int a) { | |||
| 1253 | exit(EXIT_SUCCESS); | 1255 | exit(EXIT_SUCCESS); |
| 1254 | } | 1256 | } |
| 1255 | 1257 | ||
| 1258 | |||
| 1259 | void | ||
| 1260 | stty(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 | |||
| 1256 | void | 1282 | void |
| 1257 | ttynew(void) { | 1283 | ttynew(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 | ||
| 4010 | void | 4047 | void |
| 4011 | usage(void) { | 4048 | usage(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; |
