void readline_signal_ctrl_c(void) { if (getenv("TERM") != NULL) { readline_key_end(); readline_refresh_line(); ft_putchar('\n'); ft_strdel(&sgt_readline()->concat_buffer); ft_strdel(&sgt_readline()->save_buffer); ft_strdel(&sgt_readline()->buffer); ini_readline(); sgt_readline()->completion.in_tab = false; readline_refresh_line(); } }
void readline_key_ctrl_down(void) { int i; if (sgt_readline()->select.is_select) return (s_for_select()); if (sgt_readline()->prompt.len + sgt_readline()->len_buffer > (unsigned long)tgetnum("co")) { i = tgetnum("co"); while (i > 0 && sgt_readline()->cursor_pos < sgt_readline()->len_buffer) { readline_key_right(); --i; } } }
void readline_signal_resize(void) { if (getenv("TERM") != NULL) { ioctl(STDOUT_FILENO, TIOCGWINSZ, &sgt_readline()->term.size); readline_refresh_line(); } }
void readline_key_ctrl_s(void) { if (sgt_readline()->completion.in_tab == true) { sgt_readline()->completion.in_tab = false; readline_refresh_line(); } sgt_readline()->select.is_select = !sgt_readline()->select.is_select; if (sgt_readline()->select.is_select) { sgt_readline()->select.start = sgt_readline()->cursor_pos; sgt_readline()->select.len = 0; } else { readline_refresh_line(); } }
void readline_completion_replace_concat_glob(char **abuff, char **glob) { char *ret; size_t i; ret = NULL; i = 0; while (glob[i]) { if (i > 0) ft_asprintf(&ret, "%s %s", ret, glob[i]); else ft_asprintf(&ret, "%s", glob[i]); ++i; } ft_strtable_clear(&glob); ft_strdel(abuff); *abuff = ret; sgt_readline()->completion.in_tab = false; }
t_bool readline_term_on(void) { if (tgetent(NULL, "xterm-256color") == -1) return (false); if (tcgetattr(NULL, &sgt_readline()->term.save_termios) == -1) return (false); if (tcgetattr(NULL, &sgt_readline()->term.termios) == -1) return (false); sgt_readline()->term.termios.c_lflag &= ~(ICANON | ECHO); sgt_readline()->term.termios.c_cc[VMIN] = 1; sgt_readline()->term.termios.c_cc[VTIME] = 0; if (tcsetattr(0, TCSANOW, &sgt_readline()->term.termios) == -1) return (false); return (true); }
static void s_for_select(void) { int i; if (sgt_readline()->prompt.len + sgt_readline()->len_buffer > \ (unsigned long)tgetnum("co")) { i = tgetnum("co"); while (i > 0 && sgt_readline()->cursor_pos < sgt_readline()->len_buffer) { ++sgt_readline()->cursor_pos; ++sgt_readline()->select.len; --i; } } readline_refresh_line(); }
t_bool readline_term_off(void) { if (tcsetattr(0, NULL, &sgt_readline()->term.save_termios) == -1) return (false); return (true); }