mise a la norme edition de ligne
This commit is contained in:
parent
f70722a5ae
commit
b4e7d8ab5e
12 changed files with 186 additions and 128 deletions
|
|
@ -126,6 +126,8 @@ history/history_parsing_toolz.c\
|
|||
history/history_parsing_toolz_2.c\
|
||||
history/list_toolz.c\
|
||||
history/surch_in_history.c\
|
||||
init_history.c\
|
||||
init_line.c\
|
||||
job-control/builtin_bg.c\
|
||||
job-control/builtin_fg.c\
|
||||
job-control/builtin_jobs.c\
|
||||
|
|
@ -195,6 +197,7 @@ line-editing/copy_cut_paste.c\
|
|||
line-editing/ft_prompt.c\
|
||||
line-editing/get_key.c\
|
||||
line-editing/home_end.c\
|
||||
line-editing/init_termcaps.c\
|
||||
line-editing/lib_line_editing/tool_line.c\
|
||||
line-editing/lib_line_editing/tool_line_2.c\
|
||||
line-editing/lib_line_editing/toolz.c\
|
||||
|
|
@ -216,7 +219,6 @@ main/ft_putast2.c\
|
|||
main/lib_expansion.c\
|
||||
main/main.c\
|
||||
main/remove_trailing_esc_nl.c\
|
||||
main/shell_exit.c\
|
||||
main/shell_get_avdata.c\
|
||||
main/shell_get_opts.c\
|
||||
main/shell_init.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/05 19:37:38 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/07 17:36:15 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -160,5 +160,8 @@ char *ft_strdupi_w(char const *s);
|
|||
void ft_add_str_in_history(char *str);
|
||||
void ft_init_history(void);
|
||||
char *ft_history_parsing(void);
|
||||
struct termios *ft_save_termios(int save);
|
||||
void ft_init_termios(void);
|
||||
void readline_init(char *prompt);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
37
42sh/src/init_history.c
Normal file
37
42sh/src/init_history.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* init_history.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 17:34:23 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/07 17:34:35 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void ft_init_history(void)
|
||||
{
|
||||
int fd;
|
||||
char *str;
|
||||
char *home;
|
||||
char *path;
|
||||
|
||||
if (!(home = ft_getenv(data_singleton()->env, "HOME")))
|
||||
return ;
|
||||
path = ft_str3join(home, "/", ".42sh_history");
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return ;
|
||||
while (get_next_line(fd, &str) > 0)
|
||||
{
|
||||
ft_push_back_history(&data_singleton()->line.list_beg,
|
||||
ft_create_history_list(str));
|
||||
free(str);
|
||||
}
|
||||
free(path);
|
||||
free(str);
|
||||
close(fd);
|
||||
}
|
||||
44
42sh/src/init_line.c
Normal file
44
42sh/src/init_line.c
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* init_line.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 17:34:44 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/07 17:35:09 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void ft_init_line(void)
|
||||
{
|
||||
data_singleton()->line.input = NULL;
|
||||
data_singleton()->line.copy_tmp = NULL;
|
||||
data_singleton()->line.pos = 0;
|
||||
data_singleton()->line.prompt_size = 0;
|
||||
data_singleton()->line.list_size = 0;
|
||||
data_singleton()->line.list_end = NULL;
|
||||
data_singleton()->line.list_beg = NULL;
|
||||
data_singleton()->line.opt = 0;
|
||||
}
|
||||
|
||||
void readline_init(char *prompt)
|
||||
{
|
||||
static int beg = 0;
|
||||
|
||||
if (!beg)
|
||||
{
|
||||
ft_init_line();
|
||||
ft_init_history();
|
||||
ft_save_termios(1);
|
||||
beg = 1;
|
||||
}
|
||||
ft_init_termios();
|
||||
if (STR)
|
||||
ft_strdel(&STR);
|
||||
data_singleton()->line.list_cur = data_singleton()->line.list_beg;
|
||||
POS = 0;
|
||||
prompt ? ft_putstr(prompt) : ft_prompt();
|
||||
}
|
||||
|
|
@ -6,20 +6,45 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/16 14:27:57 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/07 17:32:22 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
static int ft_git_status(void)
|
||||
static int promt_git_status(int fd)
|
||||
{
|
||||
int pip[2];
|
||||
int len;
|
||||
char *tmp;
|
||||
char *line;
|
||||
pid_t soon;
|
||||
char *exec[] = {"git", "status", "--porcelain", "--branch", NULL};
|
||||
|
||||
get_next_line(fd, &line);
|
||||
tmp = line;
|
||||
if (ft_strrchr(line, '/'))
|
||||
line = ft_strdup(ft_strrchr(line, '/') + 1);
|
||||
else
|
||||
line = ft_strdup(line + 3);
|
||||
ft_printf("\x1b[38;5;47mgit:(\x1b[38;5;203m%s\x1b[38;5;47m)", line);
|
||||
free(tmp);
|
||||
if (!get_next_line(fd, &tmp))
|
||||
printf("\x1b[38;5;83m %C ", L'✓');
|
||||
else
|
||||
{
|
||||
printf("\x1b[38;5;1m %C ", L'✗');
|
||||
while (get_next_line(fd, &tmp))
|
||||
free(tmp);
|
||||
}
|
||||
len = ft_strlen(line);
|
||||
ft_strdel(&line);
|
||||
fflush(NULL);
|
||||
return (len + 8);
|
||||
}
|
||||
|
||||
static int ft_git_status(void)
|
||||
{
|
||||
static char *exec[] = {"git", "status", "--porcelain", "--branch", NULL};
|
||||
int pip[2];
|
||||
pid_t soon;
|
||||
|
||||
pipe(pip);
|
||||
if ((soon = fork()))
|
||||
|
|
@ -28,28 +53,7 @@ static int ft_git_status(void)
|
|||
if (WEXITSTATUS(soon))
|
||||
return (-1);
|
||||
close(pip[1]);
|
||||
get_next_line(pip[0], &line);
|
||||
tmp = line;
|
||||
if (ft_strrchr(line, '/'))
|
||||
{
|
||||
line = ft_strdup(ft_strrchr(line, '/') + 1);
|
||||
ft_printf("\x1b[38;5;47mgit:(\x1b[38;5;203m%s\x1b[38;5;47m)", line);
|
||||
free(tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
line = ft_strdup(line + 3);
|
||||
ft_printf("\x1b[38;5;47mgit:(\x1b[38;5;203m%s\x1b[38;5;47m)", line);
|
||||
free(tmp);
|
||||
}
|
||||
if (!get_next_line(pip[0], &tmp))
|
||||
printf("\x1b[38;5;83m %C ", L'✓');
|
||||
else
|
||||
{
|
||||
printf("\x1b[38;5;1m %C ", L'✗');
|
||||
free(tmp);
|
||||
}
|
||||
fflush(NULL);
|
||||
return (promt_git_status(pip[0]));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -58,9 +62,7 @@ static int ft_git_status(void)
|
|||
close(pip[0]);
|
||||
execve("/usr/bin/git", exec, data_singleton()->env);
|
||||
}
|
||||
len = ft_strlen(line);
|
||||
ft_strdel(&line);
|
||||
return (len + 8);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int ft_currend_dir(void)
|
||||
|
|
@ -88,13 +90,14 @@ static int ft_currend_dir(void)
|
|||
return (ft_strlen(currend_dir + 1));
|
||||
}
|
||||
|
||||
void ft_prompt()
|
||||
void ft_prompt(void)
|
||||
{
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
ret = 0;
|
||||
do_job_notification();
|
||||
if (ft_getenv(data_singleton()->env, "?") && ft_atoi(ft_getenv(data_singleton()->env, "?")))
|
||||
if (ft_getenv(data_singleton()->env, "?") &&
|
||||
ft_atoi(ft_getenv(data_singleton()->env, "?")))
|
||||
printf("\x1b[38;5;1m%C ", L'➜');
|
||||
else
|
||||
printf("\x1b[38;5;10m%C ", L'➜');
|
||||
|
|
|
|||
41
42sh/src/line-editing/init_termcaps.c
Normal file
41
42sh/src/line-editing/init_termcaps.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* init_termcaps.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 17:33:41 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/07 17:36:38 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
struct termios *ft_save_termios(int save)
|
||||
{
|
||||
static struct termios *term_save = NULL;
|
||||
|
||||
if (save < 0)
|
||||
{
|
||||
free(term_save);
|
||||
return (NULL);
|
||||
}
|
||||
if (save > 0)
|
||||
{
|
||||
term_save = (struct termios *)malloc(sizeof(struct termios));
|
||||
tcgetattr(0, term_save);
|
||||
}
|
||||
return (term_save);
|
||||
}
|
||||
|
||||
void ft_init_termios(void)
|
||||
{
|
||||
struct termios term;
|
||||
|
||||
tcgetattr(0, &term);
|
||||
term.c_lflag &= ~(ECHO | ICANON | ISIG);
|
||||
term.c_cc[VMIN] = 1;
|
||||
term.c_cc[VTIME] = 0;
|
||||
tcsetattr(0, TCSANOW, &term);
|
||||
}
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/20 19:07:52 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/05 19:36:44 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/07 17:32:58 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void ft_clear_window(void)
|
||||
void ft_clear_window(void)
|
||||
{
|
||||
pid_t soon_pid;
|
||||
char *tab_str[2];
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/07 11:00:28 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/20 14:32:08 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/07 17:32:44 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ long long ft_pow(int nbr, int power)
|
|||
return (ret);
|
||||
}
|
||||
|
||||
char *ft_strdupi_w(char const *s)
|
||||
char *ft_strdupi_w(char const *s)
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/08 12:35:11 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/28 11:11:26 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/07 17:33:05 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int ft_put(int nb)
|
||||
int ft_put(int nb)
|
||||
{
|
||||
write(1, &nb, 1);
|
||||
return (1);
|
||||
|
|
|
|||
|
|
@ -6,95 +6,12 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/28 10:43:33 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/07 17:35:13 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void ft_init_line(void)
|
||||
{
|
||||
data_singleton()->line.input = NULL;
|
||||
data_singleton()->line.copy_tmp = NULL;
|
||||
data_singleton()->line.pos = 0;
|
||||
data_singleton()->line.prompt_size = 0;
|
||||
data_singleton()->line.list_size = 0;
|
||||
data_singleton()->line.list_end = NULL;
|
||||
data_singleton()->line.list_beg = NULL;
|
||||
data_singleton()->line.opt = 0;
|
||||
}
|
||||
|
||||
void ft_init_history(void)
|
||||
{
|
||||
int fd;
|
||||
char *str;
|
||||
char *home;
|
||||
char *path;
|
||||
|
||||
if (!(home = ft_getenv(data_singleton()->env, "HOME")))
|
||||
return ;
|
||||
path = ft_str3join(home, "/", ".42sh_history");
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return ;
|
||||
while (get_next_line(fd, &str) > 0)
|
||||
{
|
||||
ft_push_back_history(&data_singleton()->line.list_beg,
|
||||
ft_create_history_list(str));
|
||||
free(str);
|
||||
}
|
||||
free(path);
|
||||
free(str);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
struct termios *ft_save_termios(int save)
|
||||
{
|
||||
static struct termios *term_save = NULL;
|
||||
|
||||
if (save < 0)
|
||||
{
|
||||
free(term_save);
|
||||
return (NULL);
|
||||
}
|
||||
if (save > 0)
|
||||
{
|
||||
term_save = (struct termios *)malloc(sizeof(struct termios));
|
||||
tcgetattr(0, term_save);
|
||||
}
|
||||
return (term_save);
|
||||
}
|
||||
|
||||
void ft_init_termios(void)
|
||||
{
|
||||
struct termios term;
|
||||
|
||||
tcgetattr(0, &term);
|
||||
term.c_lflag &= ~(ECHO | ICANON | ISIG);
|
||||
term.c_cc[VMIN] = 1;
|
||||
term.c_cc[VTIME] = 0;
|
||||
tcsetattr(0, TCSANOW, &term);
|
||||
}
|
||||
|
||||
void readline_init(char *prompt)
|
||||
{
|
||||
static int beg = 0;
|
||||
|
||||
if (!beg)
|
||||
{
|
||||
ft_init_line();
|
||||
ft_init_history();
|
||||
ft_save_termios(1);
|
||||
beg = 1;
|
||||
}
|
||||
ft_init_termios();
|
||||
if (STR)
|
||||
ft_strdel(&STR);
|
||||
data_singleton()->line.list_cur = data_singleton()->line.list_beg;
|
||||
POS = 0;
|
||||
prompt ? ft_putstr(prompt) : ft_prompt();
|
||||
}
|
||||
|
||||
char *readline(char *prompt)
|
||||
{
|
||||
char *input;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 15:24:35 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/07 17:28:34 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -94,6 +94,6 @@ int main(int ac, char **av)
|
|||
}
|
||||
else
|
||||
non_interactive_shell(shell_get_avdata());
|
||||
builtin_exit(0);
|
||||
// builtin_exit(0);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
13
42sh/test
13
42sh/test
|
|
@ -1,3 +1,14 @@
|
|||
[7m[33m shell_init.c [1m[34m28 [0minteractive shell settings[0m
|
||||
[7m[33m main.c [1m[34m86 [0m[0m
|
||||
[7m[33m main.c [1m[34m86 [0m[0m
|
||||
[7m[33m shell_init.c [1m[34m27 [0minteractive shell settings[0m
|
||||
[7m[33m token_print.c [1m[34m29 [0m13:[ls][0m
|
||||
[7m[33m token_print.c [1m[34m29 [0m13:[ls][0m
|
||||
[7m[33m token_print.c [1m[34m29 [0m13:[ls][0m
|
||||
[7m[33m token_print.c [1m[34m29 [0m13:[ls][0m
|
||||
[7m[33m token_print.c [1m[34m29 [0m13:[cd][0m
|
||||
[7m[33m token_print.c [1m[34m29 [0m13:[cd][0m
|
||||
[7m[33m token_print.c [1m[34m29 [0m13:[-][0m
|
||||
[7m[33m token_print.c [1m[34m29 [0m13:[cd][0m
|
||||
[7m[33m token_print.c [1m[34m29 [0m13:[includes][0m
|
||||
[7m[33m token_print.c [1m[34m29 [0m13:[cd][0m
|
||||
[7m[33m token_print.c [1m[34m29 [0m13:[-][0m
|
||||
|
|
|
|||
Loading…
Reference in a new issue