Skip to content

Commit

Permalink
Enable proper playback [-p] of curses sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
8vasu committed Aug 3, 2020
1 parent 4788f7f commit f9b25d5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions usr.bin/script/script.c
Expand Up @@ -427,6 +427,34 @@ consume(FILE *fp, off_t len, char *buf, int reg)
} \
} while (0/*CONSTCOND*/)

static void
termset(void)
{
struct termios traw;

ttyflg = isatty(STDOUT_FILENO);
if (!ttyflg)
return;

if (tcgetattr(STDOUT_FILENO, &tt) == -1)
err(1, "tcgetattr");

traw = tt;
cfmakeraw(&traw);
traw.c_lflag |= ISIG;
if (tcsetattr(STDOUT_FILENO, TCSANOW, &traw) == -1)
err(1, "tcsetattr");
}

static void
termreset(void)
{
if (ttyflg)
tcsetattr(STDOUT_FILENO, TCSADRAIN, &tt);

ttyflg = 0;
}

static void
playback(FILE *fp)
{
Expand Down Expand Up @@ -470,8 +498,11 @@ playback(FILE *fp)
ctime(&tclock));
tsi = tso;
(void)consume(fp, stamp.scr_len, buf, reg);
termset();
atexit(termreset);
break;
case 'e':
termreset();
if (!qflg)
(void)printf("\nScript done on %s",
ctime(&tclock));
Expand Down

0 comments on commit f9b25d5

Please sign in to comment.