Sami
Sami

Reputation: 135

How do you delete ^\ SIGQUIT characters from the terminal in C

So I'm trying to reproduce bash, and when I press control + \ in bash it does nothing. So I'm trying to reproduce that behavior this is my code.

# include <signal.h>
# include <readline/readline.h>
# include <readline/history.h>
# include <stdlib.h>
# include <unistd.h>

void    sig_handler(int sig)
{
    write(2, "\b \b", 2);
}

int main(void)
{
    signal(SIGQUIT, sig_handler);
    while (1)
    {
        char *line = readline("test> ");
        if (!line)
            break;
        free(line);
    }
    return (0);
}

When I press control + \ , it works the first time but then when I press it again it starts showing the ^ character, so how am I supposed to do this? I'm on macOS btw.

to compile this code run gcc main.c -lreadline

Upvotes: 0

Views: 106

Answers (0)

Related Questions