From 26663dea9c8ea893e26dbc30028f8ee88865b47d Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Mon, 21 Oct 2024 22:55:03 -0700 Subject: [PATCH] Support setting pty size in script command --- examples/script.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/examples/script.c b/examples/script.c index 8068a75d5..414f07e8c 100644 --- a/examples/script.c +++ b/examples/script.c @@ -49,10 +49,10 @@ * @fileoverview Terminal Screencast Recorder / Player, e.g. * * make o//examples/script.com - * o//examples/script.com -r + * o//examples/script.com -w80 -h24 -r recording.tty * # type stuff.. * # CTRL-D - * o//examples/script.com -p typescript + * o//examples/script.com -p recording.tty * * @note works on Linux, OpenBSD, NetBSD, FreeBSD, MacOS * @see https://asciinema.org/ @@ -103,9 +103,9 @@ main(int argc, char *argv[]) fd_set rfd; int fm_fd; int aflg, Fflg, kflg, pflg, ch, k, n; - int flushtime, readstdin; + int flushtime, readstdin, width, height; - aflg = Fflg = kflg = pflg = 0; + aflg = Fflg = kflg = pflg = height = width = 0; usesleep = 1; rawout = 0; flushtime = 30; @@ -115,7 +115,7 @@ main(int argc, char *argv[]) (void)fm_fd; - while ((ch = getopt(argc, argv, "adeFfkpqrt:")) != -1) + while ((ch = getopt(argc, argv, "adeFfkpqrt:w:h:")) != -1) switch(ch) { case 'a': aflg = 1; @@ -145,6 +145,12 @@ main(int argc, char *argv[]) if (flushtime < 0) err(1, "invalid flush time %d", flushtime); break; + case 'w': + width = atoi(optarg); + break; + case 'h': + height = atoi(optarg); + break; case '?': default: usage(); @@ -172,6 +178,10 @@ main(int argc, char *argv[]) if (openpty(&master, &slave, NULL, NULL, NULL) == -1) err(1, "openpty"); } else { + if (width) + win.ws_col = width; + if (height) + win.ws_row = height; if (openpty(&master, &slave, NULL, &tt, &win) == -1) err(1, "openpty"); ttyflg = 1;