Quit from non-interactive mode using ctrl-c

When piping to tio it will automatically enter "non-interactive" mode
which means it will not react to any input key sequences but simple read
the input stream and write it to the tty device.

This also means that ctrl-t q can not be used to quit and so tio would
hang forever when used in non-interactive mode.

This change allows to send the standard termination signal by pressing
ctrl-c on tio in non-interactive mode to make it quit.
This commit is contained in:
Martin Lund 2022-07-20 17:59:13 +02:00
parent eadcc7e384
commit 5f46136b28
3 changed files with 77 additions and 45 deletions

View file

@ -27,15 +27,24 @@
#include "error.h"
#include "print.h"
#include "misc.h"
#include "tty.h"
static void signal_handler(int signum)
{
UNUSED(signum);
tio_printf("Received hangup signal!");
switch (signum)
{
case SIGHUP:
tio_printf("Received SIGHUP signal!");
break;
case SIGINT:
tio_printf("Received SIGINT signal!");
break;
}
exit(EXIT_FAILURE);
}
void signal_handlers_install(void)
{
signal(SIGHUP, signal_handler);
signal(SIGINT, signal_handler);
}