/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* 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_init.h" #include "c_keys.h" #include "c_input.h" #include "c_utils.h" #include "m_prompt.h" #include "m_loop.h" t_msh *c_get_struct(int mode, t_msh **msh) { static t_msh *mstruct = NULL; if (mode) { mstruct = *msh; } return (mstruct); } void c_signal_int(int signo) { t_msh *msh; msh = NULL; signal(SIGINT, c_signal_int); (void)signo; msh = c_get_struct(0, &msh); ft_printf("[%s]\n", msh->ps[0]); msh->ret = 130; ioctl(1, TIOCSTI, "\002"); } void c_signal_ign(int signo) { signal(SIGINT, c_signal_int); (void)signo; signal(SIGTSTP, SIG_IGN); } short c_init_line(char psx, t_caps *tcaps) { char *term; if (tcaps) { term = getenv("TERM"); if (!tgetent(NULL, term)) return (-1); c_set_term_raw(1); signal(SIGINT, c_signal_int); signal(SIGQUIT, c_signal_ign); 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); }