diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/c_init.c | 44 | ||||
-rw-r--r-- | src/c_input.c | 14 | ||||
-rw-r--r-- | src/c_input.h | 1 |
3 files changed, 35 insertions, 24 deletions
diff --git a/src/c_init.c b/src/c_init.c index 454e70a..35296e4 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -85,10 +85,10 @@ static int16_t } int16_t - c_process_key(char *buf, t_msh *msh, t_caps *tcaps) + c_process_key(char *buf, t_caps *tcaps, t_msh *msh) { - int i; static char *line = NULL; + int i; i = -1; if (line == NULL) @@ -96,47 +96,54 @@ int16_t 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, tcaps->cpos, msh); tcaps->cpos++; } else { + /* if (!(c_catch_tcaps(buf, tcaps, msh)) */ + /* return (-1); */ if (strncmp(buf, tgetstr("kr", NULL), ft_strlen(tgetstr("kr", NULL))) == 0) { - tputs(tgetstr("nd", NULL), 1, ft_putchar); - tcaps->cpos++; + if (tcaps->cpos <= ft_strlen(line)) + { + tputs(tgetstr("nd", NULL), 1, ft_putchar); + tcaps->cpos++; + } return (1); } 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); } else if (strncmp(buf, tgetstr("kl", NULL), ft_strlen(tgetstr("kl", NULL))) == 0) { - tputs(tgetstr("le", NULL), 1, ft_putchar); - tcaps->cpos--; - return (1); + if (tcaps->cpos >= 1) + { + tputs(tgetstr("le", NULL), 1, ft_putchar); + tcaps->cpos--; + return (1); + } } else if (strncmp(buf, tgetstr("kb", NULL), ft_strlen(tgetstr("kb", NULL))) == 0) { - line = c_delchar(line, tcaps->cpos); - tcaps->cpos -= 1; - tputs(tgetstr("le", NULL), 1, ft_putchar); - tputs(tgetstr("dc", NULL), 1, ft_putchar); + 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); } } @@ -156,7 +163,6 @@ int16_t c_init_tcaps(t_msh *msh) if (!tgetent(bp, term)) return (-1); tcaps.cpos = 0; - ft_printf("my term is %s", term); c_set_term_raw(1); c_get_struct(1, &tcaps); if (!(c_get_win_size(&tcaps.ws))) @@ -167,7 +173,7 @@ int16_t c_init_tcaps(t_msh *msh) if (!(read(STDIN_FILENO, nread, 4))) return (0); tputs(tgetstr("vi", NULL), 1, ft_putchar); - ret = c_process_key(nread, msh, &tcaps); + ret = c_process_key(nread, &tcaps, msh); tputs(tgetstr("ve", NULL), 1, ft_putchar); } return (1); diff --git a/src/c_input.c b/src/c_input.c index e7a3f44..a4b62ca 100644 --- a/src/c_input.c +++ b/src/c_input.c @@ -22,6 +22,15 @@ #include "m_loop.h" #include "s_struct.h" +/* +** TODO: +** 1 : cleanup +** 2 : prompt on beginning +** 3 : c_set_term(0) on command +** 4 : MAKE IT WORK ON XTERM FFS +** 5 : leaks + */ + uint16_t c_get_win_size(struct winsize *ws) { @@ -35,7 +44,6 @@ uint16_t return (1); } - char *c_delchar(char *str, uint16_t cpos) { char *dst; @@ -47,7 +55,6 @@ char *c_delchar(char *str, uint16_t cpos) if (!(dst = malloc((ft_strlen(str)) * sizeof(char)))) return (NULL); cpos -= 1; - /* ft_printf("[%c] [%d]\n", str[cpos], cpos); */ while (j < (ft_strlen(str) - 1)) { if (i == cpos) @@ -57,12 +64,9 @@ char *c_delchar(char *str, uint16_t cpos) j++; } dst[j] = '\0'; - /* ft_printf("dst : [%s]\n", dst); */ return (dst); } -/* TODO: pos += 1 lettre / -1 si kl / +1 kr del*/ - int16_t c_redraw_line(char *line, uint16_t cpos, t_msh *msh) { diff --git a/src/c_input.h b/src/c_input.h index e592ace..c340194 100644 --- a/src/c_input.h +++ b/src/c_input.h @@ -18,5 +18,6 @@ int16_t c_redraw_line(char *line, uint16_t cpos, t_msh *msh); char *c_delchar(char *str, uint16_t cpos); uint16_t c_get_win_size(struct winsize *ws); +int32_t c_catch_tcaps(char *buf, char **line, t_caps *tcaps, t_msh *msh); #endif |