vty/cbits/get_tty_erase.c
Jonathan Daugherty 4362b3cb1c Add Graphics.Vty.Config.getTtyEraseChar
This commit adds getTtyEraseChar. This function queries the kernel
for the current terminal's settings to obtain the character assigned
by the "stty erase" command. The "erase" character indicates which
input character the terminal should interpret to mean "backspace" when
the terminal is in canonical input mode. Vty applications run with
canonical mode disabled, but even in those cases some users may want
their "stty erase" setting honored by Vty's input-handling so that
incoming erase characters (according to stty) result in "KBS" key events
being delivered to the application.
2020-02-27 09:46:04 -08:00

19 lines
412 B
C

#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
// Given a file descriptor for a terminal, get the ERASE character for
// the terminal. If the terminal info cannot be obtained, this returns
// zero.
char vty_get_tty_erase(int fd)
{
struct termios trm;
if (0 == tcgetattr(fd, &trm)) {
return (char) trm.c_cc[VERASE];
} else {
return (char) 0;
}
}