diff options
author | salad <fmoenne-@student.le-101.fr> | 2020-09-07 16:56:21 +0200 |
---|---|---|
committer | salad <fmoenne-@student.le-101.fr> | 2020-09-07 16:56:21 +0200 |
commit | 99b5bdef1f069fa5d73bc44bf2714f380ed3d6e4 (patch) | |
tree | b2482b9b716e90c2732f3a918e4c58824fe1fad8 /src/c_init.c | |
parent | somewhere (diff) | |
download | 42-minishell-99b5bdef1f069fa5d73bc44bf2714f380ed3d6e4.tar.gz 42-minishell-99b5bdef1f069fa5d73bc44bf2714f380ed3d6e4.tar.bz2 42-minishell-99b5bdef1f069fa5d73bc44bf2714f380ed3d6e4.tar.xz 42-minishell-99b5bdef1f069fa5d73bc44bf2714f380ed3d6e4.tar.zst 42-minishell-99b5bdef1f069fa5d73bc44bf2714f380ed3d6e4.zip |
hoHOOOOOOOOO
Diffstat (limited to 'src/c_init.c')
-rw-r--r-- | src/c_init.c | 167 |
1 files changed, 84 insertions, 83 deletions
diff --git a/src/c_init.c b/src/c_init.c index 5d07ed1..9dde271 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -18,6 +18,7 @@ #include <libft.h> #include "c_init.h" +#include "c_input.h" #include "m_prompt.h" #include "m_loop.h" #include "s_struct.h" @@ -26,11 +27,11 @@ static char *ft_strjoin_m(char *s1, char *s2) { - size_t i; - size_t j; - char *dst; - size_t size1; - size_t size2; + size_t i; + size_t j; + char *dst; + size_t size1; + size_t size2; i = -1; j = -1; @@ -48,21 +49,21 @@ 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; + static t_caps *caps; - if (mode == 1) - { - caps = src; - } - return (caps); + if (mode == 1) + { + caps = src; + } + return (caps); } static int16_t - c_set_term_raw(uint8_t mode) + c_set_term_raw(uint8_t mode) { - struct termios tios; + struct termios tios; ft_memset(&tios, 0, sizeof(tios)); tcgetattr(STDIN_FILENO, &tios); @@ -79,87 +80,87 @@ static int16_t tios.c_oflag |= (OPOST); } tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios); - tputs(tgetstr("cd", NULL), 1, ft_putchar); + mode ? tputs(tgetstr("ns", NULL), 1, ft_putchar) : 0; return (1); } int16_t - c_process_key(t_msh *msh, char *buf) + c_process_key(t_msh *msh, char *buf) { - int i; - static char *line; + int i; + static char *line = NULL; - i = -1; - if (line == NULL) - if (!(line = ft_calloc(2, sizeof(char)))) - return (0); - if (ft_isprint(buf[0])) - { - if (*buf == 'q') - { - tputs(tgetstr("ve", NULL), 1, ft_putchar); - exit(0); - } - else if (*buf == '\n') - tputs(tgetstr("nl", NULL), 1, ft_putchar); - line = ft_strjoin_m(line, buf); - ft_printf("line [%s][%lu]", line, ft_strlen(line)); /* ft_redraw */ - } - else - { - if (strncmp(buf, tgetstr("kr", NULL), ft_strlen(tgetstr("kr", NULL))) == 0) - { - tputs(tgetstr("nd", NULL), 1, ft_putchar); - return (1); - } - else if (buf[0] == '\n') - { - write(1, buf, ft_strlen(buf)); - tputs(tgetstr("cr", NULL), 1, ft_putchar); - m_parse_and_run_line(line, msh); - tputs(tgetstr("cr", NULL), 1, ft_putchar); - ft_memdel((void**)&line); - m_prompt_psx(1, msh); - return (1); - } - else if (strncmp(buf, tgetstr("kl", NULL), ft_strlen(tgetstr("kl", NULL))) == 0) - { - tputs(tgetstr("le", NULL), 1, ft_putchar); - return (1); - } - else if (strncmp(buf, tgetstr("kb", NULL), ft_strlen(tgetstr("kb", NULL))) == 0) - { - tputs(tgetstr("le", NULL), 1, ft_putchar); - tputs(tgetstr("dc", NULL), 1, ft_putchar); - return (1); - } - } - return (0); + i = -1; + if (line == NULL) + if (!(line = ft_calloc(2, sizeof(char)))) + return (0); + if (ft_isprint(buf[0])) + { + if (*buf == 'q') + { + tputs(tgetstr("ve", NULL), 1, ft_putchar); + c_set_term_raw(0); + exit(0); + } + line = ft_strjoin_m(line, buf); + c_redraw_line(line, msh); + } + else + { + if (strncmp(buf, tgetstr("kr", NULL), ft_strlen(tgetstr("kr", NULL))) == 0) + { + tputs(tgetstr("nd", NULL), 1, ft_putchar); + return (1); + } + else if (buf[0] == '\n') + { + write(1, buf, ft_strlen(buf)); + tputs(tgetstr("cr", NULL), 1, ft_putchar); + m_parse_and_run_line(line, msh); + line = NULL; + tputs(tgetstr("cr", NULL), 1, ft_putchar); + m_prompt_psx(1, msh); + return (1); + } + else if (strncmp(buf, tgetstr("kl", NULL), ft_strlen(tgetstr("kl", NULL))) == 0) + { + tputs(tgetstr("le", NULL), 1, ft_putchar); + return (1); + } + else if (strncmp(buf, tgetstr("kb", NULL), ft_strlen(tgetstr("kb", NULL))) == 0) + { + tputs(tgetstr("le", NULL), 1, ft_putchar); + tputs(tgetstr("dc", NULL), 1, ft_putchar); + return (1); + } + } + return (0); } int16_t c_init_tcaps(t_msh *msh) { - t_caps tcaps; - char *bp; - char *term; - char nread[5]; - int ret; + t_caps tcaps; + char *bp; + char *term; + char nread[5]; + int ret; - bp = NULL; - term = getenv("TERM"); - if (!tgetent(bp, term)) - return (-1); + bp = NULL; + term = getenv("TERM"); + if (!tgetent(bp, term)) + return (-1); - c_set_term_raw(1); - c_get_struct(1, &tcaps); - while (1) - { - ft_bzero(nread, 5); - if (!(read(STDIN_FILENO, nread, 4))) - return (0); + ft_printf("my term is %s", term); + c_set_term_raw(1); + c_get_struct(1, &tcaps); + while (1) + { + ft_bzero(nread, 5); + if (!(read(STDIN_FILENO, nread, 4))) + return (0); tputs(tgetstr("vi", NULL), 1, ft_putchar); - ret = c_process_key(msh, nread); + ret = c_process_key(msh, nread); tputs(tgetstr("ve", NULL), 1, ft_putchar); - } - return (1); + } + return (1); } |