test prompt and readline
This commit is contained in:
84
srcs/main.c
84
srcs/main.c
@@ -1,7 +1,89 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
||||||
|
/* Updated: 2021/10/04 06:13:56 by lperrey ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int main(void)
|
#define TERM_RESET "\e[0m"
|
||||||
|
#define TERM_BLACK "\e[0;30m"
|
||||||
|
#define TERM_GRAY "\e[1;30m"
|
||||||
|
#define TERM_RED "\e[0;31m"
|
||||||
|
#define TERM_LIGHT_RED "\e[1;31m"
|
||||||
|
#define TERM_GREEN "\e[0;32m"
|
||||||
|
#define TERM_LIGHT_GREEN "\e[1;32m"
|
||||||
|
#define TERM_BROWN "\e[0;33m"
|
||||||
|
#define TERM_YELLOW "\e[1;33m"
|
||||||
|
#define TERM_BLUE "\e[0;34m"
|
||||||
|
#define TERM_LIGHT_BLUE "\e[1;34m"
|
||||||
|
#define TERM_PURPLE "\e[0;35m"
|
||||||
|
#define TERM_LIGHT_PURPLE "\e[1;35m"
|
||||||
|
#define TERM_CYAN "\e[0;36m"
|
||||||
|
#define TERM_LIGHT_CYAN "\e[1;36m"
|
||||||
|
#define TERM_LIGHT_GRAY "\e[0;37m"
|
||||||
|
#define TERM_WHITE "\e[1;37m"
|
||||||
|
|
||||||
|
char *ft_strjoinfree_s1(char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = ft_strjoin(s1, s2);
|
||||||
|
free(s1);
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_strjoinfree_s2(const char *s1, char *s2)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = ft_strjoin(s1, s2);
|
||||||
|
free(s2);
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[], char *envp[])
|
||||||
|
{
|
||||||
|
char *path;
|
||||||
|
char *prompt_base;
|
||||||
|
char *prompt;
|
||||||
|
char *line_input;
|
||||||
|
|
||||||
|
(void)argc;
|
||||||
|
(void)argv;
|
||||||
|
(void)envp;
|
||||||
|
ft_putendl_arr_fd(envp, 1);
|
||||||
|
path = getenv("PATH");
|
||||||
|
//printf("%s", path);
|
||||||
|
prompt_base = ft_strjoin(TERM_LIGHT_GREEN, getenv("USER"));
|
||||||
|
prompt_base = ft_strjoinfree_s1(prompt_base, "@");
|
||||||
|
prompt_base = ft_strjoinfree_s1(prompt_base, getenv("NAME"));
|
||||||
|
prompt_base = ft_strjoinfree_s1(prompt_base, TERM_RESET":"TERM_LIGHT_BLUE);
|
||||||
|
prompt = malloc(1);
|
||||||
|
line_input = NULL;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
if (line_input)
|
||||||
|
free(line_input);
|
||||||
|
free(prompt);
|
||||||
|
prompt = ft_strjoinfree_s2(prompt_base, getcwd(NULL, 0));
|
||||||
|
prompt = ft_strjoinfree_s1(prompt, TERM_RESET"€ ");
|
||||||
|
line_input = readline(prompt);
|
||||||
|
if (line_input && *line_input)
|
||||||
|
{
|
||||||
|
if (!ft_strncmp(line_input, "exit", 5))
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
else
|
||||||
|
printf("echo: %s\n", line_input);
|
||||||
|
}
|
||||||
|
//rl_redisplay();
|
||||||
|
//rl_on_new_line();
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user