Merge branch 'master' of github.com:jzck/42sh
This commit is contained in:
commit
e4939b9902
7 changed files with 95 additions and 53 deletions
|
|
@ -268,6 +268,7 @@ line_editing/queue.c\
|
|||
line_editing/readline.c\
|
||||
line_editing/resize.c\
|
||||
line_editing/underline_function.c\
|
||||
line_editing/underline_reset.c\
|
||||
main/data_exit.c\
|
||||
main/data_init.c\
|
||||
main/data_singleton.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/22 20:59:35 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/22 21:14:55 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -129,6 +129,9 @@ void sigwinch_resize(int sig);
|
|||
size_t ft_hist_len(void);
|
||||
void underline_right(char **str, size_t *pos, size_t pos_ref);
|
||||
void underline_left(char **str, size_t *pos, size_t pos_ref);
|
||||
void reset_term(char **str, size_t *pos);
|
||||
void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp);
|
||||
int reset_term_hard(void);
|
||||
|
||||
int ft_read_stdin(char **input);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 11:12:05 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/20 15:43:34 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/22 21:34:39 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -30,8 +30,9 @@ int exec_var(t_btree **ast)
|
|||
node = (*ast)->item;
|
||||
av = token_to_argv(node->data.cmd.token, 1);
|
||||
set_var(av[0], &var, &value);
|
||||
if (ft_getenv(data_singleton()->env, var))
|
||||
return (0);
|
||||
builtin_setenv("internal", (char*[]){"local", var, value, 0}, NULL);
|
||||
ft_strdel(&var);
|
||||
ft_strdel(&value);
|
||||
ft_tabdel(&av);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/16 23:38:29 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 19:52:58 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,54 +6,12 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/22 20:58:12 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/22 21:14:34 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
static void reset_term(char **str, size_t *pos)
|
||||
{
|
||||
size_t pos_ref;
|
||||
|
||||
pos_ref = *pos;
|
||||
if (*pos)
|
||||
{
|
||||
--(*pos);
|
||||
ft_get_beggin_with_curs(*str, pos);
|
||||
}
|
||||
ft_puttermcaps("cd");
|
||||
ft_current_str(*str, *pos);
|
||||
ft_get_next_str(*str, pos);
|
||||
ft_putnc('\b', *pos - pos_ref);
|
||||
(*pos) = pos_ref;
|
||||
}
|
||||
|
||||
static void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp)
|
||||
{
|
||||
size_t pos_ref;
|
||||
|
||||
pos_ref = *pos;
|
||||
if (!data_singleton()->line.pos_tmp)
|
||||
pos_ref += ft_strlen(data_singleton()->line.copy_tmp);
|
||||
while (*copy_tmp)
|
||||
{
|
||||
--pos_ref;
|
||||
*str = ft_remove_imput(*str, pos_ref);
|
||||
++copy_tmp;
|
||||
}
|
||||
if (*pos)
|
||||
{
|
||||
--(*pos);
|
||||
ft_get_beggin_with_curs(*str, pos);
|
||||
}
|
||||
ft_puttermcaps("cd");
|
||||
ft_current_str(*str, *pos);
|
||||
ft_get_next_str(*str, pos);
|
||||
ft_putnc('\b', *pos - pos_ref);
|
||||
(*pos) = pos_ref;
|
||||
}
|
||||
|
||||
int ft_x(char **str, size_t *pos)
|
||||
{
|
||||
int ret;
|
||||
|
|
@ -70,7 +28,7 @@ int ft_x(char **str, size_t *pos)
|
|||
if (read(STDIN, &ret, sizeof(int)) < 0)
|
||||
return (-1);
|
||||
if ((*str)[*pos] == '\n')
|
||||
return (0);
|
||||
return (reset_term_hard());
|
||||
if (ret == FLECHE_GAUCHE)
|
||||
underline_left(str, pos, pos_ref);
|
||||
else if (ret == FLECHE_DROITE)
|
||||
|
|
@ -99,7 +57,7 @@ int ft_c(char **str, size_t *pos)
|
|||
if (read(STDIN, &ret, sizeof(int)) < 0)
|
||||
return (-1);
|
||||
if ((*str)[*pos] == '\n')
|
||||
return (0);
|
||||
return (reset_term_hard());
|
||||
if (ret == FLECHE_GAUCHE)
|
||||
underline_left(str, pos, pos_ref);
|
||||
else if (ret == FLECHE_DROITE)
|
||||
|
|
|
|||
|
|
@ -6,13 +6,24 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/22 20:55:24 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/22 20:56:54 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/22 21:28:31 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void underline_right(char **str, size_t *pos, size_t pos_ref)
|
||||
static void underline_check_end_of_line(char *str, size_t pos)
|
||||
{
|
||||
if (!str)
|
||||
return ;
|
||||
if (ft_nb_last_line(str, pos) == 0)
|
||||
{
|
||||
ft_putchar(str[pos]);
|
||||
ft_puttermcaps("le");
|
||||
}
|
||||
}
|
||||
|
||||
void underline_right(char **str, size_t *pos, size_t pos_ref)
|
||||
{
|
||||
if (!(*pos < ft_strlen(*str)))
|
||||
return ;
|
||||
|
|
@ -25,6 +36,7 @@ void underline_right(char **str, size_t *pos, size_t pos_ref)
|
|||
ft_puttermcaps("me");
|
||||
++(data_singleton()->line.pos_tmp);
|
||||
++(*pos);
|
||||
underline_check_end_of_line(*str, *pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -34,10 +46,11 @@ void underline_right(char **str, size_t *pos, size_t pos_ref)
|
|||
if (data_singleton()->line.pos_tmp)
|
||||
--(data_singleton()->line.pos_tmp);
|
||||
++(*pos);
|
||||
underline_check_end_of_line(*str, *pos);
|
||||
}
|
||||
}
|
||||
|
||||
void underline_left(char **str, size_t *pos, size_t pos_ref)
|
||||
void underline_left(char **str, size_t *pos, size_t pos_ref)
|
||||
{
|
||||
if (!*pos)
|
||||
return ;
|
||||
|
|
@ -46,6 +59,7 @@ void underline_left(char **str, size_t *pos, size_t pos_ref)
|
|||
--(*pos);
|
||||
ft_putchar('\b');
|
||||
ft_putchar((*str)[*pos]);
|
||||
underline_check_end_of_line(*str, *pos + 1);
|
||||
ft_putchar('\b');
|
||||
data_singleton()->line.copy_tmp = ft_remove_imput(data_singleton()->
|
||||
line.copy_tmp, data_singleton()->line.pos_tmp);
|
||||
|
|
@ -61,6 +75,7 @@ void underline_left(char **str, size_t *pos, size_t pos_ref)
|
|||
data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()->
|
||||
line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp);
|
||||
ft_putchar((*str)[*pos]);
|
||||
underline_check_end_of_line(*str, *pos + 1);
|
||||
ft_puttermcaps("me");
|
||||
ft_putchar('\b');
|
||||
}
|
||||
|
|
|
|||
64
42sh/src/line_editing/underline_reset.c
Normal file
64
42sh/src/line_editing/underline_reset.c
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* underline_reset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/22 21:14:07 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/22 21:16:24 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void reset_term(char **str, size_t *pos)
|
||||
{
|
||||
size_t pos_ref;
|
||||
|
||||
pos_ref = *pos;
|
||||
if (*pos)
|
||||
{
|
||||
--(*pos);
|
||||
ft_get_beggin_with_curs(*str, pos);
|
||||
}
|
||||
ft_puttermcaps("cd");
|
||||
ft_current_str(*str, *pos);
|
||||
ft_get_next_str(*str, pos);
|
||||
ft_putnc('\b', *pos - pos_ref);
|
||||
(*pos) = pos_ref;
|
||||
}
|
||||
|
||||
void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp)
|
||||
{
|
||||
size_t pos_ref;
|
||||
|
||||
pos_ref = *pos;
|
||||
if (!data_singleton()->line.pos_tmp)
|
||||
pos_ref += ft_strlen(data_singleton()->line.copy_tmp);
|
||||
while (*copy_tmp)
|
||||
{
|
||||
--pos_ref;
|
||||
*str = ft_remove_imput(*str, pos_ref);
|
||||
++copy_tmp;
|
||||
}
|
||||
if (*pos)
|
||||
{
|
||||
--(*pos);
|
||||
ft_get_beggin_with_curs(*str, pos);
|
||||
}
|
||||
ft_puttermcaps("cd");
|
||||
ft_current_str(*str, *pos);
|
||||
ft_get_next_str(*str, pos);
|
||||
ft_putnc('\b', *pos - pos_ref);
|
||||
(*pos) = pos_ref;
|
||||
}
|
||||
|
||||
int reset_term_hard(void)
|
||||
{
|
||||
ft_putnc('\b', ft_strlen(data_singleton()->line.copy_tmp));
|
||||
ft_putstr(data_singleton()->line.copy_tmp);
|
||||
ft_strdel(&data_singleton()->line.copy_tmp);
|
||||
data_singleton()->line.pos_tmp = 0;
|
||||
return (0);
|
||||
}
|
||||
Loading…
Reference in a new issue