From 4f3d3364de8f1c23819051cb9f392fc651565b95 Mon Sep 17 00:00:00 2001 From: joe Date: Tue, 1 Dec 2020 18:36:35 +0100 Subject: commit --- src/c_init.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/c_init.c') diff --git a/src/c_init.c b/src/c_init.c index 965af3f..b463830 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -23,6 +23,7 @@ #include "c_keys_next.h" #include "c_input.h" #include "c_utils.h" +#include "d_define.h" #include "b_exit.h" #include "s_struct.h" #include "s_com.h" @@ -105,11 +106,36 @@ static short return (0); } +char *c_set_ptr(t_bool reset, char key, t_msh *msh) +{ + static char *p = NULL; + + if (reset == TRUE) + { + p = msh->curr_hist_ptr + ft_strlen(msh->curr_hist_ptr); + return (NULL); + } + if ((key == -1 && p - msh->curr_hist_ptr != 0) || key == 1) + { + p += (key == -1) ? (2 * key) : (0); + while (((key == -1 && p - msh->curr_hist_ptr != 0) || key == 1) && *p != C_LF && *p != C_NUL) + { + p += key; + } + if (p - msh->curr_hist_ptr != 0 && *p != C_NUL) + { + p += 1; + } + } + return (p); +} + static char *c_process_key(char *buf, t_caps *tcaps, t_msh *msh) { static char *line = NULL; int i; + char *ptr; i = -1; if (line == NULL) @@ -120,7 +146,15 @@ static char else if (((*((unsigned int *)buf)) == UP_K) || ((*((unsigned int *)buf)) == CTRL_P)) { - c_key_up(&line, tcaps, msh); + ptr = c_set_ptr(FALSE, -1, msh); + c_key_up_down(&line, tcaps, ptr); + c_redraw_line(line, tcaps, msh); + } + else if (((*((unsigned int *)buf)) == DOWN_K) || + ((*((unsigned int *)buf)) == CTRL_N)) + { + ptr = c_set_ptr(FALSE, 1, msh); + c_key_up_down(&line, tcaps, ptr); c_redraw_line(line, tcaps, msh); } else if ((*((unsigned int *)buf)) == DEL_K) -- cgit v1.2.3