tests ok pour modifier fonctionnement de minishell

This commit is contained in:
hugogogo
2021-11-05 16:26:27 +01:00
parent 5a98927eff
commit 0a33916c75
4 changed files with 95 additions and 94 deletions

43
test_rl_modif.c Normal file
View File

@@ -0,0 +1,43 @@
# include <stdlib.h>
# include <unistd.h>
# include <readline/readline.h>
# include <signal.h>
void handler_sigint(int id)
{
(void)id;
write(1, "\n", 1);
rl_replace_line("", 1);
rl_on_new_line();
rl_redisplay();
}
int main(int argc, char *argv[], char *envp[])
{
(void)argc;
(void)argv;
char *line_input;
char *prompt;
signal(SIGINT, handler_sigint);
line_input = NULL;
prompt = strdup("\e[0;31mtest>\e[0m ");
while (1)
{
if (line_input)
free(line_input);
line_input = readline(prompt);
if (line_input && *line_input)
{
write(1, line_input, strlen(line_input));
write(1, "\n", 1);
}
else if (!line_input)
{
write(1, "exit\n", 5);
exit(0);
}
}
return (0);
}