From: Soumendra Ganguly <soumendraganguly@gmail.com>
To: util-linux@vger.kernel.org
Subject: [PATCH] term-utils: Make scriptreplay set terminal to raw mode
Date: Fri, 10 Jul 2020 07:15:25 -0500 [thread overview]
Message-ID: <CAOW54GXn9KWBEquqCyuBOnADk-MLXA0LpBqUj=kp138Z2KFLEA@mail.gmail.com> (raw)
scriptreplay produces garbled output while replaying certain curses
sessions. script(1) from util-linux is able to record the sessions
correctly.
The following programs can be used to demonstrate this.
1. A curses-based game called "greed"; a Debian 10 package named
"greed" is available.
2. A Python implementation of Conway's game of life by GitHub user
iiSeymour. The repository is named game-of-life.
Expected output is obtained by making scriptreplay call cfmakeraw.
Signed-off-by: Soumendra Ganguly <soumendraganguly@gmail.com>
---
term-utils/scriptreplay.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/term-utils/scriptreplay.c b/term-utils/scriptreplay.c
index bca1d21b4..19a7d568b 100644
--- a/term-utils/scriptreplay.c
+++ b/term-utils/scriptreplay.c
@@ -28,6 +28,7 @@
#include <unistd.h>
#include <getopt.h>
#include <sys/time.h>
+#include <termios.h>
#include "c.h"
#include "xalloc.h"
@@ -120,12 +121,30 @@ static void appendchr(char *buf, size_t bufsz, int c)
buf[sz] = c;
}
+static int termraw(struct termios *backup)
+{
+ struct termios tattr;
+
+ if (tcgetattr(STDOUT_FILENO, backup) != 0)
+ return -1;
+
+ tattr = *backup;
+ cfmakeraw(&tattr);
+ if (tcsetattr(STDOUT_FILENO, TCSANOW, &tattr) != 0)
+ return -1;
+
+ return 0;
+}
+
int
main(int argc, char *argv[])
{
static const struct timeval mindelay = { .tv_sec = 0, .tv_usec = 100 };
struct timeval maxdelay;
+ char isterm;
+ struct termios saved;
+
struct replay_setup *setup = NULL;
struct replay_step *step = NULL;
char streams[6] = {0}; /* IOSI - in, out, signal,info */
@@ -286,6 +305,10 @@ main(int argc, char *argv[])
replay_set_delay_max(setup, &maxdelay);
replay_set_delay_min(setup, &mindelay);
+ isterm = isatty(STDOUT_FILENO);
+ if (isterm && termraw(&saved) != 0)
+ err(EXIT_FAILURE, _("failed to set terminal to raw mode"));
+
do {
rc = replay_get_next_step(setup, streams, &step);
if (rc)
@@ -300,6 +323,9 @@ main(int argc, char *argv[])
rc = replay_emit_step_data(setup, step, STDOUT_FILENO);
} while (rc == 0);
+ if (isterm)
+ tcsetattr(STDOUT_FILENO, TCSADRAIN, &saved);
+
if (step && rc < 0)
err(EXIT_FAILURE, _("%s: log file error"), replay_step_get_filename(step));
else if (rc < 0)
--
2.20.1
reply other threads:[~2020-07-10 12:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAOW54GXn9KWBEquqCyuBOnADk-MLXA0LpBqUj=kp138Z2KFLEA@mail.gmail.com' \
--to=soumendraganguly@gmail.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).