summaryrefslogtreecommitdiffstats
path: root/src/c_init.c
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-09-08 18:07:14 +0200
committersalad <fmoenne-@student.le-101.fr>2020-09-08 18:07:14 +0200
commite9d902e8d9475785952355e228dcffd223bac8be (patch)
treec4995c9e701f3128999849ccec88b0be84627800 /src/c_init.c
parentadded TODO, this is a baseline before reformatting (diff)
download42-minishell-e9d902e8d9475785952355e228dcffd223bac8be.tar.gz
42-minishell-e9d902e8d9475785952355e228dcffd223bac8be.tar.bz2
42-minishell-e9d902e8d9475785952355e228dcffd223bac8be.tar.xz
42-minishell-e9d902e8d9475785952355e228dcffd223bac8be.tar.zst
42-minishell-e9d902e8d9475785952355e228dcffd223bac8be.zip
clean, ca fait ziz
Diffstat (limited to 'src/c_init.c')
-rw-r--r--src/c_init.c51
1 files changed, 13 insertions, 38 deletions
diff --git a/src/c_init.c b/src/c_init.c
index 35296e4..ad18d92 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -19,8 +19,7 @@
#include "c_init.h"
#include "c_input.h"
-#include "m_prompt.h"
-#include "m_loop.h"
+#include "c_utils.h"
#include "s_struct.h"
static char
@@ -49,7 +48,8 @@ static char
}
static t_caps
- *c_get_struct(int mode, t_caps *src)
+ *c_get_struct(int mode,
+ t_caps *src)
{
static t_caps *caps;
@@ -60,7 +60,7 @@ static t_caps
return (caps);
}
-static int16_t
+int16_t
c_set_term_raw(uint8_t mode)
{
struct termios tios;
@@ -85,7 +85,9 @@ static int16_t
}
int16_t
- c_process_key(char *buf, t_caps *tcaps, t_msh *msh)
+ c_process_key(char *buf,
+ t_caps *tcaps,
+ t_msh *msh)
{
static char *line = NULL;
int i;
@@ -102,55 +104,28 @@ int16_t
}
else
{
- /* if (!(c_catch_tcaps(buf, tcaps, msh)) */
- /* return (-1); */
if (strncmp(buf, tgetstr("kr", NULL), ft_strlen(tgetstr("kr", NULL))) == 0)
{
- if (tcaps->cpos <= ft_strlen(line))
- {
- tputs(tgetstr("nd", NULL), 1, ft_putchar);
- tcaps->cpos++;
- }
- return (1);
+ return (c_key_right(ft_strlen(line), tcaps));
}
else if (buf[0] == '\n')
{
- write(1, buf, ft_strlen(buf));
- tputs(tgetstr("cr", NULL), 1, ft_putchar);
- c_set_term_raw(0);
- m_parse_and_run_line(line, msh);
- line = NULL;
- tcaps->cpos = 0;
- tputs(tgetstr("cr", NULL), 1, ft_putchar);
- c_set_term_raw(1);
- m_prompt_psx(1, msh);
- return (1);
+ return (c_new_line(buf, &line, msh, tcaps));
}
else if (strncmp(buf, tgetstr("kl", NULL), ft_strlen(tgetstr("kl", NULL))) == 0)
{
- if (tcaps->cpos >= 1)
- {
- tputs(tgetstr("le", NULL), 1, ft_putchar);
- tcaps->cpos--;
- return (1);
- }
+ return (c_key_left(ft_strlen(line), tcaps));
}
else if (strncmp(buf, tgetstr("kb", NULL), ft_strlen(tgetstr("kb", NULL))) == 0)
{
- if (tcaps->cpos >= 1)
- {
- line = c_delchar(line, tcaps->cpos);
- tcaps->cpos -= 1;
- tputs(tgetstr("le", NULL), 1, ft_putchar);
- tputs(tgetstr("dc", NULL), 1, ft_putchar);
- }
- return (1);
+ return (c_back_slash(&line, tcaps));
}
}
return (0);
}
-int16_t c_init_tcaps(t_msh *msh)
+int16_t
+ c_init_tcaps(t_msh *msh)
{
t_caps tcaps;
char *bp;