diff options
Diffstat (limited to 'src/c_init.c')
-rw-r--r-- | src/c_init.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/c_init.c b/src/c_init.c index 50c974b..d78a8f2 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -82,8 +82,8 @@ c_read_cap(char *buf, return (0); } -int16_t - c_process_key(char *buf, +char + *c_process_key(char *buf, t_caps *tcaps, t_msh *msh) { @@ -93,7 +93,7 @@ int16_t i = -1; if (line == NULL) if (!(line = ft_calloc(1, sizeof(char)))) - return (-1); + return (NULL); if (ft_isprint(buf[0])) { line = c_insert_char(line, buf[0], tcaps); @@ -103,26 +103,21 @@ int16_t else if ((*((unsigned int *)buf)) == DEL_K) { c_back_slash(&line, ft_strlen(msh->ps[0]), tcaps); - return (1); } - else if (buf[0] == '\n') + else { - c_new_line(ft_strdup(line), msh, tcaps); - ft_memdel((void**)&line); - return (1); + c_read_cap(buf, line, tcaps, msh); } - else - return (c_read_cap(buf, line, tcaps, msh)); - return (0); + return (ft_strdup(line)); } int16_t - c_init_tcaps(t_msh *msh) + c_init_tcaps(char **line, + t_msh *msh) { t_caps tcaps; char *term; char nread[5]; - int ret; term = getenv("TERM"); if (!tgetent(NULL, term)) @@ -130,16 +125,24 @@ int16_t c_set_term_raw(1); c_get_struct(1, &tcaps); c_init_line(&tcaps); + tputs(tgetstr("cr", NULL), 1, ft_putchar); m_prompt_psx(1, msh); signal(SIGINT, SIG_IGN); + ft_bzero(nread, 5); if (!(c_get_win_size(&tcaps.ws))) return (-1); - while (1) + while (!(ft_strchr(nread, '\n'))) { ft_bzero(nread, 5); if (!(read(STDIN_FILENO, nread, 4))) return (0); - ret = c_process_key(nread, &tcaps, msh); + else + *line = c_process_key(nread, &tcaps, msh); + if (*line == NULL) + { + ft_printf("FUCK"); + return (0); + } tputs(tgetstr("ve", NULL), 1, ft_putchar); } return (1); |