diff options
-rw-r--r-- | src/c_init.c | 48 | ||||
-rw-r--r-- | src/c_init.h | 16 | ||||
-rw-r--r-- | src/m_loop.c | 2 |
3 files changed, 43 insertions, 23 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); diff --git a/src/c_init.h b/src/c_init.h index c85f6b7..7924478 100644 --- a/src/c_init.h +++ b/src/c_init.h @@ -15,6 +15,8 @@ #include <termios.h> +#include "s_struct.h" + typedef struct s_caps { struct termios tios; char *cm_str; /*cursor mobility*/ @@ -33,6 +35,18 @@ typedef struct s_caps { } t_caps; -int16_t c_init_tcaps(void); +int16_t c_init_tcaps(t_msh *msh); #endif + + /* 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); */ diff --git a/src/m_loop.c b/src/m_loop.c index 39d8452..232919d 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -39,7 +39,7 @@ uint8_t int8_t gnl; gnl = 1; - c_init_tcaps(); + c_init_tcaps(msh); while (gnl > 0) { if (fd == STDIN_FILENO) |