diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/c_init.c | 1 | ||||
-rw-r--r-- | src/c_init.h | 1 | ||||
-rw-r--r-- | src/c_input.c | 29 | ||||
-rw-r--r-- | src/c_input.h | 1 | ||||
-rw-r--r-- | src/c_keys.c | 2 | ||||
-rw-r--r-- | src/c_utils.c | 23 |
6 files changed, 39 insertions, 18 deletions
diff --git a/src/c_init.c b/src/c_init.c index a196708..2992789 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -124,6 +124,7 @@ int16_t if (!tgetent(NULL, term)) return (-1); tcaps.cpos = 0; + tcaps.lpos = 0; c_set_term_raw(1); c_get_struct(1, &tcaps); c_init_keys(&tcaps); diff --git a/src/c_init.h b/src/c_init.h index 798abb1..a1b7c9a 100644 --- a/src/c_init.h +++ b/src/c_init.h @@ -29,6 +29,7 @@ typedef struct s_caps struct termios tios; struct winsize ws; uint32_t cpos; /*cursor position (column)*/ + uint32_t lpos; /*cursor position (line)*/ char *cm_str; /*cursor mobility*/ char *nl; /*newline, returned by tgoto()*/ char *ks; /*indicate that keys transmit from now on*/ diff --git a/src/c_input.c b/src/c_input.c index 5e9db72..4dab9f0 100644 --- a/src/c_input.c +++ b/src/c_input.c @@ -46,14 +46,39 @@ int16_t tcaps->HM[3] = 0; tcaps->ND[0] = 27; tcaps->ND[1] = 91; - tcaps->ND[2] = -103; - tcaps->ND[3] = 0; + tcaps->ND[2] = 52; + tcaps->ND[3] = 126; return (1); } else return (-1); } +uint32_t +c_get_line_num(char *line, + uint32_t cpos, + uint32_t plen, + t_caps *tcaps) +{ + uint32_t it; + uint32_t line_num; + uint32_t len; + + it = 0; + line_num = 0; + tcaps->lpos = 0; + len = ft_strlen(line); + if (len < (tcaps->ws.ws_col - plen)) + return (1); + while (it < len) + { + it += (it == 0) ? (tcaps->ws.ws_col - plen) : tcaps->ws.ws_col; + tcaps->lpos += (it < cpos) ? 1 : 0; + line_num++; + } + return (line_num); +} + int16_t c_back_slash(char **line, t_caps *tcaps) diff --git a/src/c_input.h b/src/c_input.h index e621061..b529a88 100644 --- a/src/c_input.h +++ b/src/c_input.h @@ -15,5 +15,6 @@ int16_t c_back_slash(char **line, t_caps *tcaps); int16_t c_ctrl_c(char *line, t_caps *tcaps, t_msh *msh); +uint32_t c_get_line_num(char *line, uint32_t cpos, uint32_t plen, t_caps *tcaps); #endif diff --git a/src/c_keys.c b/src/c_keys.c index 7874932..f9141d7 100644 --- a/src/c_keys.c +++ b/src/c_keys.c @@ -93,7 +93,7 @@ int16_t tputs(tgetstr("nd", NULL), 1, ft_putchar); tcaps->cpos--; } - if (tcaps->cpos >= 1) + else if (tcaps->cpos >= 1) { tputs(tgetstr("le", NULL), 1, ft_putchar); tcaps->cpos--; diff --git a/src/c_utils.c b/src/c_utils.c index f96d0b3..d5d818a 100644 --- a/src/c_utils.c +++ b/src/c_utils.c @@ -17,16 +17,15 @@ #include <unistd.h> #include "c_init.h" +#include "c_input.h" #include "m_prompt.h" #include "m_loop.h" #include "s_struct.h" /* ** TODO: -** MULTILIGHNE +** MULTILIGHNE (reprint correct) ** FLECHES UP DOWN -** quotes -** unknown chars ** C-c globul pid ** NORME */ @@ -132,23 +131,17 @@ int16_t uint32_t i; uint32_t len; int16_t ret; + uint32_t nlines; i = 0; len = ft_strlen(line); + nlines = c_get_line_num(line, tcaps->cpos, ft_strlen(msh->ps[0]), tcaps); tputs(tgetstr("cr", NULL), 1, ft_putchar); - if (len >= (tcaps->ws.ws_col - ft_strlen(msh->ps[0]))) + if (nlines > 1) { - if (len % (tcaps->ws.ws_col - ft_strlen(msh->ps[0])) == 0) - { - tputs(tgetstr("sf", NULL), 1, ft_putchar); - return (1); - } - else - { - tputs(tgetstr("sf", NULL), 1, ft_putchar); - tputs(tgetstr("up", NULL), 1, ft_putchar); - tputs(tgetstr("up", NULL), 1, ft_putchar); - } + tputs(tgetstr("sf", NULL), 1, ft_putchar); + tputs(tgetstr("up", NULL), 1, ft_putchar); + tputs(tgetstr("up", NULL), 1, ft_putchar); } while (i < ft_strlen(msh->ps[0])) { |