/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* c_input.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include #include #include #include "c_ctrls.h" #include "c_init.h" #include "c_keys.h" #include "c_input.h" #include "c_utils.h" #include "m_prompt.h" #include "m_loop.h" #include "u_vars.h" short c_init_line(char psx, t_caps *tcaps, t_msh *msh) { char term[4096]; signal(SIGINT, c_signal_int); signal(SIGQUIT, c_signal_ign); if (tcaps) { u_get_var_value(term, "$TERM", 4096, msh); if (!tgetent(NULL, term)) return (-1); c_set_term_raw(1); tcaps->cpos = 0; tcaps->lpos = 0; tcaps->nlines = 1; tcaps->psx = psx - 1; return (1); } else return (-1); } unsigned short c_get_win_size(struct winsize *ws) { if (!(ioctl(STDOUT_FILENO, TIOCGWINSZ, ws))) return (-1); if (!ws->ws_col) ws->ws_col = 80; if (!ws->ws_row) ws->ws_row = 80; return (1); } unsigned int c_get_line_num(char *line, unsigned int cpos, unsigned int plen, t_caps *tcaps) { unsigned int it; unsigned int line_num; unsigned int len; it = 0; line_num = 0; tcaps->lpos = 1; 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); } short c_back_slash(char **line, unsigned int plen, t_caps *tcaps) { if (tcaps->cpos >= 1) { *line = c_delchar(*line, tcaps->cpos); c_key_left(plen, tcaps); tputs(tgetstr("cd", NULL), 1, ft_putchar); } return (1); }