diff options
author | salad <fmoenne-@student.le-101.fr> | 2020-09-02 15:32:39 +0200 |
---|---|---|
committer | salad <fmoenne-@student.le-101.fr> | 2020-09-02 15:32:39 +0200 |
commit | 40ce30cead49a9b3527420427dff1145ac0acad4 (patch) | |
tree | 0804e6f0ae6c47b94434e9b4a3b7732aa0434a92 /src/c_init.c | |
parent | cursor soon(TM) (diff) | |
download | 42-minishell-40ce30cead49a9b3527420427dff1145ac0acad4.tar.gz 42-minishell-40ce30cead49a9b3527420427dff1145ac0acad4.tar.bz2 42-minishell-40ce30cead49a9b3527420427dff1145ac0acad4.tar.xz 42-minishell-40ce30cead49a9b3527420427dff1145ac0acad4.tar.zst 42-minishell-40ce30cead49a9b3527420427dff1145ac0acad4.zip |
enter and keys, cat line until enter pressed inc
Diffstat (limited to 'src/c_init.c')
-rw-r--r-- | src/c_init.c | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/src/c_init.c b/src/c_init.c index 401d0e2..beccf8a 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -11,7 +11,6 @@ /* ************************************************************************** */ #include <unistd.h> -#include <stdio.h> #include <termios.h> #include <stdlib.h> #include <string.h> @@ -19,6 +18,8 @@ #include <libft.h> #include "c_init.h" +#include "m_prompt.h" +#include "s_struct.h" static char *ft_strjoin_m(char *s1, @@ -45,7 +46,7 @@ static char return (dst); } -t_caps +static t_caps *c_get_struct(int mode, t_caps *src) { static t_caps *caps; @@ -57,7 +58,7 @@ t_caps return (caps); } -int16_t +static int16_t c_set_term_raw(uint8_t mode) { struct termios tios; @@ -77,15 +78,17 @@ int16_t tios.c_oflag |= (OPOST); } tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios); + tputs(tgetstr("cd", NULL), 1, ft_putchar); return (1); } int16_t - c_process_key(char *buf) + c_process_key(t_msh *msh, char *buf) { int i; static char *line; + (void)msh; i = -1; if (line == NULL) if (!(line = ft_calloc(2, sizeof(char)))) @@ -94,26 +97,41 @@ int16_t { if (*buf == 'q') exit(0); + else if (*buf == '\n') + tputs(tgetstr("nl", NULL), 1, ft_putchar); line = ft_strjoin_m(line, buf); - ft_printf("line [%s][%lu]\n", line, ft_strlen(line)); + ft_printf("line [%s][%lu]", line, ft_strlen(line)); /* ft_redraw */ } else { - if(strncmp(buf, tgetstr("kr", NULL), ft_strlen(tgetstr("kr", NULL))) == 0) + if (strncmp(buf, tgetstr("kr", NULL), ft_strlen(tgetstr("kr", NULL))) == 0) { tputs(tgetstr("nd", NULL), 1, ft_putchar); return (1); } - else if(strncmp(buf, tgetstr("kl", NULL), ft_strlen(tgetstr("kl", NULL))) == 0) + else if (buf[0] == '\n') + { + write(1, buf, ft_strlen(buf)); + m_prompt_psx(1, msh); + tputs(tgetstr("cr", NULL), 1, ft_putchar); + 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(void) +int16_t c_init_tcaps(t_msh *msh) { t_caps tcaps; char *bp; @@ -125,27 +143,15 @@ int16_t c_init_tcaps(void) term = getenv("TERM"); if (!tgetent(bp, term)) return (-1); - /* tcaps.cl = tgetstr("cl", &term); */ - /* tcaps.ks = tgetstr("ks", &term); */ - /* tcaps.kl = tgetstr("kl", &term); */ - /* tcaps.ke = tgetstr("ke", &term); */ - /* tcaps.kr = tgetstr("kr", &term); */ - /* tcaps.pc = tgetstr("pc", &term); */ - /* tcaps.bc = tgetstr("bc", &term); */ - /* tcaps.up = tgetstr("up", &term); */ - /* tcaps.nd = tgetstr("nd", &term); */ - /* tcaps.le = tgetstr("le", &term); */ - /* tcaps.DO = tgetstr("do", &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); - ret = c_process_key(nread); + ret = c_process_key(msh, nread); } ft_printf("%d\n", ret); return (1); |