Make scriptreplay set terminal to raw mode
This commit is contained in:
parent
6e7fb6c49a
commit
edb088ffbe
|
@ -28,6 +28,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <termios.h>
|
||||||
|
|
||||||
#include "c.h"
|
#include "c.h"
|
||||||
#include "xalloc.h"
|
#include "xalloc.h"
|
||||||
|
@ -120,12 +121,30 @@ static void appendchr(char *buf, size_t bufsz, int c)
|
||||||
buf[sz] = 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
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
static const struct timeval mindelay = { .tv_sec = 0, .tv_usec = 100 };
|
static const struct timeval mindelay = { .tv_sec = 0, .tv_usec = 100 };
|
||||||
struct timeval maxdelay;
|
struct timeval maxdelay;
|
||||||
|
|
||||||
|
char isterm;
|
||||||
|
struct termios saved;
|
||||||
|
|
||||||
struct replay_setup *setup = NULL;
|
struct replay_setup *setup = NULL;
|
||||||
struct replay_step *step = NULL;
|
struct replay_step *step = NULL;
|
||||||
char streams[6] = {0}; /* IOSI - in, out, signal,info */
|
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_max(setup, &maxdelay);
|
||||||
replay_set_delay_min(setup, &mindelay);
|
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 {
|
do {
|
||||||
rc = replay_get_next_step(setup, streams, &step);
|
rc = replay_get_next_step(setup, streams, &step);
|
||||||
if (rc)
|
if (rc)
|
||||||
|
@ -300,6 +323,9 @@ main(int argc, char *argv[])
|
||||||
rc = replay_emit_step_data(setup, step, STDOUT_FILENO);
|
rc = replay_emit_step_data(setup, step, STDOUT_FILENO);
|
||||||
} while (rc == 0);
|
} while (rc == 0);
|
||||||
|
|
||||||
|
if (isterm)
|
||||||
|
tcsetattr(STDOUT_FILENO, TCSADRAIN, &saved);
|
||||||
|
|
||||||
if (step && rc < 0)
|
if (step && rc < 0)
|
||||||
err(EXIT_FAILURE, _("%s: log file error"), replay_step_get_filename(step));
|
err(EXIT_FAILURE, _("%s: log file error"), replay_step_get_filename(step));
|
||||||
else if (rc < 0)
|
else if (rc < 0)
|
||||||
|
|
Loading…
Reference in New Issue