diff options
Diffstat (limited to '')
-rw-r--r-- | src/c_init.c | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/src/c_init.c b/src/c_init.c index 844e4a6..7ea11ac 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -14,6 +14,7 @@ #include <stdlib.h> #include <term.h> #include <libft.h> +#include <signal.h> #include "c_init.h" #include "c_input.h" @@ -22,18 +23,6 @@ #include "s_struct.h" #include "m_prompt.h" -static t_caps - *c_get_struct(int mode, t_caps *src) -{ - static t_caps *caps; - - if (mode == 1) - { - caps = src; - } - return (caps); -} - int16_t c_set_term_raw(uint8_t mode) { @@ -58,7 +47,21 @@ int16_t return (1); } -int16_t +static void + c_add_char(char **line, char *buf, t_caps *tcaps, t_msh *msh) +{ + *line = c_insert_char(*line, buf[0], tcaps); + tcaps->cpos++; + if ((((tcaps->cpos) + ft_strlen(msh->ps[tcaps->psx])) % + tcaps->ws.ws_col) == 0) + { + write(1, "\n\r", 2); + return ; + } + c_redraw_line(*line, tcaps, msh); +} + +static int16_t c_read_cap(char *buf, char *line, t_caps *tcaps, t_msh *msh) { uint32_t plen; @@ -70,12 +73,12 @@ int16_t else if (((*((unsigned int *)buf)) == RIGHT_K) || ((*((unsigned int *)buf)) == CTRL_F)) return (c_key_right(ft_strlen(line), plen, tcaps)); - else if ((*((unsigned int *)buf)) == HOME_K) + else if (((*((unsigned int *)buf)) == HOME_K) || + ((*((unsigned int *)buf)) == CTRL_A)) return (c_home_key(plen, tcaps)); - else if ((*((unsigned int *)buf)) == END_K) + else if (((*((unsigned int *)buf)) == END_K) || + ((*((unsigned int *)buf)) == CTRL_E)) return (c_end_key(ft_strlen(line), plen, tcaps)); - else if ((*((unsigned int *)buf)) == CTRL_C) - return (c_ctrl_c(NULL, tcaps, msh)); else if ((*((unsigned int *)buf)) == CTRL_L) return (c_ctrl_l(line, tcaps, msh)); else @@ -93,17 +96,7 @@ static char if (!(line = ft_calloc(1, sizeof(char)))) return (NULL); if (ft_isprint(buf[0])) - { - line = c_insert_char(line, buf[0], tcaps); - tcaps->cpos++; - if ((((tcaps->cpos) + ft_strlen(msh->ps[tcaps->psx])) % - tcaps->ws.ws_col) == 0) - { - write(1, "\n\r", 2); - return (NULL); - } - c_redraw_line(line, tcaps, msh); - } + c_add_char(&line, buf, tcaps, msh); else if ((*((unsigned int *)buf)) == DEL_K) { c_back_slash(&line, ft_strlen(msh->ps[tcaps->psx]), tcaps); @@ -129,9 +122,9 @@ int16_t char nread[5]; term = getenv("TERM"); + signal(SIGINT, SIG_DFL); if (!tgetent(NULL, term)) return (-1); - c_get_struct(1, &tcaps); c_init_line(psx, &tcaps); tputs(tgetstr("cr", NULL), 1, ft_putchar); m_prompt_psx(psx, msh); |