Skip to content

Commit 26663de

Browse files
committed
Support setting pty size in script command
1 parent 23da0d7 commit 26663de

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

examples/script.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
* @fileoverview Terminal Screencast Recorder / Player, e.g.
5050
*
5151
* make o//examples/script.com
52-
* o//examples/script.com -r
52+
* o//examples/script.com -w80 -h24 -r recording.tty
5353
* # type stuff..
5454
* # CTRL-D
55-
* o//examples/script.com -p typescript
55+
* o//examples/script.com -p recording.tty
5656
*
5757
* @note works on Linux, OpenBSD, NetBSD, FreeBSD, MacOS
5858
* @see https://asciinema.org/
@@ -103,9 +103,9 @@ main(int argc, char *argv[])
103103
fd_set rfd;
104104
int fm_fd;
105105
int aflg, Fflg, kflg, pflg, ch, k, n;
106-
int flushtime, readstdin;
106+
int flushtime, readstdin, width, height;
107107

108-
aflg = Fflg = kflg = pflg = 0;
108+
aflg = Fflg = kflg = pflg = height = width = 0;
109109
usesleep = 1;
110110
rawout = 0;
111111
flushtime = 30;
@@ -115,7 +115,7 @@ main(int argc, char *argv[])
115115

116116
(void)fm_fd;
117117

118-
while ((ch = getopt(argc, argv, "adeFfkpqrt:")) != -1)
118+
while ((ch = getopt(argc, argv, "adeFfkpqrt:w:h:")) != -1)
119119
switch(ch) {
120120
case 'a':
121121
aflg = 1;
@@ -145,6 +145,12 @@ main(int argc, char *argv[])
145145
if (flushtime < 0)
146146
err(1, "invalid flush time %d", flushtime);
147147
break;
148+
case 'w':
149+
width = atoi(optarg);
150+
break;
151+
case 'h':
152+
height = atoi(optarg);
153+
break;
148154
case '?':
149155
default:
150156
usage();
@@ -172,6 +178,10 @@ main(int argc, char *argv[])
172178
if (openpty(&master, &slave, NULL, NULL, NULL) == -1)
173179
err(1, "openpty");
174180
} else {
181+
if (width)
182+
win.ws_col = width;
183+
if (height)
184+
win.ws_row = height;
175185
if (openpty(&master, &slave, NULL, &tt, &win) == -1)
176186
err(1, "openpty");
177187
ttyflg = 1;

0 commit comments

Comments
 (0)