I am currently working on a complete shell built in C.
I want to implement a bash history and navigation using arrows keys through my double linked list but I am having some troubles with TermCaps and properly
setting up read()
function.
Here is how I set up my terminal :
static int set_terminal_mode(t_shell *shell, const int mode)
{
char *term_name;
if (mode == 0)
{
if ((term_name = getenv("TERM")) == NULL)
return (-1);
ioctl(0, TCGETS, &shell->term);
shell->term.c_lflag &= ~ICANON;
shell->term.c_cc[VMIN] = 1;
shell->term.c_cc[VTIME] = 0;
ioctl(0, TCGETS, &shell->term_save);
ioctl(0, TCSETS, &shell->term);
}
if (mode == 1)
ioctl(0, TCSETS, &shell->term_save);
return (0);
}
I can catch when left or right key is pressed and then I use \r
to erase the line (which doesn't really work) but the main problem is that I cannot use the return key anymore (only display ^?
)
How can I fix this?